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

IndexError: list index out of range when using Open Router #4815

Open
yingdaomayi-qwe opened this issue Dec 26, 2024 · 1 comment
Open

IndexError: list index out of range when using Open Router #4815

yingdaomayi-qwe opened this issue Dec 26, 2024 · 1 comment
Labels
0.2 Issues which are related to the pre 0.4 codebase needs-triage

Comments

@yingdaomayi-qwe
Copy link

What happened?

When I try to run the code below:

from autogen import AssistantAgent, UserProxyAgent
import os
from Openrouter_class import Openrouter

llm_config={
"config_list": [{"model": "openai/gpt-4o-2024-11-20","base_url": "https://openrouter.ai/api/v1/chat/completions","api_key": "my_key","model_client_cls": "Openrouter"}]}
assistant = AssistantAgent("assistant", llm_config=llm_config)
assistant.register_model_client(model_client_cls=Openrouter)
user_proxy = UserProxyAgent("user_proxy", code_execution_config=False, human_input_mode="TERMINATE")

Start the chat

user_proxy.initiate_chat(
assistant,
message="Tell me a joke about NVDA and TESLA stock prices.",
)

I got the error below:

Traceback (most recent call last):
File "/home/dell/PycharmProjects/pythonProject/quickstart.py", line 13, in
user_proxy.initiate_chat(
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 1153, in initiate_chat
self.send(msg2send, recipient, silent=silent)
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 788, in send
recipient.receive(message, self, request_reply, silent)
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 953, in receive
reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 2113, in generate_reply
final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 1475, in generate_oai_reply
extracted_response = self._generate_oai_reply_from_client(
File "/home/dell/Workarea/Anaconda3/envs/autogen/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 1500, in _generate_oai_reply_from_client
extracted_response = llm_client.extract_text_or_completion_object(response)[0]
IndexError: list index out of range

It is strange because when I use the code below, there is no error:

llm_config = {"config_list": config_list_custom , "cache_seed": 42}

Create ConversableAgents

agent1 = ConversableAgent(name="Matt",system_message="You are Matt.", llm_config=llm_config)
agent2 = ConversableAgent(name="Alice",system_message="You are Alice.",llm_config=llm_config)

FIX: Main thing is registering these clients!

agent1.register_model_client(Openrouter)
agent2.register_model_client(Openrouter)

Start conversation

chat_result = agent1.initiate_chat(
agent2, message="Hi Alice!", max_turns=2)

What did you expect to happen?

Can you tell me why the error happened?

How can we reproduce it (as minimally and precisely as possible)?

The code is listed above.

AutoGen version

0.2.40

Which package was this bug in

AgentChat

Model used

openrouter as a router for gpt-4o

Python version

No response

Operating system

No response

Any additional info you think would be helpful for fixing this bug

No response

@ekzhu ekzhu added the 0.2 Issues which are related to the pre 0.4 codebase label Dec 26, 2024
@ekzhu ekzhu changed the title IndexError: list index out of range IndexError: list index out of range when using Open Router Dec 26, 2024
@ekzhu
Copy link
Collaborator

ekzhu commented Dec 26, 2024

I am not familiar with Open Router. Can you confirm this base_url is correct or it needs the /chat/completions part.

"base_url": "https://openrouter.ai/api/v1/chat/completions"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2 Issues which are related to the pre 0.4 codebase needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants