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

Tool Crawl4AI has error with Ollama #1584

Closed
vanetreg opened this issue Dec 16, 2024 · 0 comments · Fixed by #1597
Closed

Tool Crawl4AI has error with Ollama #1584

vanetreg opened this issue Dec 16, 2024 · 0 comments · Fixed by #1597

Comments

@vanetreg
Copy link

vanetreg commented Dec 16, 2024

I use newest versions:
phidata 2.7.3
crawl4ai 0.4.23
ollama 0.4.4

crawl4ai example code works with
model=OpenAIChat(id="gpt-4o-mini"),
but not with:
model=Ollama(id="llama3.2:latest", host = ollama_base_url),

The full code used:

from phi.agent import Agent
from phi.model.ollama import Ollama
from phi.tools.crawl4ai_tools import Crawl4aiTools
import os
from dotenv import load_dotenv

load_dotenv()

ollama_base_url = os.getenv("OLLAMA_BASE_URL")

agent = Agent(
    model=Ollama(id="llama3.2:latest", host = ollama_base_url),
    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)

I got error:

(phidata-venv) PS D:\Projects\AI_testing\phidata> python .\crawl4ai_tool_ollama.py
▰▰▰▰▰▰▱ Thinking...
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓┃                                                                                                                                                       ┃┃ Summarize me the key points in bullet points of this: https://blog.google/products/gemini/google-gemini-deep-research/                                ┃┃                                                                                                                                                       ┃┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛Traceback (most recent call last):
  File "D:\Projects\AI_testing\phidata\crawl4ai_tool_ollama.py", line 16, in <module>
    agent.print_response("Summarize me the key points in bullet points of this: https://blog.google/products/gemini/google-gemini-deep-research/", stream=True)
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\phi\agent\agent.py", line 2783, in print_response
    for resp in self.run(message=message, messages=messages, stream=True, **kwargs):
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\phi\agent\agent.py", line 1794, in _run
    for model_response_chunk in self.model.response_stream(messages=messages_for_model):
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\phi\model\ollama\chat.py", line 597, in response_stream
    for response in self.invoke_stream(messages=messages):
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\phi\model\ollama\chat.py", line 236, in invoke_stream
    yield from self.get_client().chat(
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\ollama\_client.py", line 339, in chat
    tools=[tool for tool in _copy_tools(tools)],
                            ^^^^^^^^^^^^^^^^^^
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\ollama\_client.py", line 1133, in _copy_tools
    yield convert_function_to_tool(unprocessed_tool) if callable(unprocessed_tool) else Tool.model_validate(unprocessed_tool)
                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\AI_testing\phidata\phidata-venv\Lib\site-packages\pydantic\main.py", line 627, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Tool
function.parameters.properties.max_length.type
  Input should be a valid string [type=string_type, input_value=['number', 'null'], input_type=list]
    For further information visit https://errors.pydantic.dev/2.10/v/string_type

Note I used 3.5-sonnet in Cursor for debugging and I tried to set
max_length to default None, 1000 and "1000"
in "Crawl4aiTools(max_length="1000")"
but none ot them worked, had the same error...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant