ChatDev icon indicating copy to clipboard operation
ChatDev copied to clipboard

Feat: Allow Azure ChatGPT usage

Open dnhkng opened this issue 1 year ago • 4 comments

Adds access to the environment variable "OPENAI_API_ENGINE", which is needed for the Azure API.

The Azure API requires the use of the 'engine' parameter in the ChatCompletion and not the 'model' parameter. ie, from the documentation, here are the needed parameters:

response = openai.ChatCompletion.create(
    engine="gpt-35-turbo", # Here we use 'engine', not 'model'
    messages=[
        {"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
        {"role": "user", "content": "Who were the founders of Microsoft?"}
    ]
)

This patch lets you use your Azure ChatGPT account by defining the engine and other required variables as environment variables, without affecting the standard OpenAI API use. Azure API access is used like this:

OPENAI_API_BASE="https://your_deployment_name.openai.azure.com/" OPENAI_API_TYPE=azure OPENAI_API_ENGINE=your_model_name OPENAI_API_VERSION=2023-05-15 OPENAI_API_KEY=your_secret_key python3 run.py --task "Snake game in pure html" --name "WebSnake"

This has been tested with Azure and OpenAI APIs successfully.

dnhkng avatar Oct 17 '23 10:10 dnhkng

Hi! Thanks for this. It helped me find the error for my system and I can now use Azure! 🥳

OhNotWilliam avatar Oct 25 '23 12:10 OhNotWilliam

Hi, do you have any idea how Azure can be used with the docker version?

AkivaAK avatar Nov 05 '23 09:11 AkivaAK

@AkivaAK Apply my diff, and it should work I think.

dnhkng avatar Nov 14 '23 13:11 dnhkng

@cryptictech Maybe I can use the same way to implement the function I want, I will use a third-party api, they will have the same api capabilities as open ai, just the base url is different.

kirinzer avatar Feb 05 '24 04:02 kirinzer