Azure / azure-functions-openai-extension

An extension that adds support for Azure OpenAI/ OpenAI bindings in Azure Functions for LLM (GPT-3.5-Turbo, GPT-4, etc)
MIT License
73 stars 26 forks source link

[Bug] Using managed identity for chat table storage results in "Exception while executing function: Functions.GetChatState The assistant must be initialized first using CreateAssistantAsync (Parameter 'tableClient')" when calling a Post or Get after the chat is initialized successfully #112

Open eamonoreilly opened 3 weeks ago

eamonoreilly commented 3 weeks ago

What language are you using?

Dotnet (OOP)

Expected Behavior

Should be able to call AssistantPostInput binding once the chat has been initialized with AssistantCreateOutput successfully.

Actual Behavior

Using the new support for specifying the ChatStorageConnectionString in the function binding AssistantCreateOutput prevents the other two calls AssistantPostInput and AssistantQueryInput from working when running in Azure with the below error: Exception while executing function: Functions.GetChatState The assistant must be initialized first using CreateAssistantAsync (Parameter 'tableClient')

When you run locally it works successfully but gives the above error when running in Azure.

Host.json

No response

Steps to Reproduce

Follow the chat sample in the repro and create a new app setting called OpenAiStorageConnection__tableServiceUri that points to https://.table.core.windows.net. Give the managed system identity of the function app and your user account table contributor access to this storage account. Update the chat sample with the following in the code. return new CreateChatBotOutput { HttpResponse = new ObjectResult(responseJson) { StatusCode = 201 }, ChatBotCreateRequest = new AssistantCreateRequest(chatId, createRequestBody?.Instructions) { ChatStorageConnectionSetting = "OpenAiStorageConnection", CollectionName = "SampleChatState" }, }; }

If you run this locally, you should be able to create a new chat and post messages to it as defined in the sample. This works as expected.

If you publish the app to Azure, you can create a new chat session successfully, but post messages result in the error

Exception while executing function: Functions.GetChatState The assistant must be initialized first using CreateAssistantAsync (Parameter 'tableClient')

Relevant code being tried

No response

Relevant log output

No response

Where are you facing this problem?

Production Environment (explain below)

Additional Information

No response