Skip to content

Commit

Permalink
fix: custom chat exception (eosphoros-ai#257)
Browse files Browse the repository at this point in the history
fix custom chat exception
raise user can understand error
  • Loading branch information
csunny committed Jun 20, 2023
2 parents 730dd20 + f9437db commit 31e7ea8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 15 additions & 7 deletions pilot/scene/chat_knowledge/custom/chat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from chromadb.errors import NoIndexException

from pilot.scene.base_chat import BaseChat, logger, headers
from pilot.scene.base import ChatScene
from pilot.common.sql_database import Database
Expand Down Expand Up @@ -50,13 +52,19 @@ def __init__(
)

def generate_input_values(self):
docs = self.knowledge_embedding_client.similar_search(
self.current_user_input, CFG.KNOWLEDGE_SEARCH_TOP_SIZE
)
context = [d.page_content for d in docs]
self.metadata = [d.metadata for d in docs]
context = context[:2000]
input_values = {"context": context, "question": self.current_user_input}
try:
docs = self.knowledge_embedding_client.similar_search(
self.current_user_input, CFG.KNOWLEDGE_SEARCH_TOP_SIZE
)
context = [d.page_content for d in docs]
self.metadata = [d.metadata for d in docs]
context = context[:2000]
input_values = {"context": context, "question": self.current_user_input}
except NoIndexException:
raise ValueError(
f"you have no {self.knowledge_name} knowledge store, please upload your knowledge"
)

return input_values

def do_with_prompt_response(self, prompt_response):
Expand Down
3 changes: 1 addition & 2 deletions pilot/server/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from pilot.configs.model_config import (
DATASETS_DIR,
KNOWLEDGE_UPLOAD_ROOT_PATH,
LLM_MODEL_CONFIG,
LOGDIR,
)

Expand Down Expand Up @@ -632,7 +631,7 @@ def knowledge_embedding_store(vs_id, files):
)
knowledge_embedding_client = KnowledgeEmbedding(
file_path=os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, vs_id, filename),
model_name=LLM_MODEL_CONFIG["text2vec"],
model_name=CFG.EMBEDDING_MODEL,
vector_store_config={
"vector_store_name": vector_store_name["vs_name"],
"vector_store_path": KNOWLEDGE_UPLOAD_ROOT_PATH,
Expand Down

0 comments on commit 31e7ea8

Please sign in to comment.