langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
50.85k stars 7.31k forks source link

Model Provider add Google Gemini failed! #4571

Closed betashepherd closed 5 months ago

betashepherd commented 5 months ago

Self Checks

Dify version

0.6.8

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Settings
  2. Model Provider
  3. Google Gemini setup
  4. Enter API key for Google Gemini and click Save.
docker-nginx-1       | 172.24.0.1 - - [22/May/2024:03:52:05 +0000] "POST /console/api/workspaces/current/model-providers/google HTTP/1.1" 400 77 "http://localhost/app/32d0e4f1-3b5b-4954-96be-b46df7db943a/configuration" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"

✔️ Expected Behavior

save Google Gemini success

❌ Actual Behavior

save Google Gemini failed

dosubot[bot] commented 5 months ago

To resolve the issue of receiving a 400 error when trying to add Google Gemini as a Model Provider in your self-hosted Dify instance (version 0.6.8, running on Docker), follow these steps:

  1. Verify API Key Configuration: Ensure that you have correctly configured the API key in the google.yaml file. The configuration should include the google_api_key as shown below:

    provider: google
    label:
     en_US: Google
    description:
     en_US: Google's Gemini model.
     zh_Hans: 谷歌提供的 Gemini 模型.
    icon_small:
     en_US: icon_s_en.svg
    icon_large:
     en_US: icon_l_en.svg
    background: "#FCFDFF"
    help:
     title:
       en_US: Get your API Key from Google
       zh_Hans: 从 Google 获取 API Key
     url:
       en_US: https://ai.google.dev/
    supported_model_types:
     - llm
    configurate_methods:
     - predefined-model
    provider_credential_schema:
     credential_form_schemas:
       - variable: google_api_key
         label:
           en_US: API Key
         type: secret-input
         required: true
         placeholder:
           zh_Hans: 在此输入您的 API Key
           en_US: Enter your API Key
  2. Check API Key Validity: Make sure that the API key you are using is valid and has the necessary permissions. If the API key is incorrect or missing, it could result in a 400 error.

  3. Enable Debug Mode for More Information: To get more detailed logs and understand why the setup is failing, you can enable debug mode in your Docker setup. Here are the steps to enable debug mode:

    • Locate the docker-compose.yaml file.

    • Modify the LOG_LEVEL, DEBUG, and FLASK_DEBUG environment variables for the api service:

      version: '3'
      services:
      api:
       image: langgenius/dify-api:0.6.8
       restart: always
       environment:
         LOG_LEVEL: DEBUG
         DEBUG: true
         FLASK_DEBUG: true
         # other environment variables...
    • Save the changes and restart the Docker services:

      docker-compose down
      docker-compose up -d
  4. Review Specific Error Messages: The specific error messages or codes that can be returned by the Google Gemini setup API endpoint in Dify include:

    • app_unavailable - "App unavailable, please check your app configurations." (Code: 400)
    • not_completion_app - "Please check if your Completion app mode matches the right API route." (Code: 400)
    • not_chat_app - "Please check if your app mode matches the right API route." (Code: 400)
    • not_workflow_app - "Please check if your Workflow app mode matches the right API route." (Code: 400)
    • provider_not_initialize - "No valid model provider credentials found. Please go to Settings -> Model Provider to complete your provider credentials." (Code: 400)
    • provider_quota_exceeded - "Your quota for Dify Hosted Model Provider has been exhausted. Please go to Settings -> Model Provider to complete your own provider credentials." (Code: 400)
    • model_currently_not_support - "Dify Hosted OpenAI trial currently not support the GPT-4 model." (Code: 400)
    • completion_request_error - "Completion request failed." (Code: 400)

    These error messages can help you pinpoint the exact issue.

By following these steps, you should be able to resolve the 400 error and successfully add Google Gemini as a Model Provider in your Dify instance. If the issue persists, please provide more details from the debug logs for further assistance.

#### Details **Sources** - [api/core/model_runtime/model_providers/google/google.yaml](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/google/google.yaml) - [api/controllers/console/error.py](https://github.com/langgenius/dify/blob/main/api/controllers/console/error.py) - [api/controllers/web/error.py](https://github.com/langgenius/dify/blob/main/api/controllers/web/error.py) - [api/controllers/console/app/error.py](https://github.com/langgenius/dify/blob/main/api/controllers/console/app/error.py) - [docker/docker-compose.yaml](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml) - [.devcontainer/post_create_command.sh](https://github.com/langgenius/dify/blob/main/.devcontainer/post_create_command.sh) - [en/getting-started/install-self-hosted/environments.md](https://github.com/langgenius/dify-docs/blob/main/en/getting-started/install-self-hosted/environments.md) - [api/core/model_runtime/model_providers/google/llm/llm.py](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/google/llm/llm.py) - [api/tests/integration_tests/model_runtime/google/test_llm.py](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/google/test_llm.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

crazywoola commented 5 months ago

You need to ensure you computer can access google gemini service as expected, typically it should behind a proxy.

betashepherd commented 5 months ago

Yes, I can use Gemini no trouble with network, I am using an openwrt wifi router. For https://gemini.google.com/app works.

betashepherd commented 5 months ago

thks.