测试logprobs功能
()
| 547 | |
| 548 | |
| 549 | def test_logprobs(): |
| 550 | """测试logprobs功能""" |
| 551 | client = LightLLMClient() |
| 552 | |
| 553 | try: |
| 554 | print("=== 测试logprobs ===") |
| 555 | result = client.completions_with_logprobs("The capital of France is", logprobs=5, max_tokens=20) |
| 556 | print("提示: The capital of France is") |
| 557 | print("补全:", result["choices"][0]["text"]) |
| 558 | |
| 559 | # 检查logprobs结构 |
| 560 | logprobs = result["choices"][0]["logprobs"] |
| 561 | if logprobs: |
| 562 | print("Logprobs结构:") |
| 563 | print(f" tokens: {logprobs.get('tokens', [])[:5]}...") # 只显示前5个 |
| 564 | print(f" token_logprobs: {logprobs.get('token_logprobs', [])[:5]}...") |
| 565 | print(f" text_offset: {logprobs.get('text_offset', [])[:5]}...") |
| 566 | print(f" top_logprobs: {logprobs.get('top_logprobs', [])[:2]}...") # 只显示前2个 |
| 567 | print() |
| 568 | except Exception as e: |
| 569 | print(f"错误: {e}") |
| 570 | |
| 571 | |
| 572 | def test_echo(): |
no test coverage detected