mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
refactor: processing of blackbox chroma query and chat
This commit is contained in:
@ -20,7 +20,7 @@ class ChromaQuery(Blackbox):
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
# config = read_yaml(args[0])
|
||||
# load chromadb and embedding model
|
||||
self.embedding_model_1 = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="/model/Weight/BAAI/bge-small-en-v1.5", device = "cuda")
|
||||
self.embedding_model_1 = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="/model/Weight/BAAI/bge-large-zh-v1.5", device = "cuda")
|
||||
# self.embedding_model_2 = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="/model/Weight/BAAI/bge-small-en-v1.5", device = "cuda")
|
||||
self.client_1 = chromadb.HttpClient(host='10.6.82.192', port=8000)
|
||||
# self.client_2 = chromadb.HttpClient(host='10.6.82.192', port=8000)
|
||||
@ -51,7 +51,7 @@ class ChromaQuery(Blackbox):
|
||||
return JSONResponse(content={"error": "question is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if chroma_embedding_model is None or chroma_embedding_model.isspace() or chroma_embedding_model == "":
|
||||
chroma_embedding_model = "bge-small-en-v1.5"
|
||||
chroma_embedding_model = "bge-large-zh-v1.5"
|
||||
|
||||
if chroma_host is None or chroma_host.isspace() or chroma_host == "":
|
||||
chroma_host = "10.6.82.192"
|
||||
@ -60,17 +60,22 @@ class ChromaQuery(Blackbox):
|
||||
chroma_port = "8000"
|
||||
|
||||
if chroma_collection_id is None or chroma_collection_id.isspace() or chroma_collection_id == "":
|
||||
chroma_collection_id = DEFAULT_COLLECTION_ID
|
||||
chroma_collection_id = "g2e"
|
||||
|
||||
if chroma_n_results is None or chroma_n_results == "":
|
||||
chroma_n_results = 3
|
||||
|
||||
# load client
|
||||
# load client and embedding model from init
|
||||
if re.search(r"10.6.82.192", chroma_host) and re.search(r"8000", chroma_port):
|
||||
client = self.client_1
|
||||
else:
|
||||
client = chromadb.HttpClient(host=chroma_host, port=chroma_port)
|
||||
|
||||
if re.search(r"bge-small-en-v1.5", chroma_embedding_model):
|
||||
if re.search(r"bge-large-zh-v1.5", chroma_embedding_model):
|
||||
embedding_model = self.embedding_model_1
|
||||
else:
|
||||
chroma_embedding_model = "/model/Weight/BAAI/" + chroma_embedding_model
|
||||
embedding_model = embedding_functions.SentenceTransformerEmbeddingFunction(model_name=chroma_embedding_model, device = "cuda")
|
||||
|
||||
# load collection
|
||||
collection = client.get_collection(chroma_collection_id, embedding_function=embedding_model)
|
||||
@ -81,7 +86,9 @@ class ChromaQuery(Blackbox):
|
||||
n_results=3,
|
||||
)
|
||||
|
||||
response = str(results["documents"] + results["metadatas"])
|
||||
# response = str(results["documents"] + results["metadatas"])
|
||||
response = str(results["documents"])
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user