fix(api-brains): fixed with new types of brains (#2052)

# 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:
Stan Girard 2024-01-21 19:44:03 -08:00 committed by GitHub
parent 849e0dea9c
commit 6ce62b38e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,12 +151,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
save_answer: bool = True,
should_log_steps: Optional[bool] = True,
):
if not question.brain_id:
raise HTTPException(
status_code=400, detail="No brain id provided in the question"
)
brain = brain_service.get_brain_by_id(question.brain_id)
brain = brain_service.get_brain_by_id(self.brain_id)
if not brain:
raise HTTPException(status_code=404, detail="Brain not found")
@ -186,7 +181,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
"chat_id": chat_id,
"user_message": question.question,
"assistant": "",
"brain_id": question.brain_id,
"brain_id": self.brain_id,
"prompt_id": self.prompt_to_use_id,
}
)
@ -222,7 +217,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
async for value in self.make_completion(
messages=messages,
functions=[get_api_brain_definition_as_json_schema(brain)],
brain_id=question.brain_id,
brain_id=self.brain_id,
should_log_steps=should_log_steps,
):
streamed_chat_history.assistant = value
@ -322,12 +317,12 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
question: ChatQuestion,
save_answer: bool = True,
):
if not question.brain_id:
if not self.brain_id:
raise HTTPException(
status_code=400, detail="No brain id provided in the question"
)
brain = brain_service.get_brain_by_id(question.brain_id)
brain = brain_service.get_brain_by_id(self.brain_id)
if not brain:
raise HTTPException(status_code=404, detail="Brain not found")
@ -353,7 +348,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
response = self.make_completion_without_streaming(
messages=messages,
functions=[get_api_brain_definition_as_json_schema(brain)],
brain_id=question.brain_id,
brain_id=self.brain_id,
should_log_steps=False,
)
@ -365,7 +360,7 @@ class APIBrainQA(KnowledgeBrainQA, QAInterface):
"chat_id": chat_id,
"user_message": question.question,
"assistant": answer,
"brain_id": question.brain_id,
"brain_id": self.brain_id,
"prompt_id": self.prompt_to_use_id,
}
)