'commit'
This commit is contained in:
31
test01.py
31
test01.py
@@ -1,31 +0,0 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
# API配置
|
||||
url = 'https://api.lingyaai.cn/v1/images/generations'
|
||||
api_key = 'sk-bSjxX2X1FAptXPcBjItcMcbRvcGFZTtRRcUf52BGQr1dscZM' # 请替换为你的实际API密钥
|
||||
|
||||
# 请求头
|
||||
headers = {
|
||||
'Authorization': f'Bearer {api_key}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# 请求数据
|
||||
data = {
|
||||
'prompt': '帮我生成一张数字化校园的结构图',
|
||||
'model': 'nano-banana-pro',
|
||||
'aspect_ratio': '1:1'
|
||||
}
|
||||
|
||||
# 发送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'JSON响应: {json.dumps(result, indent=2, ensure_ascii=False)}')
|
||||
38
test02.py
38
test02.py
@@ -1,38 +0,0 @@
|
||||
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)}')
|
||||
Reference in New Issue
Block a user