调用api文档时返回内容为空
问题描述 / Problem Description 我在试图调用api文档进行回答时,返回了空的text。
复现问题的步骤 / Steps to Reproduce
-
启动了langchain api文档相关服务,如图所示。
-
写了一个本地的调用代码,按照文档示例给定了输入。
下面图片为示例
-
print result,可以看到返回了空的answer。
访问方式或调用代码是否有问题?
Based on the information you provided and the context from the Langchain-Chatchat repository, there are a few potential issues that could be causing your problem.
Firstly, there are two similar issues in the Langchain-Chatchat repository that might be relevant to your situation. The first one is [FEATURE] 能否支持本地的API调用, which suggests that you can call a local API by modifying the model_config.py file. You can add your local API address to the model configuration in model_config.py by referring to the suggestions in this issue. The second one is [BUG] 我无法调用该项目的api功能, but the context does not provide more details about this issue.
Secondly, there might be a problem with the way you're using the requests library to call the "Longchain-ChatChat API Server" version 1.2.7. The issue lies in how you process the response with iter_content and attempt to decode and load JSON data. A safer and more general approach would be to use response.json() to directly parse the JSON response if the API returns a standard JSON object. Here's a revised version of the critical part:
response = requests.post(url, headers=headers, json=data)
try:
result = response.json() # Directly parse the JSON response
except json.JSONDecodeError:
print("Error decoding JSON from response")
result = []
Thirdly, the expected format of the JSON payload for creating chat sessions, receiving feedback, and teaching the chatbot new responses in the "Longchain-ChatChat API Server" version 1.2.7 is as follows:
{
"query": "What's the weather like today?",
"history": [
{
"role": "user",
"content": "What's the weather forecast for today?"
},
{
"role": "assistant",
"content": "The weather forecast for today is sunny."
}
],
"stream": false,
"model_name": "gpt-3",
"temperature": 0.7,
"max_tokens": 150,
"prompt_name": "default"
}
Lastly, the "Longchain-ChatChat API Server" version 1.2.7 handles the receiving of feedback through a specific API endpoint. The endpoint for receiving feedback and teaching new responses is /chat/feedback. However, the provided code does not explicitly detail how the feedback is used to teach new responses or improve the model's performance.
I hope this information helps you solve your problem. If you need further assistance, please provide more details about your issue.
Sources
- [FEATURE] 能否支持本地的API调用
- [BUG] 我无法调用该项目的api功能
- tests/api/test_stream_chat_api_thread.py
- server/chat/agent_chat.py
- server/api.py
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
这个问题已经被标记为 stale ,因为它已经超过 30 天没有任何活动。