Update app.py
Browse files
app.py
CHANGED
|
@@ -184,6 +184,7 @@ available_tools = [
|
|
| 184 |
]
|
| 185 |
|
| 186 |
# --- Fixed Streaming Response Generator ---
|
|
|
|
| 187 |
async def generate_streaming_response(messages: List[Dict], use_search: bool, temperature: float):
|
| 188 |
"""Generate streaming response with optional search"""
|
| 189 |
|
|
@@ -199,7 +200,8 @@ async def generate_streaming_response(messages: List[Dict], use_search: bool, te
|
|
| 199 |
|
| 200 |
if use_search:
|
| 201 |
llm_kwargs["tools"] = available_tools
|
| 202 |
-
|
|
|
|
| 203 |
|
| 204 |
source_links = []
|
| 205 |
response_content = ""
|
|
@@ -259,13 +261,13 @@ async def generate_streaming_response(messages: List[Dict], use_search: bool, te
|
|
| 259 |
|
| 260 |
function_name = tool_call["function"]["name"]
|
| 261 |
|
| 262 |
-
if function_name == "
|
| 263 |
try:
|
| 264 |
args = json.loads(tool_call["function"]["arguments"])
|
| 265 |
query = args.get("query", "").strip()
|
| 266 |
if query:
|
| 267 |
logger.info(f"Executing search with query: {query}")
|
| 268 |
-
search_results = await
|
| 269 |
|
| 270 |
if search_results:
|
| 271 |
processed_any_tools = True
|
|
|
|
| 184 |
]
|
| 185 |
|
| 186 |
# --- Fixed Streaming Response Generator ---
|
| 187 |
+
|
| 188 |
async def generate_streaming_response(messages: List[Dict], use_search: bool, temperature: float):
|
| 189 |
"""Generate streaming response with optional search"""
|
| 190 |
|
|
|
|
| 200 |
|
| 201 |
if use_search:
|
| 202 |
llm_kwargs["tools"] = available_tools
|
| 203 |
+
# FIX: Let the model decide when to call the tool
|
| 204 |
+
llm_kwargs["tool_choice"] = "auto"
|
| 205 |
|
| 206 |
source_links = []
|
| 207 |
response_content = ""
|
|
|
|
| 261 |
|
| 262 |
function_name = tool_call["function"]["name"]
|
| 263 |
|
| 264 |
+
if function_name == "Google Search":
|
| 265 |
try:
|
| 266 |
args = json.loads(tool_call["function"]["arguments"])
|
| 267 |
query = args.get("query", "").strip()
|
| 268 |
if query:
|
| 269 |
logger.info(f"Executing search with query: {query}")
|
| 270 |
+
search_results = await Google Search_tool_async(query)
|
| 271 |
|
| 272 |
if search_results:
|
| 273 |
processed_any_tools = True
|