MCPcopy
hub / github.com/ModelTC/LightLLM / test_stream_function_call

Function test_stream_function_call

test/test_api/test_openai_api.py:472–508  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

470
471
472def test_stream_function_call():
473
474 client = LightLLMClient()
475
476 tools = [
477 {
478 "type": "function",
479 "function": {
480 "name": "get_weather",
481 "description": "获取指定城市的天气信息",
482 "parameters": {
483 "type": "object",
484 "properties": {
485 "city": {"type": "string", "description": "城市名称"},
486 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
487 },
488 "required": ["city"],
489 },
490 },
491 }
492 ]
493
494 try:
495 print("用户: 上海今天天气怎么样?")
496 print("助手: ", end="", flush=True)
497
498 for chunk in client.stream_function_call("上海今天天气怎么样?", tools):
499 if chunk["type"] == "content":
500 print(chunk["data"], end="", flush=True)
501 elif chunk["type"] == "tool_call":
502 print(f"\n[函数调用: {chunk['data']['function']['name']}]")
503 if chunk["data"]["function"].get("arguments"):
504 print(f"参数: {chunk['data']['function']['arguments']}")
505 print("\n")
506
507 except Exception as e:
508 print(f"错误: {e}")
509
510
511def test_token_completions():

Callers 1

mainFunction · 0.85

Calls 3

stream_function_callMethod · 0.95
LightLLMClientClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected