Closed doggy8088 closed 7 months ago
Thanks!
New extension method CheckResponse
has been implemented already and is currently used in ChatSession.SendMessage[Stream]
methods. Going to extend the use to more methods soon. Need to cross-check with the Python sources for appropriate locations.
public static void CheckResponse(this GenerateContentResponse response, bool stream = false)
{
if (response.PromptFeedback.BlockReason is not BlockedReason.BlockedReasonUnspecified)
{
throw new BlockedPromptException(response.PromptFeedback);
}
if (!stream)
{
if (response.Candidates[0].FinishReason is
FinishReason.Safety or
FinishReason.Recitation or
FinishReason.Other)
{
throw new StopCandidateException(response.Candidates[0]);
}
}
}
Apart from STOP
there is also UNSPECIFIED
and MAX_TOKENS
as acceptable reason that the response has been concluded. That's according to the Python sources.
Apart from
STOP
there is alsoUNSPECIFIED
andMAX_TOKENS
as acceptable reason that the response has been concluded. That's according to the Python sources.
Can you share the Python source link? I want to check it as well. Thanks.
Hello @doggy8088
Yes, sure. See here: https://github.com/google/generative-ai-python/blob/ae8f7ccaee2629152072ff1302da912eba458daf/google/generativeai/generative_models.py#L468-L478
Hi @doggy8088
This has been improved in v1.1.2.
In the current version, the code only check for
FinishReason.Safety
.Due to docs said, I think there are others needs to be mentioned.
There are only
STOP
can be treated as "NORMAL" response.