mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Update handling of gemini response with new API changes. Per documentation:
finish_reason (google.ai.generativelanguage_v1beta.types.Candidate.FinishReason): Optional. Output only. The reason why the model stopped generating tokens. If empty, the model has not stopped generating the tokens.
This commit is contained in:
parent
27835628e6
commit
07ab8ab931
1 changed files with 4 additions and 0 deletions
|
@ -148,6 +148,10 @@ def handle_gemini_response(candidates, prompt_feedback=None):
|
|||
elif candidates[0].finish_reason == FinishReason.SAFETY:
|
||||
message = generate_safety_response(candidates[0].safety_ratings)
|
||||
stopped = True
|
||||
# Check if finish reason is empty, therefore generation is in progress
|
||||
elif not candidates[0].finish_reason:
|
||||
message = None
|
||||
stopped = False
|
||||
# Check if the response was stopped due to reaching maximum token limit or other reasons
|
||||
elif candidates[0].finish_reason != FinishReason.STOP:
|
||||
message = f"\nI can't talk further about that because of **{candidates[0].finish_reason.name} issue.**"
|
||||
|
|
Loading…
Add table
Reference in a new issue