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
45.3k stars 6.36k forks source link

Cannot use wenxinyiyan or Ernie 4 #7010

Closed zpyzl closed 1 month ago

zpyzl commented 1 month ago

Self Checks

Dify version

0.6.16

Cloud or Self Hosted

Cloud

Steps to reproduce

Select settings > Model Provider > Wenxinyiyan > setup > enter into key and secret > Save

✔️ Expected Behavior

successfully save WENXINYIYAN model API key and secret

❌ Actual Behavior

dc17749e015d1603a5f32beb249c890

zpyzl commented 1 month ago

WENXINYIYAN website has redirect to https://console.bce.baidu.com/qianfan/ais/console/onlineTest where I applied the API key

dosubot[bot] commented 1 month ago

Hey @zpyzl! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together!

To resolve the "Credentials validation failed: Invalid API key or secret key: unknown client id" error when trying to use the Wenxinyiyan model in Dify version 0.6.16 (Cloud), ensure that you are providing valid API key and secret key credentials. Here is a code snippet that shows how to validate these credentials using environment variables:

import os

import pytest

from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.wenxin.wenxin import WenxinProvider

def test_validate_provider_credentials():
    provider = WenxinProvider()

    with pytest.raises(CredentialsValidateFailedError):
        provider.validate_provider_credentials(
            credentials={
                'api_key': 'hahahaha',
                'secret_key': 'hahahaha'
            }
        )

    provider.validate_provider_credentials(
        credentials={
            'api_key': os.environ.get('WENXIN_API_KEY'),
            'secret_key': os.environ.get('WENXIN_SECRET_KEY')
        }
    )

Make sure that the environment variables WENXIN_API_KEY and WENXIN_SECRET_KEY are set with the correct values. You can set these environment variables in your operating system or in your deployment environment.

For example, in a Unix-based system, you can set these variables in the terminal:

export WENXIN_API_KEY='your_actual_api_key'
export WENXIN_SECRET_KEY='your_actual_secret_key'

In a deployment environment, you would typically set these variables in the configuration settings of your cloud service provider.

Additionally, the validate_provider_credentials method in the WenxinProvider class uses the ernie-bot model to validate the credentials. Ensure that the credentials you are using are valid for the ernie-bot model:

class WenxinProvider(ModelProvider):
    def validate_provider_credentials(self, credentials: dict) -> None:
        """
        Validate provider credentials

        if validate failed, raise exception

        :param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
        """
        try:
            model_instance = self.get_model_instance(ModelType.LLM)

            # Use `ernie-bot` model for validate,
            model_instance.validate_credentials(
                model='ernie-bot',
                credentials=credentials
            )
        except CredentialsValidateFailedError as ex:
            raise ex
        except Exception as ex:
            logger.exception(f'{self.get_provider_schema().provider} credentials validate failed')
            raise ex

By ensuring that the API key and secret key are correctly set and valid for the ernie-bot model, you should be able to resolve the credentials validation error [1][2].

To continue talking to Dosu, mention @dosu.