-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Enable Azure Open AI function calling via Azure Functions #1133
base: main
Are you sure you want to change the base?
Conversation
@@ -123,6 +123,11 @@ class _AzureOpenAISettings(BaseSettings): | |||
embedding_endpoint: Optional[str] = None | |||
embedding_key: Optional[str] = None | |||
embedding_name: Optional[str] = None | |||
function_call_azure_functions_enabled: bool = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this Optional[bool] for consistency?
# Remote function calls | ||
if app_settings.azure_openai.function_call_azure_functions_enabled: | ||
azure_functions_tools_url = f"{app_settings.azure_openai.function_call_azure_functions_tools_base_url}?code={app_settings.azure_openai.function_call_azure_functions_tools_key}" | ||
response = requests.get(azure_functions_tools_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use an async call here
"tool_name": function_name, | ||
"tool_arguments": json.loads(function_args) | ||
} | ||
response = requests.post(azure_functions_tool_url, data=json.dumps(body), headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make this async as well
) | ||
] | ||
} | ||
if messages[-1]["role"] == "user": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a safety check here that len(messages) > 0 would be good
Motivation and Context
Description
This PR implements OpenAI Function Calling feature.
It uses Azure Functions to retrieve the OpenAI tools metadata JSON, and also to run the functions.
To add new OpenAI Functions, only the code in Azure Functions needs to be modified.
Architecture
1, 2 - Get JSON with OpenAI function call metadata
3, 4, 5, 6 - Send user prompt to Open AI model optionally with On Your Data, querying Azure AI Search
7, 8 - If Open AI model returns any function call, execute the function remotely using App Functions
9, 10 - Submit the results from Azure Function call execution to OpenAI to generate the final answer
This enables users to add real-time data to their chatbots, or to implement actions.
Azure Functions
There are two Azure Functions:
Azure Functions code sample
Contribution Checklist