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

MoonshotChat moonshot_api_key is invaild for api key #21237

Closed
5 tasks done
tears743 opened this issue May 3, 2024 · 1 comment · Fixed by #21361
Closed
5 tasks done

MoonshotChat moonshot_api_key is invaild for api key #21237

tears743 opened this issue May 3, 2024 · 1 comment · Fixed by #21361
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations

Comments

@tears743
Copy link

tears743 commented May 3, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

MoonshotChat(api_key=model.api_key,streaming=True,model=model.name)

Error Message and Stack Trace (if applicable)

openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Invalid Authentication', 'type': 'invalid_authentication_error'}}

Description

class MoonshotCommon(BaseModel):

    _client: _MoonshotClient

    base_url: str = MOONSHOT_SERVICE_URL_BASE

    moonshot_api_key: Optional[SecretStr] = Field(default=None, alias="api_key")

    model_name: str = Field(default="moonshot-v1-8k", alias="model")

    max_tokens = 1024

    temperature = 0.3

The moonshot_api_key type is SecretStr ,when MoonshotChat class build openai client params ,it still use secret string ,

client_params = {
            "api_key": values["moonshot_api_key"],

            "base_url": values["base_url"]

            if "base_url" in values

            else MOONSHOT_SERVICE_URL_BASE,

        }

cause the request error:
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Invalid Authentication', 'type': 'invalid_authentication_error'}}

client_params = {
            "api_key": values["moonshot_api_key"]._secret_value, # this will be work

            "base_url": values["base_url"]

            if "base_url" in values

            else MOONSHOT_SERVICE_URL_BASE,

        }

System Info

openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Invalid Authentication', 'type': 'invalid_authentication_error'}}

@dosubot dosubot bot added 🔌: openai Primarily related to OpenAI integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels May 3, 2024
@liugddx
Copy link
Contributor

liugddx commented May 6, 2024

Let me see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations
Projects
None yet
2 participants