mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-14 17:03:29 +03:00
fix: 🐛 related (#2090)
now updates # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
4aebcc54aa
commit
c5546fd374
@ -331,7 +331,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
|
||||
chat_service.update_message_by_id(
|
||||
message_id=str(streamed_chat_history.message_id),
|
||||
user_message=question.question,
|
||||
assistant="".join(response_tokens),
|
||||
assistant="".join(str(token) for token in response_tokens),
|
||||
metadata=self.metadata,
|
||||
)
|
||||
|
||||
|
@ -30,7 +30,7 @@ class CreateBrainProperties(BaseModel, extra=Extra.forbid):
|
||||
status: Optional[str] = "private"
|
||||
model: Optional[str]
|
||||
temperature: Optional[float] = 0.0
|
||||
max_tokens: Optional[int] = 256
|
||||
max_tokens: Optional[int] = 2000
|
||||
prompt_id: Optional[UUID] = None
|
||||
brain_type: Optional[BrainType] = BrainType.DOC
|
||||
brain_definition: Optional[CreateApiBrainDefinition]
|
||||
|
@ -53,42 +53,47 @@ class BrainfulChat(ChatInterface):
|
||||
user_id,
|
||||
chat_question,
|
||||
):
|
||||
brain_id_to_use = brain_id
|
||||
metadata = {}
|
||||
if not brain_id:
|
||||
brain_settings = BrainSettings()
|
||||
supabase_client = get_supabase_client()
|
||||
embeddings = None
|
||||
if brain_settings.ollama_api_base_url:
|
||||
embeddings = OllamaEmbeddings(
|
||||
base_url=brain_settings.ollama_api_base_url
|
||||
) # pyright: ignore reportPrivateUsage=none
|
||||
else:
|
||||
embeddings = OpenAIEmbeddings()
|
||||
vector_store = CustomSupabaseVectorStore(
|
||||
supabase_client, embeddings, table_name="vectors", user_id=user_id
|
||||
)
|
||||
# Get the first question from the chat_question
|
||||
brain_settings = BrainSettings()
|
||||
supabase_client = get_supabase_client()
|
||||
embeddings = None
|
||||
if brain_settings.ollama_api_base_url:
|
||||
embeddings = OllamaEmbeddings(
|
||||
base_url=brain_settings.ollama_api_base_url
|
||||
) # pyright: ignore reportPrivateUsage=none
|
||||
else:
|
||||
embeddings = OpenAIEmbeddings()
|
||||
vector_store = CustomSupabaseVectorStore(
|
||||
supabase_client, embeddings, table_name="vectors", user_id=user_id
|
||||
)
|
||||
|
||||
question = chat_question.question
|
||||
history = chat_service.get_chat_history(chat_id)
|
||||
if history:
|
||||
question = history[0].user_message
|
||||
brain_id_to_use = history[0].brain_id
|
||||
# Init
|
||||
|
||||
list_brains = []
|
||||
if history:
|
||||
list_brains = vector_store.find_brain_closest_query(user_id, question)
|
||||
metadata["close_brains"] = list_brains
|
||||
else:
|
||||
list_brains = vector_store.find_brain_closest_query(user_id, question)
|
||||
if list_brains:
|
||||
brain_id_to_use = list_brains[0]["id"]
|
||||
else:
|
||||
brain_id_to_use = None
|
||||
# Add to metadata close_brains and close_brains_similarity
|
||||
metadata["close_brains"] = list_brains
|
||||
brain_id_to_use = brain_id
|
||||
|
||||
# Get the first question from the chat_question
|
||||
|
||||
question = chat_question.question
|
||||
history = chat_service.get_chat_history(chat_id)
|
||||
|
||||
list_brains = [] # To return
|
||||
|
||||
if history and not brain_id_to_use:
|
||||
# Replace the question with the first question from the history
|
||||
question = history[0].user_message
|
||||
|
||||
if history and not brain_id:
|
||||
brain_id_to_use = history[0].brain_id
|
||||
|
||||
# Calculate the closest brains to the question
|
||||
list_brains = vector_store.find_brain_closest_query(user_id, question)
|
||||
|
||||
metadata["close_brains"] = list_brains
|
||||
|
||||
if list_brains and not brain_id_to_use:
|
||||
brain_id_to_use = list_brains[0]["id"]
|
||||
|
||||
# GENERIC
|
||||
follow_up_questions = chat_service.get_follow_up_question(chat_id)
|
||||
metadata["follow_up_questions"] = follow_up_questions
|
||||
metadata["model"] = model
|
||||
|
@ -99,7 +99,7 @@ class ChatService:
|
||||
assistant=message.assistant,
|
||||
message_time=message.message_time,
|
||||
brain_name=brain.name if brain else None,
|
||||
brain_id=brain.id if brain else None,
|
||||
brain_id=str(brain.id) if brain else None,
|
||||
prompt_title=prompt.title if prompt else None,
|
||||
metadata=message.metadata,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user