Commit 652c33e5 authored by chenych's avatar chenych
Browse files

Fix bugs

parent cf14b883
...@@ -65,7 +65,7 @@ def stream_query(query, user_id=None): ...@@ -65,7 +65,7 @@ def stream_query(query, user_id=None):
'query': query, 'query': query,
'history': [] 'history': []
} }
resp = requests.get(url, resp = requests.post(url,
headers=headers, headers=headers,
data=json.dumps(data), data=json.dumps(data),
timeout=300, timeout=300,
......
...@@ -4,7 +4,7 @@ import json ...@@ -4,7 +4,7 @@ import json
import httpx import httpx
import configparser import configparser
import torch import torch
import requests
import numpy as np import numpy as np
from loguru import logger from loguru import logger
from BCEmbedding.tools.langchain import BCERerank from BCEmbedding.tools.langchain import BCERerank
...@@ -48,9 +48,9 @@ class OpenAPIClient: ...@@ -48,9 +48,9 @@ class OpenAPIClient:
continue continue
yield output yield output
async def get_response(self, headers, data): def get_response(self, headers, data):
async with httpx.AsyncClient() as client:
resp = await client.post(self.url, json=data, headers=headers, timeout=300) resp = requests.post(self.url, json=data, headers=headers, timeout=300)
try: try:
result = json.loads(resp.content.decode("utf-8")) result = json.loads(resp.content.decode("utf-8"))
output = result['choices'][0]['message']['content'] output = result['choices'][0]['message']['content']
......
...@@ -137,10 +137,8 @@ class Worker: ...@@ -137,10 +137,8 @@ class Worker:
if len(chunks) == 0: if len(chunks) == 0:
logger.debug('Response by finetune model') logger.debug('Response by finetune model')
response = self.response_by_finetune(query, history=history) response = await self.response_by_finetune(query, history=history)
data = json.loads(response.content.decode("utf-8")) chunks = [response]
chunks = [output]
elif use_template: elif use_template:
logger.debug('Response by template') logger.debug('Response by template')
response = self.format_rag_result(chunks, references, stream=stream) response = self.format_rag_result(chunks, references, stream=stream)
......
...@@ -14,7 +14,7 @@ from BCEmbedding.tools.langchain import BCERerank ...@@ -14,7 +14,7 @@ from BCEmbedding.tools.langchain import BCERerank
from langchain.retrievers import ContextualCompressionRetriever from langchain.retrievers import ContextualCompressionRetriever
from langchain_community.vectorstores.utils import DistanceStrategy from langchain_community.vectorstores.utils import DistanceStrategy
from requests.exceptions import RequestException from requests.exceptions import RequestException
from elastic_keywords_search import ElasticKeywordsSearch from .elastic_keywords_search import ElasticKeywordsSearch
app = FastAPI() app = FastAPI()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment