()
| 470 | |
| 471 | |
| 472 | def 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 | |
| 511 | def test_token_completions(): |
no test coverage detected