166 lines
3.8 KiB
Markdown
Executable File
166 lines
3.8 KiB
Markdown
Executable File
# LLM关系抽取测试报告
|
|
|
|
**日期**: 2026-04-10 11:53 GMT+8
|
|
**状态**: API验证成功,Python客户端待调试
|
|
|
|
---
|
|
|
|
## API连接测试
|
|
|
|
### curl测试 ✅
|
|
|
|
```bash
|
|
curl -X POST https://coding.dashscope.aliyuncs.com/v1/chat/completions \
|
|
-H "Authorization: Bearer sk-REDACTED" \
|
|
-d '{"model": "qwen3.6-plus", "messages": [{"role": "user", "content": "Hello"}]}'
|
|
```
|
|
|
|
**结果**: ✅ 成功
|
|
|
|
```json
|
|
{
|
|
"model": "qwen3.6-plus",
|
|
"choices": [{
|
|
"message": {
|
|
"content": "Hello! How can I assist you today?",
|
|
"reasoning_content": "Here's a thinking process..."
|
|
}
|
|
}]
|
|
}
|
|
```
|
|
|
|
### Python客户端测试 ❌
|
|
|
|
```python
|
|
from openai import OpenAI
|
|
client = OpenAI(api_key=api_key, base_url="https://coding.dashscope.aliyuncs.com/v1")
|
|
response = client.chat.completions.create(...)
|
|
```
|
|
|
|
**结果**: ⏳ 超时/无响应
|
|
|
|
---
|
|
|
|
## 问题分析
|
|
|
|
### 可能原因
|
|
|
|
1. **网络超时**: Python客户端默认超时时间可能过长
|
|
2. **代理设置**: 可能需要配置代理
|
|
3. **SSL证书**: 可能有证书验证问题
|
|
4. **DNS解析**: 域名解析可能较慢
|
|
|
|
### 解决方案
|
|
|
|
**方案1: 使用curl替代**
|
|
```python
|
|
import subprocess
|
|
import json
|
|
|
|
def call_llm_with_curl(prompt):
|
|
cmd = [
|
|
'curl', '-s', '-X', 'POST',
|
|
'https://coding.dashscope.aliyuncs.com/v1/chat/completions',
|
|
'-H', 'Content-Type: application/json',
|
|
'-H', f'Authorization: Bearer {api_key}',
|
|
'-d', json.dumps({
|
|
'model': 'qwen3.6-plus',
|
|
'messages': [{'role': 'user', 'content': prompt}],
|
|
'max_tokens': 500
|
|
})
|
|
]
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
|
return json.loads(result.stdout)
|
|
```
|
|
|
|
**方案2: 配置超时参数**
|
|
```python
|
|
from openai import OpenAI
|
|
import httpx
|
|
|
|
client = OpenAI(
|
|
api_key=api_key,
|
|
base_url="https://coding.dashscope.aliyuncs.com/v1",
|
|
http_client=httpx.Client(timeout=60.0)
|
|
)
|
|
```
|
|
|
|
---
|
|
|
|
## 修复后的提取器
|
|
|
|
### 使用curl的实现
|
|
|
|
```python
|
|
import subprocess
|
|
import json
|
|
|
|
def extract_relations_llm_curl(sections, entities, api_key):
|
|
"""使用curl调用百炼API"""
|
|
relations = []
|
|
|
|
for sec in sections:
|
|
text = sec['text'][:2000]
|
|
prompt = f"""从以下文本中提取基因关系...
|
|
|
|
文本: {text}
|
|
格式: gene_id | relation | target | evidence
|
|
"""
|
|
|
|
cmd = [
|
|
'curl', '-s', '-X', 'POST',
|
|
'https://coding.dashscope.aliyuncs.com/v1/chat/completions',
|
|
'-H', 'Content-Type: application/json',
|
|
'-H', f'Authorization: Bearer {api_key}',
|
|
'-d', json.dumps({
|
|
'model': 'qwen3.6-plus',
|
|
'messages': [
|
|
{'role': 'system', 'content': '你是基因关系提取助手'},
|
|
{'role': 'user', 'content': prompt}
|
|
],
|
|
'temperature': 0.1,
|
|
'max_tokens': 500
|
|
})
|
|
]
|
|
|
|
try:
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
|
response = json.loads(result.stdout)
|
|
content = response['choices'][0]['message']['content']
|
|
|
|
# 解析关系...
|
|
|
|
except Exception as e:
|
|
print(f"错误: {e}")
|
|
|
|
return relations
|
|
```
|
|
|
|
---
|
|
|
|
## 结论
|
|
|
|
### 当前状态
|
|
|
|
| 项目 | 状态 | 说明 |
|
|
|------|------|------|
|
|
| API Key读取 | ✅ | 修复成功 |
|
|
| curl调用 | ✅ | 工作正常 |
|
|
| Python客户端 | ❌ | 需要调试 |
|
|
| 章节文本保存 | ✅ | 工作正常 |
|
|
|
|
### 建议
|
|
|
|
1. **立即**: 使用curl替代Python客户端进行LLM调用
|
|
2. **短期**: 调试Python客户端连接问题
|
|
3. **长期**: 封装统一的LLM调用接口
|
|
|
|
### 下一步
|
|
|
|
创建使用curl的修复版提取器,测试完整流程。
|
|
|
|
---
|
|
|
|
**报告时间**: 2026-04-10 11:58 GMT+8
|
|
**签名**: 🧬🤖
|