update chroma_chat

This commit is contained in:
ACBBZ
2024-05-23 04:02:50 +00:00
parent 99ecc45a47
commit 38c5d43e48

View File

@ -4,8 +4,7 @@ from fastapi import Request, Response, status
from fastapi.responses import JSONResponse
from .blackbox import Blackbox
from ..utils import chroma_setting
from .fastchat import Fastchat
from .chat import Chat
from .chroma_query import ChromaQuery
DEFAULT_COLLECTION_ID = "123"
@ -15,8 +14,8 @@ from injector import singleton,inject
class ChromaChat(Blackbox):
@inject
def __init__(self, fastchat: Fastchat, chroma_query: ChromaQuery):
self.fastchat = fastchat
def __init__(self, chat: Chat, chroma_query: ChromaQuery):
self.chat = chat
self.chroma_query = chroma_query
def __call__(self, *args, **kwargs):
@ -26,18 +25,18 @@ class ChromaChat(Blackbox):
data = args[0]
return isinstance(data, list)
def processing(self, question, setting: chroma_setting) -> str:
def processing(self, question, context: list) -> str:
if context == None:
context = []
# load or create collection
if setting is None:
collection_id = DEFAULT_COLLECTION_ID
else:
collection_id = setting.ChromaSetting.collection_ids[0]
# query it
chroma_result = self.chroma_query(question, collection_id)
fast_question = "问题: "+ question + "。根据问题,总结以下内容和来源:" + chroma_result
response = self.fastchat(model_name="Qwen1.5-14B-Chat", prompt=fast_question, template='回答限制50字.', context=None, temperature=0.8, top_p=0.8, top_k=-1, n=1, max_tokens=1024)
response = self.chat(model_name="Qwen1.5-14B-Chat", prompt=fast_question, template='', context=context, temperature=0.8, top_p=0.8, n=1, max_tokens=1024, stop=100,frequency_penalty=0.5,presence_penalty=0.8)
return response