49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import openai
|
|
import time
|
|
|
|
# 硬编码配置
|
|
base_url = "https://api.moonshot.cn/v1"
|
|
api_key = "sk-xW0xjfQM6Mp9ZCWMLlnHiRJcpEOIZPTkXcN0dQ15xpZSuw2y"
|
|
|
|
print("=== 简化版API测试 ===")
|
|
print(f"Base URL: {base_url}")
|
|
print(f"API Key: {api_key[:10]}...{api_key[-10:]}")
|
|
|
|
# 等待避免并发限制
|
|
print("\n等待10秒避免组织并发限制...")
|
|
time.sleep(10)
|
|
|
|
# 创建客户端
|
|
client = openai.Client(
|
|
base_url=base_url,
|
|
api_key=api_key,
|
|
)
|
|
|
|
# 简单的对话测试
|
|
print("\n正在发送简单对话请求...")
|
|
try:
|
|
response = client.chat.completions.create(
|
|
model="kimi-k2-thinking",
|
|
messages=[
|
|
{"role": "system", "content": "你是一个友好的助手。"},
|
|
{"role": "user", "content": "你好!请简单介绍一下今天是什么日期,以及你能帮我做什么?"}
|
|
],
|
|
max_tokens=500,
|
|
temperature=0.7,
|
|
)
|
|
|
|
print("\n=== 成功获取响应 ===")
|
|
print("思考过程:")
|
|
if hasattr(response.choices[0].message, 'reasoning_content'):
|
|
print(response.choices[0].message.reasoning_content[:200] + "...")
|
|
|
|
print("\n回复内容:")
|
|
print(response.choices[0].message.content)
|
|
|
|
print(f"\n使用token数: {response.usage.total_tokens}")
|
|
|
|
except Exception as e:
|
|
print(f"错误: {e}")
|
|
|
|
print("\n=== 测试完成 ===")
|