Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tool parsing for ollama #1597

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cookbook/providers/ollama/agent_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterator # noqa
from phi.agent import Agent, RunResponse # noqa
from phi.model.ollama import Ollama
from phi.tools.crawl4ai_tools import Crawl4aiTools
from phi.tools.yfinance import YFinanceTools

agent = Agent(
Expand All @@ -20,3 +21,10 @@

# Print the response in the terminal
agent.print_response("What are analyst recommendations for NVDA and TSLA", stream=True)


agent = Agent(model=Ollama(id="llama3.1:8b"), tools=[Crawl4aiTools(max_length=1000)], show_tool_calls=True)
agent.print_response(
"Summarize me the key points in bullet points of this: https://blog.google/products/gemini/google-gemini-deep-research/",
stream=True,
)
5 changes: 5 additions & 0 deletions phi/model/ollama/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def request_kwargs(self) -> Dict[str, Any]:
request_params["keep_alive"] = self.keep_alive
if self.tools is not None:
request_params["tools"] = self.get_tools_for_api()
# Ensure types are valid strings
for tool in request_params["tools"]:
for prop, obj in tool["function"]["parameters"]["properties"].items():
if isinstance(obj["type"], list):
obj["type"] = obj["type"][0]
if self.request_params is not None:
request_params.update(self.request_params)
return request_params
Expand Down
1 change: 0 additions & 1 deletion phi/tools/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def process_entrypoint(self, strict: bool = False):

# Get JSON schema for parameters only
parameters = get_json_schema(type_hints=param_type_hints, strict=strict)

# If strict=True mark all fields as required
# See: https://platform.openai.com/docs/guides/structured-outputs/supported-schemas#all-fields-must-be-required
if strict:
Expand Down
Loading