mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-29 07:14:20 +00:00
fix(brave-search): change tool name and standardize response format
- Change tool name from 'web_search' to 'web_search_brave' to avoid conflicts with Tavily - Standardize response format to JSON with 'query' and 'top_k' fields for consistency - Remove built_in_type parameter from ToolDef to match Tavily implementation - Return structured dict instead of string from _clean_result_by_type method Fixes #2606: Resolves tool name conflicts and response format inconsistencies that were causing non-deterministic behavior and poor user experience
This commit is contained in:
parent
ec2ce3ef9d
commit
a0a8b86fc8
1 changed files with 6 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
|||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
@ -18,7 +19,6 @@ from llama_stack.apis.tools import (
|
|||
ToolRuntime,
|
||||
)
|
||||
from llama_stack.distribution.request_headers import NeedsRequestProviderData
|
||||
from llama_stack.models.llama.datatypes import BuiltinTool
|
||||
from llama_stack.providers.datatypes import ToolGroupsProtocolPrivate
|
||||
|
||||
from .config import BraveSearchToolConfig
|
||||
|
@ -54,7 +54,7 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe
|
|||
return ListToolDefsResponse(
|
||||
data=[
|
||||
ToolDef(
|
||||
name="web_search",
|
||||
name="web_search_brave",
|
||||
description="Search the web for information",
|
||||
parameters=[
|
||||
ToolParameter(
|
||||
|
@ -63,7 +63,6 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe
|
|||
parameter_type="string",
|
||||
)
|
||||
],
|
||||
built_in_type=BuiltinTool.brave_search,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
@ -85,9 +84,10 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe
|
|||
)
|
||||
response.raise_for_status()
|
||||
results = self._clean_brave_response(response.json())
|
||||
content_items = "\n".join([str(result) for result in results])
|
||||
# Format response consistently with Tavily (JSON with query and top_k)
|
||||
formatted_response = {"query": kwargs["query"], "top_k": results}
|
||||
return ToolInvocationResult(
|
||||
content=content_items,
|
||||
content=json.dumps(formatted_response),
|
||||
)
|
||||
|
||||
def _clean_brave_response(self, search_response):
|
||||
|
@ -143,4 +143,4 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe
|
|||
else:
|
||||
cleaned = {k: v for k, v in results.items() if k in selected_keys}
|
||||
|
||||
return str(cleaned)
|
||||
return cleaned
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue