@@ -201,10 +201,10 @@ Register handlers for your functions using the LLM service's [`register_function
201
201
llm = OpenAILLMService(api_key = " your-api-key" , model = " gpt-4" )
202
202
203
203
# Main function handler - called to execute the function
204
- async def fetch_weather_from_api (function_name , tool_call_id , args , llm , context , result_callback ):
204
+ async def fetch_weather_from_api (params : FunctionCallParams ):
205
205
# Fetch weather data from your API
206
206
weather_data = {" conditions" : " sunny" , " temperature" : " 75" }
207
- await result_callback(weather_data)
207
+ await params. result_callback(weather_data)
208
208
209
209
# Register the function
210
210
llm.register_function(
@@ -243,12 +243,13 @@ pipeline = Pipeline([
243
243
244
244
### Handler Parameters
245
245
246
- - ` function_name ` : Name of the called function
247
- - ` tool_call_id ` : Unique identifier for the function call
248
- - ` args ` : Arguments passed by the LLM
249
- - ` llm ` : Reference to the LLM service
250
- - ` context ` : Current conversation context
251
- - ` result_callback ` : Async function to return results
246
+ - ` params ` : FunctionCallParams
247
+ - ` function_name ` : Name of the called function
248
+ - ` arguments ` : Arguments passed by the LLM
249
+ - ` tool_call_id ` : Unique identifier for the function call
250
+ - ` llm ` : Reference to the LLM service
251
+ - ` context ` : Current conversation context
252
+ - ` result_callback ` : Async function to return results
252
253
253
254
### Return Values
254
255
@@ -287,18 +288,18 @@ Controls whether the LLM should generate a response after the function call:
287
288
### Example Usage
288
289
289
290
``` python
290
- async def fetch_weather_from_api (function_name , tool_call_id , args , llm , context , result_callback ):
291
+ async def fetch_weather_from_api (params : FunctionCallParams ):
291
292
# Fetch weather data
292
293
weather_data = {" conditions" : " sunny" , " temperature" : " 75" }
293
294
294
295
# Don't run LLM after this function call
295
296
properties = FunctionCallResultProperties(run_llm = False )
296
297
297
- await result_callback(weather_data, properties = properties)
298
+ await params. result_callback(weather_data, properties = properties)
298
299
299
- async def query_database (function_name , tool_call_id , args , llm , context , result_callback ):
300
+ async def query_database (params : FunctionCallParams ):
300
301
# Query database
301
- results = await db.query(args [" query" ])
302
+ results = await db.query(params.arguments [" query" ])
302
303
303
304
async def on_update ():
304
305
await notify_system(" Database query complete" )
@@ -309,7 +310,7 @@ async def query_database(function_name, tool_call_id, args, llm, context, result
309
310
on_context_updated = on_update
310
311
)
311
312
312
- await result_callback(results, properties = properties)
313
+ await params. result_callback(results, properties = properties)
313
314
```
314
315
315
316
## Next steps
0 commit comments