Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gemini.parse_response_for_mode raises an error for unhandled response structure #78

Open
vkryukov opened this issue Nov 9, 2024 · 0 comments

Comments

@vkryukov
Copy link

vkryukov commented Nov 9, 2024

When asking Gemini to summarize content that it finds objectionable (e.g., this article) it raises an error because Gemini.parse_response_for_mode only handles a happy path:

** (FunctionClauseError) no function clause matching in Instructor.Adapters.Gemini.parse_response_for_mode/2    
    
    The following arguments were given to Instructor.Adapters.Gemini.parse_response_for_mode/2:
    
        # 1
        :json_schema
    
        # 2
        %{
          "candidates" => [
            %{
              "finishReason" => "SAFETY",
              "index" => 0,
              "safetyRatings" => [
                %{
                  "category" => "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                  "probability" => "NEGLIGIBLE"
                },
                %{
                  "category" => "HARM_CATEGORY_HATE_SPEECH",
                  "probability" => "NEGLIGIBLE"
                },
                %{
                  "category" => "HARM_CATEGORY_HARASSMENT",
                  "probability" => "NEGLIGIBLE"
                },
                %{
                  "category" => "HARM_CATEGORY_DANGEROUS_CONTENT",
                  "probability" => "MEDIUM"
                }
              ]
            }
          ],
          "modelVersion" => "gemini-1.5-flash-001",
          "usageMetadata" => %{"promptTokenCount" => 10842, "totalTokenCount" => 10842}
        }
    
    Attempted function clauses (showing 2 out of 2):
    
        defp parse_response_for_mode(:tools, %{"candidates" => [%{"content" => %{"parts" => [%{"functionCall" => %{"args" => args}}]}}]})
        defp parse_response_for_mode(:json_schema, %{"candidates" => [%{"content" => %{"parts" => [%{"text" => text}]}}]})
    
    (instructor 0.0.5) lib/instructor/adapters/gemini.ex:225: Instructor.Adapters.Gemini.parse_response_for_mode/2
    (instructor 0.0.5) lib/instructor/adapters/gemini.ex:214: Instructor.Adapters.Gemini.do_chat_completion/3
    (instructor 0.0.5) lib/instructor.ex:485: Instructor.do_adapter_chat_completion/2
    (instructor 0.0.5) lib/instructor.ex:432: Instructor.do_chat_completion/3
vkryukov added a commit to vkryukov/instructor_ex that referenced this issue Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant