39 lines
948 B
Python
39 lines
948 B
Python
|
|
import requests
|
||
|
|
import json
|
||
|
|
|
||
|
|
# API配置
|
||
|
|
url = 'https://api.lingyaai.cn/v1/messages'
|
||
|
|
api_key = 'sk-bSjxX2X1FAptXPcBjItcMcbRvcGFZTtRRcUf52BGQr1dscZM' # 请替换为你的实际API密钥
|
||
|
|
|
||
|
|
# 读取scene.txt文件内容
|
||
|
|
with open('scene.txt', 'r', encoding='utf-8') as f:
|
||
|
|
scene_content = f.read()
|
||
|
|
|
||
|
|
# 请求头
|
||
|
|
headers = {
|
||
|
|
'anthropic-version': '2023-06-01',
|
||
|
|
'content-type': 'application/json',
|
||
|
|
'x-api-key': api_key
|
||
|
|
}
|
||
|
|
|
||
|
|
# 请求数据
|
||
|
|
data = {
|
||
|
|
'model': 'claude-sonnet-4-5-20250929',
|
||
|
|
'max_tokens': 1024,
|
||
|
|
'messages': [
|
||
|
|
{'role': 'user', 'content': scene_content}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
# 发送POST请求
|
||
|
|
response = requests.post(url, headers=headers, json=data)
|
||
|
|
|
||
|
|
# 打印响应
|
||
|
|
print(f'状态码: {response.status_code}')
|
||
|
|
print(f'响应内容: {response.text}')
|
||
|
|
|
||
|
|
# 如果需要解析JSON响应
|
||
|
|
if response.status_code == 200:
|
||
|
|
result = response.json()
|
||
|
|
print(f'\nJSON响应: {json.dumps(result, indent=2, ensure_ascii=False)}')
|