mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
- 移除所有未使用的导入 (unused imports) - 修复未使用的变量 (unused variables) - 修复未使用的 mut 声明 - 修复 private_interfaces 警告 - 为有用但未使用的代码添加 #[allow(dead_code)] 属性 - 修复前端 TypeScript 未使用变量警告 - 更新版本号到 v0.26.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import http.client
|
|
import json
|
|
|
|
conn = http.client.HTTPConnection("127.0.0.1", 8999)
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": "Bearer Proxycast-key11"
|
|
}
|
|
|
|
data = {
|
|
"model": "claude-opus-4-5-20251101",
|
|
"messages": [{"role": "user", "content": "你好"}],
|
|
"stream": True
|
|
}
|
|
|
|
print("发送流式请求...")
|
|
print(f"请求数据: {json.dumps(data, ensure_ascii=False)}\n")
|
|
conn.request("POST", "/v1/chat/completions", json.dumps(data), headers)
|
|
|
|
response = conn.getresponse()
|
|
print(f"HTTP 状态码: {response.status}")
|
|
print(f"响应头: {dict(response.getheaders())}\n")
|
|
|
|
print("开始接收流式数据:\n")
|
|
chunk_count = 0
|
|
content_buffer = ""
|
|
|
|
while True:
|
|
line = response.readline()
|
|
if not line:
|
|
break
|
|
|
|
chunk_count += 1
|
|
decoded = line.decode('utf-8').strip()
|
|
|
|
if not decoded:
|
|
continue
|
|
|
|
print(f"Chunk {chunk_count}: {decoded[:150]}...")
|
|
|
|
if decoded.startswith('data: '):
|
|
json_str = decoded[6:]
|
|
if json_str == '[DONE]':
|
|
print(" → 流结束")
|
|
break
|
|
|
|
try:
|
|
data_obj = json.loads(json_str)
|
|
if 'choices' in data_obj and data_obj['choices']:
|
|
delta = data_obj['choices'][0].get('delta', {})
|
|
content = delta.get('content', '')
|
|
if content:
|
|
content_buffer += content
|
|
print(f" ✓ 内容: {content}")
|
|
except json.JSONDecodeError as e:
|
|
print(f" ✗ JSON 解析失败: {e}")
|
|
|
|
print(f"\n总共接收 {chunk_count} 个数据块")
|
|
print(f"累积内容: {content_buffer}")
|
|
|
|
conn.close()
|