Coder Social home page Coder Social logo

how to use web search in ollama? about phidata HOT 7 OPEN

win4r avatar win4r commented on May 26, 2024
how to use web search in ollama?

from phidata.

Comments (7)

ysolanky avatar ysolanky commented on May 26, 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)

from phidata.

win4r avatar win4r commented on May 26, 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?

from phidata.

win4r avatar win4r commented on May 26, 2024

here is my code:

image

from phidata.

ysolanky avatar ysolanky commented on May 26, 2024

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

from phidata.

ashpreetbedi avatar ashpreetbedi commented on May 26, 2024

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

from phidata.

vdsasi avatar vdsasi commented on May 26, 2024

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

from phidata.

vawterdada avatar vawterdada commented on May 26, 2024

@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

from phidata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.