Chainlit / openai-assistant

MIT License
15 stars 14 forks source link

How to make it compatible with Azure OpenAI Assistants + Function Calling? #1

Open Shivanandroy opened 1 month ago

samaea commented 3 weeks ago

In app.py:-

Change

from openai import AsyncAssistantEventHandler, AsyncOpenAI, OpenAI

to

from openai import AsyncAssistantEventHandler, AsyncAzureOpenAI, AzureOpenAI

Change

async_openai_client = AsyncOpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
sync_openai_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

to

async_openai_client = AsyncAzureOpenAI(
        azure_endpoint=os.getenv("OPENAI_API_BASE"),
        api_key=os.getenv("OPENAI_API_KEY"),
        api_version=os.getenv("OPENAI_API_VERSION"),
)

sync_openai_client = AzureOpenAI(
        azure_endpoint=os.getenv("OPENAI_API_BASE"),
        api_key=os.getenv("OPENAI_API_KEY"),
        api_version=os.getenv("OPENAI_API_VERSION"),
)

In .env, change to:-

OPENAI_API_TYPE="azure"
OPENAI_API_VERSION="2024-05-01-preview"
OPENAI_API_BASE="https://[NAME_OF_INSTANCE].openai.azure.com/"
OPENAI_API_KEY="[AZURE_OPENAI_KEY"

Under requirements.txt:-

openai==1.33.0
chainlit

Worth noting:- it looks like the code interrupter is working, but I am not able to get the visualisations working as shown below:-

image

P.S:- I am not one of the contributor to this project.

samaea commented 3 weeks ago

Ended up forking the repo and implemented step-by-step instructions here:- https://github.com/samaea/azure-openai-assistant-with-chainlit.