mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
examples: remove duplicate import and refactor message initialization
- Remove duplicate `from ollama import ChatResponse, chat` import - Initialize `messages` as empty list instead of getting from kwargs - Remove `reserved` set and `chat_kwargs` filtering logic - Add `think` parameter to client function call - Reformat client_fn call with explicit parameters on separate lines
This commit is contained in:
parent
e6c8210330
commit
ddb9fcd3e3
@ -1,7 +1,5 @@
|
||||
from ollama import ChatResponse, chat
|
||||
|
||||
from ollama import ChatResponse, chat
|
||||
|
||||
|
||||
def ollama_chat_automatic_function_calling(
|
||||
client_fn: chat, options: dict = None, **kwargs
|
||||
@ -27,10 +25,9 @@ def ollama_chat_automatic_function_calling(
|
||||
if model is None:
|
||||
raise ValueError("model must be specified")
|
||||
|
||||
messages = kwargs.get("messages", [])
|
||||
max_turns = kwargs.get("max_turns", 20)
|
||||
tools = kwargs.get("tools", [])
|
||||
tool_map = kwargs.get("tool_map")
|
||||
messages = list()
|
||||
last_response = None
|
||||
|
||||
def _to_msg_dict(msg):
|
||||
@ -81,12 +78,14 @@ def ollama_chat_automatic_function_calling(
|
||||
if not callable(client_fn):
|
||||
raise ValueError("client_fn must be a callable")
|
||||
|
||||
reserved = {"messages", "max_turns", "model", "tools", "tool_map"}
|
||||
chat_kwargs = {k: v for k, v in kwargs.items() if k not in reserved}
|
||||
|
||||
for _ in range(max_turns):
|
||||
response = client_fn(
|
||||
model=model, tools=tools, messages=messages, options=options, **chat_kwargs
|
||||
model=model,
|
||||
tools=tools,
|
||||
messages=messages,
|
||||
options=options,
|
||||
think=think,
|
||||
**chat_kwargs,
|
||||
)
|
||||
last_response = response
|
||||
assistant_msg = response.message
|
||||
|
||||
Loading…
Reference in New Issue
Block a user