-
Notifications
You must be signed in to change notification settings - Fork 841
client/types: update web search and fetch API #584
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments
There was a problem hiding this comment.
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
examples/web-search-crawl.py
Outdated
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): |
There was a problem hiding this comment.
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, | ||
): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
examples/web-search-crawl.py
Outdated
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", "")}') |
There was a problem hiding this comment.
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
examples/web-search-crawl.py
Outdated
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]) |
There was a problem hiding this comment.
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?
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}) |
There was a problem hiding this comment.
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
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: |
There was a problem hiding this comment.
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
ollama/_client.py
Outdated
) | ||
|
||
async def webcrawl(self, urls: Sequence[str]) -> WebCrawlResponse: | ||
async def webfetch(self, url: str) -> WebFetchResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async def webfetch(self, url: str) -> WebFetchResponse: | |
async def web_fetch(self, url: str) -> WebFetchResponse: |
18b415d
to
81c71ba
Compare
updated shapes of web_search and web_fetch to reflect go version