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

InvalidApiKey. Error message: Invalid API-key provided. #448

Closed
DrYurets opened this issue Feb 7, 2025 · 1 comment
Closed

InvalidApiKey. Error message: Invalid API-key provided. #448

DrYurets opened this issue Feb 7, 2025 · 1 comment

Comments

@DrYurets
Copy link

DrYurets commented Feb 7, 2025

  1. I copy the API key in the control panel bailian.console.alibabacloud.com

Image

Image

  1. Paste it into *.py code
import urllib.parse
import json5
from qwen_agent.agents import Assistant
from qwen_agent.tools.base import BaseTool, register_tool

llm_cfg = {
    # Use the model service provided by DashScope:
    'model': 'qwen2.5-72b-instruct',
    'model_server': 'dashscope',
    'api_key': "sk-aec*******************7b1f01",

    # (Optional) LLM hyperparameters for generation:
    'generate_cfg': {
        'top_p': 0.8
    }
}

# Step 3: Create an agent. Here we use the `Assistant` agent as an example, which is capable of using tools and reading files.
...
  1. Get an error message
λ python qwen.py
user query: test
Traceback (most recent call last):
  File "C:\qwen\qwen.py", line 43, in <module>
    for response in bot.run(messages=messages):
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\agent.py", line 94, in run
    for rsp in self._run(messages=new_messages, **kwargs):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\agents\assistant.py", line 99, in _run
    new_messages = self._prepend_knowledge_prompt(messages=messages, lang=lang, knowledge=knowledge, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\agents\assistant.py", line 110, in _prepend_knowledge_prompt
    *_, last = self.mem.run(messages=messages, lang=lang, **kwargs)
    ^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\agent.py", line 94, in run
    for rsp in self._run(messages=new_messages, **kwargs):
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\memory\memory.py", line 97, in _run
    for last in response:
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\agent.py", line 94, in run
    for rsp in self._run(messages=new_messages, **kwargs):
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 347, in _convert_messages_iterator_to_target_type
    for messages in messages_iter:
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 235, in _format_and_cache
    for o in output:
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 331, in _postprocess_messages_iterator
    for pre_msg in messages:
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 503, in retry_model_service_iterator
    num_retries, delay = _raise_or_delay(e, num_retries, delay, max_retries)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 517, in _raise_or_delay
    raise e
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\base.py", line 498, in retry_model_service_iterator
    for rsp in it_fn():
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\qwen_agent\llm\qwen_dashscope.py", line 111, in _full_stream_output
    raise ModelServiceError(code=chunk.code, message=chunk.message)
qwen_agent.llm.base.ModelServiceError:
Error code: InvalidApiKey. Error message: Invalid API-key provided.

What did i do wrong?

@DrYurets DrYurets closed this as completed Feb 7, 2025
@DrYurets
Copy link
Author

DrYurets commented Feb 7, 2025

instead of the "dashscope" you had to write the server URL

    # Use the model service provided by DashScope:
    'model': 'qwen2.5-72b-instruct',
    'model_server': 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
    'api_key': "sk-aec******************7b1f01",

    # (Optional) LLM hyperparameters for generation:
    'generate_cfg': {
        'top_p': 0.8
    }
}

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