Skip to content

Commit 1ea954e

Browse files
authored
fix: Ollama tools with streaming (#1906)
* Allow to use ollama chat generator with tools and stream * optimise OllamaChatGenerator * Add docstrings * revert docstring for _convert_ollama_meta_to_openai_format * Update docstrings * Add usage example * Add backword compatibility * Fix bug * Update chat_generator.py * Clean up OllamaChatGenerator: remove unused imports and improve formatting - Remove unused DefaultDict import and collections.defaultdict - Remove section comment dividers for cleaner code structure - Fix code formatting and indentation consistency - Simplify tool call list comprehension formatting - Remove unused api_base_url parameter from __init__ - Update example code with better formatting and clearer variable names * Improve variable naming in Ollama chat generator meta conversion Replace single-letter variable names 'k' and 'v' with more descriptive 'key' and 'value' in dictionary comprehension for better code readability. * Refactor OllamaChatGenerator streaming and tool call handling - Replace private _role attribute with public role property - Improve variable naming in tool call processing loop - Fix typo in docstring ("assistant role.." -> "assistant role.") - Simplify streaming response handler with clearer accumulator logic - Use more descriptive variable names (callback vs streaming_callback) * Improve variable naming in OllamaChatGenerator tool call processing Rename `tc_id` to `tool_call_id` in list comprehension for better code readability and consistency with the codebase naming conventions. * Fix Ollama chat generator tests for tools and streaming compatibility Remove failing test cases that expected ValueError exceptions when using tools with streaming or response formatting. Replace with working tests that verify proper functionality of tools with streaming callbacks and JSON response formatting, including validation of tool calls and structured response parsing. * Add integration test markers to Ollama chat generator tests Mark streaming and tools-related test methods with @pytest.mark.integration to properly categorize tests that require external Ollama service. * Fix import path in OllamaChatGenerator docstring example * Remove trailing whitespace from import statement * Add detailed comment explaining Ollama tool call ID handling Explain why fallback logic is needed for missing tool call IDs due to inconsistent behavior between Ollama's native and OpenAI-compatible endpoints, with references to relevant GitHub issues. * Improve comment formatting in OllamaChatGenerator tool_calls handling Break long comment lines and improve readability of the explanation about Ollama server's inconsistent tool_call id field behavior.
1 parent bef6a26 commit 1ea954e

File tree

2 files changed

+222
-107
lines changed

2 files changed

+222
-107
lines changed

0 commit comments

Comments
 (0)