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

[Issue]: TypeError: Completions.create() got an unexpected keyword argument 'request_timeout' #1156

Closed
ahmetkarslix opened this issue Jan 6, 2024 · 14 comments

Comments

@ahmetkarslix
Copy link

Describe the issue

Hello, I am trying to make artificial intelligence that develops a 2d game with autogen. I am trying to do it with this linked video "https://youtu.be/Bq-0ClZttc8?si=SREV4voQgOOu6NCd&t=143" that I found on Youtube, I did all the steps, I installed autogen, I installed basic.py as in the video, I performed the chart operations, but when I come to the game section, I get an error even though I get the code exactly.

The error I get is :
Traceback (most recent call last):
File "/Users/ahmetkarsli/Desktop/Autogen Proje/code_agent.py", line 31, in
user_proxy.initiate_chat(
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 562, in initiate_chat
self.send(self.generate_init_message(**context), recipient, silent=silent)
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 360, in send
recipient.receive(message, self, request_reply, silent)
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 493, in receive
reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 968, in generate_reply
final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 353, in run_chat
speaker = groupchat.select_speaker(speaker, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 197, in select_speaker
final, name = selector.generate_oai_reply(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 637, in generate_oai_reply
response = client.create(
^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/oai/client.py", line 261, in create
response = self._completions_create(client, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/oai/client.py", line 359, in _completions_create
response = completions.create(**params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/openai/_utils/_utils.py", line 272, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'request_timeout'

I don't understand where I went wrong, please help me.

Steps to reproduce

No response

Screenshots and logs

resim_2024-01-06_161906839

resim_2024-01-06_161939061

resim_2024-01-06_162003151

Additional Information

Python version: 3.11.5
Operating System: MacOS Sonoma 14.2.1

@rickyloynd-microsoft
Copy link
Contributor

rickyloynd-microsoft commented Jan 6, 2024

Openai has dropped the completions API (including request_timeout). Do you actually need it? See our migration guide.

@ahmetkarslix
Copy link
Author

hello my current versions:
autogen 0.2.3
python 3.11.5

and this is the code I am using now:
import autogen
from autogen import config_list_from_json

Get api key

config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
llm_config = {"config_list": config_list, "seed": 42, "request_timeout": 120}

Create user proxy agent, coder, product manager

user_proxy = autogen.UserProxyAgent(
name="User_proxy",
system_message="A human admin who will give the idea and run the code provided by Coder.",
code_execution_config={"last_n_messages": 2, "work_dir": "groupchat"},
human_input_mode="ALWAYS",
)
coder = autogen.AssistantAgent(
name="Coder",
llm_config=llm_config,
)
pm = autogen.AssistantAgent(
name="product_manager",
system_message="You will help break down the initial idea into a well scoped requirement for the coder; Do not involve in future conversations or error fixing",
llm_config=llm_config,
)

Create groupchat

groupchat = autogen.GroupChat(
agents=[user_proxy, coder, pm], messages=[])
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)

Start the conversation

user_proxy.initiate_chat(
manager, message="Build a classic & basic pong game with 2 players in python")

Can you help me what I need to change in my code according to the new migration?
@rickyloynd-microsoft

@rickyloynd-microsoft
Copy link
Contributor

What is the version of your openai package?

@ahmetkarslix
Copy link
Author

@rickyloynd-microsoft
openai version 1.6.1

multitasking 0.0.11
numpy 1.26.3
openai 1.6.1
packaging 23.2
pandas 2.1.4
peewee 3.17.0
pillow 10.2.0
pip 23.2.1
pyautogen 0.2.3
pydantic 2.5.3
pydantic_core 2.14.6
pyparsing 3.1.1
python-dateutil 2.8.2
python-dotenv 1.0.0

@rickyloynd-microsoft
Copy link
Contributor

Interesting. Let's try something even simpler. Can you run this sample script?

@ahmetkarslix
Copy link
Author

@rickyloynd-microsoft
It works without any problems
resim_2024-01-06_194826852

@rickyloynd-microsoft
Copy link
Contributor

That's a good sign. What about twoagent.py?

@ahmetkarslix
Copy link
Author

@rickyloynd-microsoft
first of all when I run the code;
Before running this script, you need to make sure that the necessary Python libraries (pandas_datareader, matplotlib, datetime) are installed. If they are not, they can be installed via pip:

pip install pandas_datareader matplotlib

After that, you can execute the Python script with:

python stock_price_plot.py

I got the message after exiting,
```sh
pip install pandas_datareader matplotlib

I ran the partition

then I ran it again but I got this error;
Traceback (most recent call last):
File "stock_price_plot.py", line 11, in
nvda = pdr.get_data_yahoo('NVDA', start=start_date, end=end_date)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/pandas_datareader/data.py", line 80, in get_data_yahoo
return YahooDailyReader(*args, **kwargs).read()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/pandas_datareader/base.py", line 253, in read
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/pandas_datareader/yahoo/daily.py", line 153, in _read_one_data
data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

here are the screenshots:

resim_2024-01-06_200852034

resim_2024-01-06_200914194

then ignored and pressed enter again and it worked?

resim_2024-01-06_200943548

@rickyloynd-microsoft
Copy link
Contributor

What do you mean by "I ran the partition"?

I assume that you didn't pip install the requested packages yourself. The user proxy should do that if you hit enter.

Anyway, the main difference from twoagent.py is that your code uses GroupChatManager. @afourney probably knows why the completions api is being invoked.

@ahmetkarslix
Copy link
Author

When I say that I ran that partition, I mean that I ran it myself with pip and the necessary ;

pip install pandas_datareader matplotlib

I manually ran this code in the terminal and installed it and as far as I understand the code is now working as in the last screenshot I posted.

@rickyloynd-microsoft
Copy link
Contributor

And does your original code still hit the error about request_timeout?

@ahmetkarslix
Copy link
Author

@rickyloynd-microsoft

Yes, I still get this error:
Traceback (most recent call last):
File "/Users/ahmetkarsli/Desktop/Autogen Proje/code_agent.py", line 33, in
user_proxy.initiate_chat(
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 562, in initiate_chat
self.send(self.generate_init_message(**context), recipient, silent=silent)
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 360, in send
recipient.receive(message, self, request_reply, silent)
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 493, in receive
reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 968, in generate_reply
final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 353, in run_chat
speaker = groupchat.select_speaker(speaker, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 197, in select_speaker
final, name = selector.generate_oai_reply(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 637, in generate_oai_reply
response = client.create(
^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/oai/client.py", line 261, in create
response = self._completions_create(client, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/autogen/oai/client.py", line 359, in _completions_create
response = completions.create(**params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahmetkarsli/Desktop/Autogen Proje/pyautogen/lib/python3.11/site-packages/openai/_utils/_utils.py", line 272, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'request_timeout'

@rickyloynd-microsoft
Copy link
Contributor

I watched the video from your link, and saw the earlier lines of code that you didn't include here. Specifically, this line introduces request_timeout:

llm_config = {"config_list": config_list, "seed": 42, "request_timeout": 120}

As explained in our migration guide, request_timeout needs to be replaced with timeout instead. See if that helps.

@ahmetkarslix
Copy link
Author

Thank you very much, I just need to change one line of code, thank you for helping me, it works!

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

2 participants