microsoft / teams-ai

SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
MIT License
350 stars 144 forks source link

[PY] feat: Azure OpenAI On Your Data - Azure AI Search support #1670

Closed lifan0127 closed 2 weeks ago

lifan0127 commented 1 month ago

Linked issues

closes: #1730

related PR: https://github.com/microsoft/teams-ai/pull/1426 (JS implementation)

Details

Hi, I recently needed to create a Python-based RAG bot using teams-ai and realized the "Azure OpenAI On Your Data" feature was not quite complete. So I made some small changes to make it work.

Change details

Describe your changes, with screenshots and code snippets as appropriate

code snippets:

The main change is to add the data source info in to the extra_body for the OpenAI API call:

        try:
+            extra_body = {}
+            if template.config.completion.data_sources is not None:
+                 extra_body["data_sources"] = template.config.completion.data_sources
            completion = await self._client.chat.completions.create(
                messages=messages,
                model=model,
                presence_penalty=template.config.completion.presence_penalty,
                frequency_penalty=template.config.completion.frequency_penalty,
                top_p=template.config.completion.top_p,
                temperature=template.config.completion.temperature,
                max_tokens=max_tokens,
+               extra_body=extra_body,
            )

Attestation Checklist

Additional information

Feel free to add other relevant information below

lifan0127 commented 1 month ago

@microsoft-github-policy-service agree company="IFF"

lifan0127 commented 1 month ago

The changes look good. Could you add a sample as well. You can look at this: JS PR, JS azureOpenAI sample. Most of the sample files are scaffolding which you can copy from python sample.

Hi @singhk97 I have added an example based on the JS example: https://github.com/microsoft/teams-ai/tree/main/js/samples/04.ai-apps/h.datasource-azureOpenAI

singhk97 commented 2 weeks ago

@lifan0127 I've picked up your commits and made a few tweaks in this PR: #1759. Thanks!