ai-chat-ui/server/utils/test_glm_search.py

32 lines
885 B
Python

import os
import sys
import asyncio
from pathlib import Path
# Add project root to sys.path
root_dir = Path(__file__).parent
sys.path.insert(0, str(root_dir))
from utils.glm_adapter import glm_stream_generator, _ensure_venv, glm_chat_sync
# Set API key from .env if needed
from dotenv import load_dotenv
load_dotenv()
async def test_stream():
msgs = [{"role": "user", "content": "今天北京天气怎样?"}]
print("Testing stream...")
async for chunk in glm_stream_generator(msgs, "glm-4.5-air", 0.7, 1024, web_search=True):
print(chunk, end="")
def test_sync():
msgs = [{"role": "user", "content": "今天几号?武汉天气怎样?"}]
print("Testing sync...")
res = glm_chat_sync(msgs, "glm-4.5-air", 0.7, 1024, web_search=True)
print(res)
if __name__ == "__main__":
_ensure_venv()
# test_sync()
asyncio.run(test_stream())