MindSearch
MindSearch copied to clipboard
硅基流动 API Special Token 不显示
from openai import OpenAI
import os
def flowapi(action):
client = OpenAI(api_key=os.getenv('FLOWAPIKEY'), base_url="https://api.siliconflow.cn/v1")
message = [dict(role='system', content="""
你是一个可以调用外部工具的助手,可以使用的工具包括:
[
{
"name": "multiply",
"description": "Multiply two numbers",
"parameters": {
"type": "object",
"properties": {
"num1": {"type": "number"},
"num2": {"type": "number"},
},
"required": ["num1", "num2"],
},
}
]
如果使用工具请遵循以下格式回复:
```
**Thought**:思考过程
**{action}**: {"name": "工具名", "parameters": {"parameter1": value1, "parameter2": value2}}
```
工具返回按照以下格式回复:
```
Resonse:调用工具后的结果
```
如果你已经知道了答案,或者你不需要工具,请直接回复答案。
开始!
""".replace("{action}", action)
),
dict(role='user', content='1024 乘以 2033 等于多少')]
response = client.chat.completions.create(
model='internlm/internlm2_5-7b-chat',
messages=message,
temperature=0,
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content, end='')
if __name__ == '__main__':
print("without special token 1")
flowapi('Action')
print("without special token 2")
flowapi('Tool')
print("without special token 3")
flowapi('Plugin')
print("with special token ")
flowapi('<|action_start|>')
output
(openai) ➜ openai_playground python test.py
without special token 1
None分析「1024 乘以 2033 等于多少」这个问题,我们可以计算「1024*2033」得到答案。
**Thought**:根据您的要求,我们可以调用计算器API得到:1024*2033
**Action**: {"name": "multiply", "parameters": {"num1": 1024, "num2": 2033}}
without special token 2
分析「1024 乘以 2033 等于多少」这个问题,我们可以计算「1024*2033」得到答案。
**Thought**:根据乘法的定义,我们可以直接将两个数相乘得到结果。
**Tool**: {"name": "multiply", "parameters": {"num1": 1024, "num2": 2033}}None
without special token 3
None分析「1024 乘以 2033 等于多少」这个问题,我们可以计算「1024*2033」得到答案。
**Thought**:根据您的要求,我们可以调用计算器API得到:1024*2033
**Plugin**: {"name": "multiply", "parameters": {"num1": 1024, "num2": 2033}}None
with special token
None分析「1024 乘以 2033 等于多少」这个问题,我们可以计算「1024*2033」得到答案。
**Thought**:根据乘法的定义,我们可以直接将两个数相乘得到结果。
****: {"name": "multiply", "parameters": {"num1": 1024, "num2": 2033}}None%