FastGPT通过API调用工作流问答
版本
fastgpt v4.8.10
使用说明
注意两个参数
-
stream 是否流式输出
-
detail 是否体现工作流过程细节
代码模板
import requests
import pandas as pd
def get_completion(question):
# Define the URL and headers
url = "http://xxxx:3000/api/v1/chat/completions"
headers = {
"Authorization": "Bearer ",
"Content-Type": "application/json"
}
data = {
"chatId": "lizhihiui",
"stream": False,
"detail": False,
"responseChatItemId": "my_responseChatItemId",
"variables": {
"uid": "asdfadsfasfd2323",
"name": "张三"
},
"messages": [
{
"role": "user",
"content": question
}
]
}
response = requests.post(url, json=data, headers=headers)
api_response = response.json()
if 'code' in api_response and api_response['code'] == 500:
return "报错"
content = api_response["choices"][0]["message"]["content"]
return content
print(get_completion("你是谁"))