50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
|
|
import sys
|
||
|
|
import os
|
||
|
|
import asyncio
|
||
|
|
import logging
|
||
|
|
import traceback
|
||
|
|
|
||
|
|
# Add project root to path
|
||
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||
|
|
|
||
|
|
# Configure logging
|
||
|
|
logging.basicConfig(level=logging.INFO)
|
||
|
|
|
||
|
|
from Util.GeminiClient import GeminiClient
|
||
|
|
|
||
|
|
async def main():
|
||
|
|
print("=== Testing LingYa LLM via Util.GeminiClient ===")
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 使用 LingYa 提供商初始化客户端
|
||
|
|
client = GeminiClient(provider="LingYa")
|
||
|
|
|
||
|
|
messages = [
|
||
|
|
{"role": "developer", "content": "你是一个幽默的助手。"},
|
||
|
|
{"role": "user", "content": "用一句话形容程序员的生活。"}
|
||
|
|
]
|
||
|
|
|
||
|
|
# 使用 gpt-5.2 进行测试,流式响应更稳定
|
||
|
|
# 项目默认配置可能是 gemini-3-pro-preview
|
||
|
|
# model = Config.LINGYA_API_GEMINI_MODEL
|
||
|
|
model = "gpt-5.2"
|
||
|
|
print(f"Requesting with model: {model}")
|
||
|
|
print(f"\n[Response]:")
|
||
|
|
|
||
|
|
async for content in client.send_chat_completion_stream(messages, model=model):
|
||
|
|
print(content, end="", flush=True)
|
||
|
|
print("\n")
|
||
|
|
|
||
|
|
except BaseException as e:
|
||
|
|
print(f"Test failed: {e}")
|
||
|
|
traceback.print_exc()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
try:
|
||
|
|
asyncio.run(main())
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
print("\nInterrupted by user")
|
||
|
|
except BaseException as e:
|
||
|
|
print(f"\nMain failed: {e}")
|
||
|
|
traceback.print_exc()
|