Skip to content

client/types: update web search and fetch API - #584

Merged
ParthSareen merged 12 commits into
mainfrom
nicole/shape-update
Sep 23, 2025
Merged

ParthSareen merged 12 commits into
mainfrom
nicole/shape-update

Conversation

@npardal

@npardal npardal commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

updated shapes of web_search and web_fetch to reflect go version

@npardal
npardal requested review from ParthSareen and removed request for ParthSareen September 22, 2025 22:18
@npardal
npardal marked this pull request as ready for review September 22, 2025 22:25

@ParthSareen ParthSareen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments

Comment thread examples/web-search-crawl.py
Comment thread examples/web-search-crawl.py
@npardal npardal changed the title browser: web_search + web_fetch shape update client/types: web_search + web_fetch shape update Sep 23, 2025
@npardal
npardal marked this pull request as draft September 23, 2025 00:39
@npardal
npardal marked this pull request as ready for review September 23, 2025 01:43

@ParthSareen ParthSareen left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments but the type update looks good

Comment thread examples/web-search-crawl.py Outdated
Comment on lines +23 to +24
for query, search_results in results.results.items():
output.append(f'Search results for "{query}":')
for i, result in enumerate(search_results, 1):
output.append(f'{i}. {result.title}')
output.append(f' URL: {result.url}')
output.append(f' Content: {result.content}')
if isinstance(results.results, dict):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we matching this on results.results?

*,
query: Optional[str] = None,
url: Optional[str] = None,
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of two optionals, just have query and make it mandatory to call the function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's actually just remove these - the model should have context from the attached message - we can just focus on the result

Comment thread examples/web-search-crawl.py Outdated
Comment on lines +25 to +44
for q, search_results in results.results.items():
output.append(f'Search results for "{q}":')
for i, result in enumerate(search_results, 1):
title = getattr(result, 'title', None)
url_value = getattr(result, 'url', None)
output.append(f'{i}. {title}' if title else f'{i}. {getattr(result, "content", "")}')
if url_value:
output.append(f' URL: {url_value}')
output.append(f' Content: {getattr(result, "content", "")}')
output.append('')
else:
if query:
output.append(f'Search results for "{query}":')
for i, result in enumerate(results.results, 1):
title = getattr(result, 'title', None)
url_value = getattr(result, 'url', None)
output.append(f'{i}. {title}' if title else f'{i}. {getattr(result, "content", "")}')
if url_value:
output.append(f' URL: {url_value}')
output.append(f' Content: {getattr(result, "content", "")}')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, you can directly assign from the type like earlier as long as you are matching on the right type

Comment thread examples/web-search-crawl.py
Comment thread examples/web-search-crawl.py Outdated
Comment on lines +89 to +100
args = tool_call.function.arguments
result: Union[WebSearchResponse, WebFetchResponse] = function_to_call(**args)
print('Result from tool call name: ', tool_call.function.name, 'with arguments: ', args)

if tool_call.function.name == 'web_search':
formatted = format_tool_results(result, query=args.get('query'))
elif tool_call.function.name == 'web_fetch':
formatted = format_tool_results(result, url=args.get('url'))
else:
formatted = format_tool_results(result)

print('Result: ', formatted[:200])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this change minimal like before?

Comment thread examples/web-search-crawl.py Outdated

# caps the result at ~2000 tokens
messages.append({'role': 'tool', 'content': format_tool_results(result)[: 2000 * 4], 'tool_name': tool_call.function.name})
messages.append({'role': 'tool', 'content': formatted[: 2000 * 4], 'tool_name': tool_call.function.name})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming to formatted_tool_results or something alike

Comment thread ollama/_client.py Outdated
return cls(**(await self._request_raw(*args, **kwargs)).json())

async def websearch(self, queries: Sequence[str], max_results: int = 3) -> WebSearchResponse:
async def websearch(self, query: str, max_results: int = 3) -> WebSearchResponse:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't realize i didn't update the naming for these. should be web_search

Comment thread ollama/_client.py Outdated
)

async def webcrawl(self, urls: Sequence[str]) -> WebCrawlResponse:
async def webfetch(self, url: str) -> WebFetchResponse:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def webfetch(self, url: str) -> WebFetchResponse:
async def web_fetch(self, url: str) -> WebFetchResponse:

@npardal
npardal force-pushed the nicole/shape-update branch from 18b415d to 81c71ba Compare September 23, 2025 19:00
@npardal
npardal marked this pull request as draft September 23, 2025 19:06
@ParthSareen ParthSareen changed the title client/types: web_search + web_fetch shape update client/types: update web search and fetch API Sep 23, 2025
@ParthSareen
ParthSareen marked this pull request as ready for review September 23, 2025 20:27
@ParthSareen
ParthSareen merged commit 16f344f into main Sep 23, 2025
2 checks passed
@ParthSareen
ParthSareen deleted the nicole/shape-update branch September 23, 2025 20:27
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 this pull request may close these issues.

2 participants