mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 17:13:25 +00:00
fix: chroma setting url and key
This commit is contained in:
@ -6,7 +6,10 @@ from .blackbox import Blackbox
|
||||
|
||||
from .chat import Chat
|
||||
from .chroma_query import ChromaQuery
|
||||
from ..log.logging_time import logging_time
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger
|
||||
DEFAULT_COLLECTION_ID = "123"
|
||||
|
||||
from injector import singleton,inject
|
||||
@ -24,19 +27,68 @@ class ChromaChat(Blackbox):
|
||||
def valid(self, *args, **kwargs) -> bool:
|
||||
data = args[0]
|
||||
return isinstance(data, list)
|
||||
|
||||
@logging_time(logger=logger)
|
||||
def processing(self, question: str, context: list, settings: dict) -> str:
|
||||
|
||||
if settings is None:
|
||||
settings = {}
|
||||
|
||||
# # chat setting
|
||||
user_model_name = settings.get("model_name")
|
||||
user_context = context
|
||||
user_question = question
|
||||
user_template = settings.get("template")
|
||||
user_temperature = settings.get("temperature")
|
||||
user_top_p = settings.get("top_p")
|
||||
user_n = settings.get("n")
|
||||
user_max_tokens = settings.get("max_tokens")
|
||||
user_stop = settings.get("stop")
|
||||
user_frequency_penalty = settings.get("frequency_penalty")
|
||||
user_presence_penalty = settings.get("presence_penalty")
|
||||
|
||||
# # chroma_query settings
|
||||
chroma_embedding_model = settings.get("chroma_embedding_model")
|
||||
chroma_host = settings.get("chroma_host")
|
||||
chroma_port = settings.get("chroma_port")
|
||||
chroma_collection_id = settings.get("chroma_collection_id")
|
||||
chroma_n_results = settings.get("chroma_n_results")
|
||||
|
||||
def processing(self, question, context: list) -> str:
|
||||
if context == None:
|
||||
context = []
|
||||
|
||||
# load or create collection
|
||||
collection_id = DEFAULT_COLLECTION_ID
|
||||
if user_question is None:
|
||||
return JSONResponse(content={"error": "question is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# query it
|
||||
chroma_result = self.chroma_query(question, collection_id)
|
||||
chroma_settings_json={
|
||||
"chroma_embedding_model": chroma_embedding_model,
|
||||
"chroma_host": chroma_host,
|
||||
"chroma_port": chroma_port,
|
||||
"chroma_collection_id": chroma_collection_id,
|
||||
"chroma_n_results": chroma_n_results
|
||||
}
|
||||
|
||||
fast_question = "问题: "+ question + "。根据问题,总结以下内容和来源:" + chroma_result
|
||||
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)
|
||||
# chroma answer
|
||||
chroma_result = self.chroma_query(user_question, chroma_settings_json)
|
||||
|
||||
# chat prompt
|
||||
fast_question = f"问题: {user_question}。根据问题,总结以下内容和来源:{chroma_result}"
|
||||
|
||||
chat_settings_json = {
|
||||
"model_name": user_model_name,
|
||||
"context": user_context,
|
||||
"template": user_template,
|
||||
"temperature": user_temperature,
|
||||
"top_p": user_top_p,
|
||||
"n": user_n,
|
||||
"max_tokens": user_max_tokens,
|
||||
"stop": user_stop,
|
||||
"frequency_penalty": user_frequency_penalty,
|
||||
"presence_penalty": user_presence_penalty
|
||||
}
|
||||
|
||||
# chat answer
|
||||
response = self.chat(fast_question, chat_settings_json)
|
||||
|
||||
return response
|
||||
|
||||
@ -49,10 +101,8 @@ class ChromaChat(Blackbox):
|
||||
|
||||
user_question = data.get("question")
|
||||
user_context = data.get("context")
|
||||
|
||||
if user_question is None:
|
||||
return JSONResponse(content={"error": "question is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
setting: dict = data.get("settings")
|
||||
|
||||
return JSONResponse(
|
||||
content={"response": self.processing(user_question, user_context)},
|
||||
content={"response": self.processing(user_question, user_context, setting)},
|
||||
status_code=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user