fix: Redis连接支持环境变量,修复json.loads错误

This commit is contained in:
2026-04-22 17:10:04 +08:00
parent d929a15dec
commit a310e7a38e

View File

@@ -1,4 +1,5 @@
import json import json
import os
import redis import redis
import uuid import uuid
import requests import requests
@@ -9,7 +10,11 @@ from typing import Optional, List
app = FastAPI() app = FastAPI()
# 连接到Redis服务器(默认端口是6379) # 连接到Redis服务器(默认端口是6379)
redis_instance = redis.Redis(host='localhost', port=6379, db=0) redis_instance = redis.Redis(
host=os.getenv("REDIS_HOST", "localhost"),
port=int(os.getenv("REDIS_PORT", "6379")),
db=0,
)
mock_time_created = 20230512084843 mock_time_created = 20230512084843
mock_id1 = "131424542124" mock_id1 = "131424542124"
mock_id2 = "1231414141541252525" mock_id2 = "1231414141541252525"
@@ -48,8 +53,9 @@ def request_dify_api(question, request, conversation_id):
# 发送POST请求 # 发送POST请求
response = requests.post(url, data=json.dumps(data), headers=headers_json) response = requests.post(url, data=json.dumps(data), headers=headers_json)
data = json.loads(response) resp_data = response.json()
return data["answer"] return resp_data["answer"]
return resp_data["answer"]
# 对接dify,流式传输 # 对接dify,流式传输