@@ -11,7 +11,7 @@ def build_google_search_function() -> list[ChatCompletionToolParam]:
11
11
{
12
12
"type" : "function" ,
13
13
"function" : {
14
- "name" : "search_database " ,
14
+ "name" : "search_google " ,
15
15
"description" : "Search for relevant products based on user query" ,
16
16
"parameters" : {
17
17
"type" : "object" ,
@@ -20,6 +20,17 @@ def build_google_search_function() -> list[ChatCompletionToolParam]:
20
20
"type" : "string" ,
21
21
"description" : "Query string to use for full text search, e.g. 'ตรวจสุขภาพ'" ,
22
22
},
23
+ "locations" : {
24
+ "type" : "array" ,
25
+ "items" : {
26
+ "type" : "string" ,
27
+ },
28
+ "description" : """
29
+ A list of nearby districts(Amphoes) from what the user provides.
30
+ For example, if the user says `รังสิต`, the locations should be
31
+ [`ธัญบุรี`, `เมืองปทุมธานี`, `คลองหลวง`, `ลำลูกกา`].
32
+ """
33
+ }
23
34
},
24
35
"required" : ["search_query" ],
25
36
},
@@ -30,19 +41,19 @@ def build_google_search_function() -> list[ChatCompletionToolParam]:
30
41
def extract_search_arguments (chat_completion : ChatCompletion ):
31
42
response_message = chat_completion .choices [0 ].message
32
43
search_query = None
44
+
33
45
34
46
if response_message .tool_calls :
35
47
for tool in response_message .tool_calls :
36
48
if tool .type != "function" :
37
49
continue
38
50
function = tool .function
39
- if function .name == "search_database " :
51
+ if function .name == "search_google " :
40
52
arg = json .loads (function .arguments )
41
53
search_query = arg .get ("search_query" )
42
- elif query_text := response_message .content :
43
- search_query = query_text .strip ()
54
+ locations = arg .get ("locations" , [])
44
55
45
- return search_query
56
+ return search_query , locations
46
57
47
58
48
59
def build_specify_package_function () -> list [ChatCompletionToolParam ]:
0 commit comments