forked from Sen-illion/DN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_llm.py
More file actions
39 lines (32 loc) · 1.1 KB
/
test_llm.py
File metadata and controls
39 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
import os, time
os.environ['PYTHONIOENCODING'] = 'utf-8'
# 直接测试 LLM API 调用
from dotenv import load_dotenv
load_dotenv("C:/Users/User/Desktop/DN-main/.env")
import openai
api_key = os.environ.get("Camera_Analyst_API_KEY", "")
base_url = os.environ.get("Camera_Analyst_BASE_URL", "")
model = os.environ.get("Camera_Analyst_MODEL", "")
print(f"API Key: {api_key[:20]}...")
print(f"Base URL: {base_url}")
print(f"Model: {model}")
client = openai.OpenAI(api_key=api_key, base_url=base_url)
print("\n发送测试请求...")
start = time.time()
try:
resp = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "说 hello"}],
max_tokens=50,
timeout=60
)
elapsed = time.time() - start
print(f"成功! 耗时: {elapsed:.1f}秒")
print(f"回复: {resp.choices[0].message.content}")
except Exception as e:
elapsed = time.time() - start
print(f"失败! 耗时: {elapsed:.1f}秒")
print(f"错误: {e}")