Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pydantic AI duckduckgo search tool out of date #2182

Closed
Labels
questionFurther information is requested
@CarlosR759

Description

@CarlosR759

Question

Hi !

I'm trying to use the duck duck go search tool from this link:https://ai.pydantic.dev/common-tools/ but after setting all in a virt env, when the application is launched, it launches a warning showing that the pydantic-ai-slim[duckduckgo] installed by pip is deprecated, and I should use ddgshttps://github.com/deedy5/ddgs .

So when I try to use the new ddgs using pydantic ai, it seems that the agent is working fine in catching the ddgs module to make queries to the search engine, but I don't know how to use the cli flags of ddgs like "text' or "news" for example to make more precisely queries for the agent. So how can I send the flag attributes of ddgs to the agent ? Here is the code of what I'm trying to do, please forgive me for not finishing yet the mouse wheel scrolling for the output text, probably I'm going to change cruses to another TUI library soon also:

from pydantic_ai import Agentfrom pydantic_ai.models.openai import OpenAIModelfrom pydantic_ai.providers.openai import OpenAIProviderfrom pydantic_ai.common_tools.duckduckgo import duckduckgo_search_toolfrom ddgs import DDGSimport osimport asyncioimport cursesfrom curses import wrapperfrom curses.textpad import Textbox, rectangleasyncio.set_event_loop(asyncio.new_event_loop())model_name = os.getenv('MODEL_NAME')print(model_name)ollama_model = OpenAIModel (               model_name=model_name,               provider=OpenAIProvider(base_url='http://localhost:11434/v1'),)agent = Agent(ollama_model,              output_type=str,              tools=[duckduckgo_search_tool()],              system_prompt="Search DuckDuckGo for the given query and return the result.",)def main(stdscr):    #Enable mouse for curses    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)    curses.curs_set(0) #Hide cursor    height, width = stdscr.getmaxyx()    stdscr.clear()    #Title    title = "Python Agent \uee0d"    title_len = len(title)    title_x = (width - title_len) // 2    curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)    BLUE_AND_BLACK = curses.color_pair(1)    stdscr.addstr(1,title_x, title, BLUE_AND_BLACK)    #uncomment to have a border in terminal.    #stdscr.border()    #rectangle drawing    rect_y1, rect_x1 = 2, 2    rect_y2, rect_x2 = height - 2, width - 2    rectangle(stdscr, rect_y1, rect_x1, 5, rect_x2)    #window creating with padding    window_height = rect_y2 - rect_y1 - 1    window_width = rect_x2 - rect_x1 - 1    window_y, window_x = rect_y1 + 1, rect_x1 + 1    window = curses.newwin(2 , window_width, window_y, window_x)    box = Textbox(window)    stdscr.refresh()    box.edit()    text = box.gather()    current_y, current_x = stdscr.getyx()    stdscr.refresh()    result = agent.run_sync(text)    output_lines = result.output.split('\n')    max_lines = height - 6    #output window for LLM output    output_win = curses.newwin(height - 6, width - 4, 6, 2)    output_win.scrollok(True)    output_win.addstr(result.output)    output_win.refresh()    scroll_offset = 0    while True:       key = stdscr.getch()       if key == ord('q'): #pressing q quits the program            break       # Handle mouse wheel       if key == curses.KEY_MOUSE:           _, mx, my, _, btn = curses.getmouse()           if btn == 4:  # Scroll up               scroll_offset = max(0, scroll_offset - 1)               output_win.scroll(-1)           elif btn == 5:  # Scroll down               scroll_offset = min(len(output_lines) - (height - 6), scroll_offset + 1)               output_win.scroll(1)           output_win.refresh()       # Handle keyboard arrows       elif key == curses.KEY_UP:           scroll_offset = max(0, scroll_offset - 1)           output_win.scroll(-1)           output_win.refresh()       elif key == curses.KEY_DOWN:           scroll_offset = min(len(output_lines) - (height - 6), scroll_offset + 1)           output_win.scroll(1)           output_win.refresh()#wrapper(main)if __name__ == "__main__":    curses.wrapper(main)

As you can see in this block:

from pydantic_ai.common_tools.duckduckgo import duckduckgo_search_toolfrom ddgs import DDGS

I do the importation of both ddgs, the current one in the pydantic ai documention, and the needed for the newer ddgs implementation, which it can be installed with pip install ddgs. Probably the code would work fine if I just comment the first "from" of the block.

Additional Context

Current version of pip packages that I'm working on:

pydantic 2.11.7
pydantic-ai 0.4.0
ddgs 9.0.0
duckduckgo_search 8.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp