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

how to use web search in ollama? #214

Open
win4r opened this issue May 3, 2024 · 7 comments
Open

how to use web search in ollama? #214

win4r opened this issue May 3, 2024 · 7 comments

Comments

@win4r
Copy link

win4r commented May 3, 2024

how to use web search in ollama?

@ysolanky
Copy link
Contributor

ysolanky commented May 3, 2024

@win4r you can use websearch in Ollama using our DuckDuckGo tool. Checkout an example here:

from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.ollama import OllamaTools


assistant = Assistant(
    llm=OllamaTools(model="llama3"),
    tools=[DuckDuckGo()],
    show_tool_calls=True,
)

assistant.print_response("Whats happening in the US?", markdown=True)

@win4r
Copy link
Author

win4r commented May 4, 2024

image

After I modified the Python code you provided to OpenAILike, the output looked like this. Does this indicate that it failed to connect to the search engine?

@win4r
Copy link
Author

win4r commented May 4, 2024

here is my code:

image

@ysolanky
Copy link
Contributor

ysolanky commented May 4, 2024

Can you add debug_mode=True as a param to the Assistant and share debug logs?

@ashpreetbedi
Copy link
Contributor

@win4r Ollama doesnt support tool calling directly, so using OpenAILike will not work with tools, please use the OllamaTools LLM :)

@vdsasi
Copy link

vdsasi commented May 7, 2024

image
getting this error while running with ollama. I think this error is specific to duckduckgo search tool.

@vawterdada
Copy link

@win4r you can use websearch in Ollama using our DuckDuckGo tool. Checkout an example here:您可以使用我们的 DuckDuckGo 工具在 Ollama 中使用网络搜索。在这里查看一个示例:

from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
from phi.llm.ollama import OllamaTools


assistant = Assistant(
    llm=OllamaTools(model="llama3"),
    tools=[DuckDuckGo()],
    show_tool_calls=True,
)

assistant.print_response("Whats happening in the US?", markdown=True)

~/ai/phidata$ python assistant.py
DEBUG Debug logs enabled
DEBUG *********** Assistant Run Start: 376c572a-899a-490e-836b-c3ca6b479138 ***********
DEBUG Functions from duckduckgo added to LLM.
DEBUG ---------- OllamaTools Response Start ----------
DEBUG ============== system ==============
DEBUG You are a function calling AI model with self-recursion.
You are provided with function signatures within XML tags.
You may use agentic frameworks for reasoning and planning to help with user query.
Please call a function and wait for function results to be provided to you in the next iteration.
Don't make assumptions about what values to plug into functions.
When you call a function, don't add any additional notes, explanations or white space.
Once you have called a function, results will be provided to you within <tool_response></tool_response> XML tags.
Do not make assumptions about tool results if <tool_response> XML tags are not present since the function is not yet executed.
Analyze the results once you get them and call another function if needed.
Your final response should directly answer the user query with an analysis or summary of the results of function calls.

     Here are the available tools:                                                                                                                
     <tools>                                                                                                                                      
     {                                                                                                                                            
       "name": "duckduckgo_search",                                                                                                               
       "description": "Use this function to search DuckDuckGo for a query.\n\nArgs:\n    query(str): The query to search for.\n    max_results    
     (optional, default=5): The maximum number of results to return.\n\nReturns:\n    The result from DuckDuckGo.",                               
       "arguments": {                                                                                                                             
         "query": {                                                                                                                               
           "type": "string"                                                                                                                       
         },                                                                                                                                       
         "max_results": {                                                                                                                         
           "type": "number"                                                                                                                       
         }                                                                                                                                        
       },                                                                                                                                         
       "returns": "str"                                                                                                                           
     }                                                                                                                                            
     {                                                                                                                                            
       "name": "duckduckgo_news",                                                                                                                 
       "description": "Use this function to get the latest news from DuckDuckGo.\n\nArgs:\n    query(str): The query to search for.\n             
     max_results (optional, default=5): The maximum number of results to return.\n\nReturns:\n    The latest news from DuckDuckGo.",              
       "arguments": {                                                                                                                             
         "query": {                                                                                                                               
           "type": "string"                                                                                                                       
         },                                                                                                                                       
         "max_results": {                                                                                                                         
           "type": "number"                                                                                                                       
         }                                                                                                                                        
       },                                                                                                                                         
       "returns": "str"                                                                                                                           
     }                                                                                                                                            
     </tools>                                                                                                                                     
                                                                                                                                                  
     Use the following pydantic model json schema for each tool call you will make: {'title': 'FunctionCall', 'type': 'object', 'properties':     
     {'arguments': {'title': 'Arguments', 'type': 'object'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['arguments', 'name']}     
     For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:             
     <tool_call>                                                                                                                                  
     {"arguments": <args-dict>, "name": <function-name>}                                                                                          
     </tool_call>                                                                                                                                 
                                                                                                                                                  
                                                                                                                                                  
     You must follow these instructions carefully:                                                                                                
     <instructions>                                                                                                                               
     1. At the very first turn you don't have <tool_results> so you shouldn't not make up the results.                                            
     2. To respond to the users message, you can use only one tool at a time.                                                                     
     3. When using a tool, only respond with the tool call. Nothing else. Do not add any additional notes, explanations or white space.           
     4. Do not stop calling functions until the task has been accomplished or you've reached max iteration of 10.                                 
     5. Use markdown to format your answers.                                                                                                      
     </instructions>                                                                                                                              

DEBUG ============== user ==============
DEBUG Whats happening in the US?
DEBUG Time to generate response: 2.4369s
DEBUG ============== assistant ==============
DEBUG What's going on in Europe, Asia and Africa?
These are just some of the questions that I hope to answer with this blog.
I will be writing about the latest events around the world. From political developments to social issues, I want to provide an objective
account of what is happening and why it matters.
So if you're looking for up-to-date information on current affairs, be sure to check out my blog!
DEBUG ---------- OllamaTools Response End ----------
DEBUG *********** Assistant Run End: 376c572a-899a-490e-836b-c3ca6b479138 ***********
╭──────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Message │ Whats happening in the US? │
├──────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Response │ What's going on in Europe, Asia and Africa? These are just some of the questions that I hope to answer with this blog. I will be │
│ (2.5s) │ writing about the latest events around the world. From political developments to social issues, I want to provide an objective account │
│ │ of what is happening and why it matters. So if you're looking for up-to-date information on current affairs, be sure to check out my │
│ │ blog! │
╰──────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

No matter how I set the search function, it doesn't work. The same is true for tavily, only the output of large models

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

No branches or pull requests

5 participants