Skip to content

Instantly share code, notes, and snippets.

@mberman84
Last active May 14, 2024 14:50
Show Gist options
  • Save mberman84/584b470962c15930340ff49ae4e28a02 to your computer and use it in GitHub Desktop.
Save mberman84/584b470962c15930340ff49ae4e28a02 to your computer and use it in GitHub Desktop.
app.py
import autogen
config_list = [
{
'model': 'gpt-4',
'api_key': 'API_KEY'
}
]
llm_config={
"request_timeout": 600,
"seed": 42,
"config_list": config_list,
"temperature": 0
}
assistant = autogen.AssistantAgent(
name="CTO",
llm_config=llm_config,
system_message="Chief technical officer of a tech company"
)
user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={"work_dir": "web"},
llm_config=llm_config,
system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)
task = """
Write python code to output numbers 1 to 100, and then store the code in a file
"""
user_proxy.initiate_chat(
assistant,
message=task
)
task2 = """
Change the code in the file you just created to instead output numbers 1 to 200
"""
user_proxy.initiate_chat(
assistant,
message=task2
)
@truepipeAI
Copy link

truepipeAI commented Oct 11, 2023

Similar error - even after renaming the folder to 'agen' instead of 'autogen'

Traceback (most recent call last):
File "/Users/GuestUser/GitHub/agen/app.py", line 1, in
import autogen
ModuleNotFoundError: No module named 'autogen'

EDIT: Even though I was on version 3.11.4 I had to switch it manually clicking on the version number in the bottom of VS Code as it was on 3.9

@TonyHalik404
Copy link

Traceback (most recent call last):
File "C:\Autog\app.py", line 1, in
import autogen
ModuleNotFoundError: No module named 'autogen'

@truepipeAI
Copy link

Traceback (most recent call last): File "C:\Autog\app.py", line 1, in import autogen ModuleNotFoundError: No module named 'autogen'

Take a look at the bottom right of VS Code. If it doesn't say Python 3.11.4 then click on it, and you'll see in the top middle it gives you an option to choose Python 3.11.4 - switch to that, and then run it.

@oneCodeScholar
Copy link

Thanks for this tips, I'll check them out as I'd like to complete the tutorial the way shown. What I did was, load autogen from github and add another file in the test folder and add this code there and it's working. The issue now is the token size and amount in ChatGPT. I have the plus account and have money there but the token run out really fast and I have to wait to get new ones and the token size limit for input is low. autogen is requiring lots of interaction and large input fields. We need to get FastChat working as a local LLM API or get access to the LLM APIs in Pinokio so we do not run into token limits. I'm getting stalled on the FastChat build at launch the RESTful API server: https://microsoft.github.io/autogen/blog/2023/07/14/Local-LLMs/ Can you get FastChat to build or do you have experience with Pinokio? Thanks

@TonyHalik404
Copy link

truepipeAI Thank you, now im stuck in same possition as you:
PS C:\Users\Admin> & C:/Users/Admin/anaconda3/envs/autogen/python.exe c:/Autog/app.py
Traceback (most recent call last):
File "c:\Autog\app.py", line 17, in
assistant = autogen.AssistantAgent(
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'autogen' has no attribute 'AssistantAgent'

@drgumshoe
Copy link

I had "autogen" in my file path. I changed the folder's name and re-ran it successfully.

@TonyHalik404
Copy link

Changed path and still the same :/
PS C:\Users\alek> & C:/Users/alek/AppData/Local/Programs/Python/Python310/python.exe c:/Autog/main.py
Traceback (most recent call last):
File "c:\Autog\main.py", line 1, in
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
File "C:\Users\alek\AppData\Local\Programs\Python\Python311\Lib\site-packages\autogen\autogen.py", line 17, in
from .defaultlog import log
ImportError: attempted relative import with no known parent package

@goforit5
Copy link

Use pip install pyautogen instead of pip install autogen

That fixed the "module 'autogen' has no attribute 'AssistantAgent'" for me and then I was able to run the file properly.

@PeterToo1
Copy link

Thank you that worked for me.

@oneCodeScholar
Copy link

I found if you set it to human_input_mode="ALWAYS" the output tends to be more useable. This issue I'm having is now is, let's say it were to write code, I can not then tell it to output a file. I ask the CTO to output a file and they say they do so but the file is not there. Sometimes it seems like its testing the code and other times it seems like it didn't. I thought the CTO was suppose to check the code. It would be great if it always tested the code and the CTO would respond to commands such as write code to file or run and test code. Any thoughts?

@maillme
Copy link

maillme commented Oct 15, 2023

I am getting an API key error - but my API key is fine..... Anyone else?

File "/Users/neil/anaconda3/envs/autogen/lib/python3.11/site-packages/openai/util.py", line 186, in default_api_key raise openai.error.AuthenticationError( openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details.

UPDATE:

I tested it within the same folder, using this code, and it worked, so the API is working:

import openai

# Set your OpenAI API key here
openai.api_key = "API"

# Test the API key by making a simple request
try:
    response = openai.Completion.create(
        engine="davinci",  # You can use any engine you have access to
        prompt="Hello, OpenAI!",
        max_tokens=5
    )

    print("API Key is valid. Response:")
    print(response.choices[0].text)
except Exception as e:
    print(f"API Key test failed. Error: {str(e)}")

Result

(base) neil@Neils-iMac Autogen % /Users/neil/anaconda3/envs/autogen/bin/python "/Volumes/GoogleDrive/Shared drives/Growth/AI/Autogen/testAPI.py"
API Key is valid. Response:
 "Hi OpenAI!

thanks.

@oneCodeScholar
Copy link

It's still not working for me. Have have changed the folder name, I have conda and vscode both on 3.11.4, I have done a: pip install pyautogen and pip install autogen. Still getting the following error:

assistant = autogen.AssistantAgent(
            ^^^^^^^^^^^^^^^^^^^^^^

AttributeError: module 'autogen' has no attribute 'AssistantAgent'

Please advise.

@btquanto
Copy link

btquanto commented Oct 18, 2023

It's still not working for me. Have have changed the folder name, I have conda and vscode both on 3.11.4, I have done a: pip install pyautogen and pip install autogen. Still getting the following error:

assistant = autogen.AssistantAgent(
            ^^^^^^^^^^^^^^^^^^^^^^

AttributeError: module 'autogen' has no attribute 'AssistantAgent'

Please advise.

autogen is the incorrect pip package. Only install pyautogen. Don't install both of them.

First, remove both autogen and pyautogen package:

pip uninstall autogen pyautogen

Then reinstall pyautogen package:

pip install pyautogen

@adnansalamat
Copy link

is there any way to terminate the task once completed it is is running indefinitely looping

@adnansalamat
Copy link

I think i solved the problem of it endless looping but the file is not saving. In my case import docker and adding user_docker paramters did the trick

import sys
#import pytest
import docker
import autogen

config_list = [
{
'api_type': 'open_ai',
'api_base': 'http://localhost:1234/v1',
'api_key': 'NULL'
}
]

llm_config={
"request_timeout": 600,
"seed": 42,
"config_list": config_list,
"temperature": 0
}

assistant = autogen.AssistantAgent(
name="CTO",
llm_config=llm_config,
system_message="Chief technical officer of a tech company"
)

user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={
"work_dir": "web",
"use_docker": "python:3.11.6",
"timeout": 60,
},
llm_config=llm_config,
system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)

task = """
Write python code to output numbers from 1 to 100, and then store the code in a file
"""
#task = """
#What Artifical Inteligence will eventually does
#"""

user_proxy.initiate_chat(
assistant,
message=task
)
print(user_proxy.get_last_message())
#task2 = """
#Change the code in the file you just created to instead output numbers 1 to 200
#"""

#user_proxy.initiate_chat(

assistant,

message=task2

#)

@strider1000
Copy link

mine is saying 'As an AI language model, I don't have the capability to browse the internet or access real-time information.'

can anyone help here?

@a-ml
Copy link

a-ml commented Oct 18, 2023

I keep having endless loop.

@JaPossert
Copy link

I keep having endless loop.
Editing the System message of the user proxy might help like this one:
Untitled

@giammy677dev
Copy link

Me too keep having endless loop :( Anyone solved?

@lytworkshift
Copy link

I'm getting error, please advise: Traceback (most recent call last): File "c:\Users\GuestUser\vsCode\autogen\app.py", line 17, in assistant = autogen.AssistantAgent( ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'autogen' has no attribute 'AssistantAgent'

try
python -m pip install autogen

@fenixlam
Copy link

fenixlam commented Nov 2, 2023

assistant = autogen.AssistantAgent(
AttributeError: partially initialized module 'autogen' has no attribute 'AssistantAgent' (most likely due to a circular import)

My python environments has only pyautogen==0.1.14, no autogen But this error still appear.
The funny thing is, I have a ubuntu and a win11, this error does not appear in win11, only appear in ubuntu.

@jez120
Copy link

jez120 commented Nov 2, 2023

According to BARD AI to fix the loop you need to: "Another way to fix the problem is to change the code so that the user proxy will only automatically reply to messages that are not completed. You can do this by changing the max_consecutive_auto_reply setting to 0. This will ensure that the user proxy will only automatically reply to the first message in a conversation." - tested stopped looping

@tzack1
Copy link

tzack1 commented Nov 20, 2023

I am using assistants to calculate today's date based on your video. But it gives out this response : As an AI, I don't have real-time capabilities or access to current data, including today's date or the latest stock market figures. To find out today's date, please check your computer or smartphone's clock.

image
image

@xeniode
Copy link

xeniode commented Nov 26, 2023

Anyone trying this on Ubuntu and getting various errors. I have it working. First make sure to use "use_docker" as adnansalamat mentioned. Make sure you have the python:3 image pulled from Docker registry. Also, if you are using Docker Desktop, use the locate command to search for your socket. If it is outside of /var/run you need to make a link from the location to /var/run/docker.sock

@jneb802
Copy link

jneb802 commented Nov 28, 2023

I'm getting this error: TypeError: Completions.create() got an unexpected keyword argument 'request_timeout'

Anyone experience this?

Using pyautogen on python 3.11.6 in a virtual environment.

@jneb802
Copy link

jneb802 commented Nov 28, 2023

I'm getting this error: TypeError: Completions.create() got an unexpected keyword argument 'request_timeout'

Anyone experience this?

Using pyautogen on python 3.11.6 in a virtual environment.

Found the solution here
Change...

llm_config={
    "request_timeout": 600,

to...

 llm_config = {
        "timeout": 600,

@MarkB122
Copy link

MarkB122 commented Dec 3, 2023

  1. autogen.AssistantAgent error fix:
    pip uninstall autogen pyautogen
    pip install pyautogen
  2. request_timeout issue:
    "timeout": 600
  3. Infinte loop issue:
    in the user_proxy set the max_consecutive_auto_reply=0
  4. Stopping a session
    ctrl + c

@Trundicho
Copy link

For me it seems when ever I get a ''' in the LLM response autogen stops with "Process finished with exit code 0"

Example LLM Output:
`CTO (to user_proxy):

def get_numbers():
    return list(range(1, 201))
with open("generated.py", "w") as f:
    f.write('''print(*get_numbers())''')

Process finished with exit code 0`

@manjunathshiva
Copy link

Here is the complete code. Am using text gen web UI local model not Run Pod using Mistral 7B instruct Q8 GGUF. Be sure to enable openai and gallery extensions and api and listen Under Sessions tab on Text Gen Web UI

import autogen

config_list = [
{
"base_url": "http://localhost:5000/v1",
"api_key": "NULL",
}
]

llm_config={
"timeout": 600,
"seed": 42,
"config_list": config_list,
}

USE_MEMGPT = True

assistant = autogen.AssistantAgent(
name="CTO",
llm_config=llm_config,
system_message="Chief technical officer of a tech company"
)

user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=0,
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={"work_dir": "web"},
llm_config=llm_config,
system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)

task = """
Write python code to output numbers 1 to 100, and then store the code in a file
"""

user_proxy.initiate_chat(
assistant,
message=task
)

task2 = """
Change the code in the file you just created to instead output numbers 1 to 200
"""

user_proxy.initiate_chat(
assistant,
message=task2
)

@ray30087
Copy link

ray30087 commented Jan 9, 2024

I'm getting stuck on the following error:
raise self._make_status_error_from_response(err.response) from None
openai.RateLimitError: Error code: 429 - {'error': {'message': 'Rate limit reached for gpt-4 in organization org-ehVxQx3I1TFqEcMydXbUkFUz on tokens per min (TPM): Limit 10000, Used 9343, Requested 1103. Please try again in 2.676s. Visit https://platform.openai.com/account/rate-limits to learn more.', 'type': 'tokens', 'param': None, 'code': 'rate_limit_exceeded'}}
what can i do with the rate-limiting error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment