Skip to content

Conversation

ysfscream
Copy link
Member

@ysfscream ysfscream commented Apr 16, 2025

PR Checklist

If you have any questions, you can refer to the Contributing Guide

What is the current behavior?

Currently, MQTTX Copilot does not support using Azure OpenAI as an AI service provider. Users are limited to the existing providers like OpenAI, Google, Anthropic, etc.

Issue Number

What is the new behavior?

This PR introduces support for Azure OpenAI within MQTTX Copilot, allowing users to configure and utilize their Azure OpenAI deployments.

  • Adds "Azure OpenAI" to the list of available AI providers in the Copilot settings.
  • Enables configuration via Azure Endpoint URL or Resource Name (provided in the "API Host" field).
  • Requires the API Version to be appended as a query parameter (?api-version=...) to the API Host field.
  • Requires Azure Deployment Names to be prefixed with deployment- when entered in the "Model" field.
  • Includes a build-time patch to fix an upstream dependency issue in @ai-sdk/azure.
  • Updates unit tests to cover Azure OpenAI configuration and instantiation, and improves test coverage for other providers.

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known before review?

Azure OpenAI Integration Notes:

  • Goal: The primary goal was to add Azure OpenAI support with minimal changes to the existing architecture, avoiding the introduction of a distinct "Provider" selection logic or adding new database fields/Vuex states specifically for Azure configuration where possible. This led to some non-standard configuration approaches.
  • Configuration:
    • Endpoint/Resource Name: Azure's "Endpoint URL" (e.g., https://your-resource.openai.azure.com/) OR "Resource Name" (e.g., your-resource) should be entered into the existing "API Host" field in the settings.
    • API Version: The Azure "API Version" (e.g., 2025-01-01-preview) must be appended as a query parameter to the URL/Resource Name entered in the "API Host" field. Example: https://your-resource.openai.azure.com/?api-version=2025-01-01-preview or your-resource?api-version=2025-01-01-preview.
    • Rationale: This approach avoids adding a separate "API Version" input field and associated state/DB changes. The getAzureProviderOptions helper function in src/utils/ai/copilot.ts parses the api-version from the baseURL string.
  • Model Naming (Deployment Name):
    • Azure models (Deployments) should be prefixed with deployment- when entered into the "Model" field (e.g., deployment-gpt-4o).
    • Rationale: This convention helps distinguish Azure Deployments from standard OpenAI model names within the same configuration structure and aids the determineProviderType logic in AIAgent.ts without needing a separate "Provider" field tied to the model selection. The processModel function in AIAgent.ts handles stripping this prefix before passing the actual deployment name to the Azure SDK.
  • Patch Script: Includes a build-time patch script scripts/patch-azure-sdk.js (run via postinstall) to fix an upstream dependency resolution issue in @ai-sdk/azure related to @ai-sdk/openai/internal.
  • Documentation: Due to these non-standard configuration requirements, user documentation must clearly explain how to correctly configure the "API Host" (including appending ?api-version=...) and "Model" (using the deployment- prefix) fields for Azure OpenAI. Reference: Azure OpenAI.
  • Testing: Unit tests in tests/unit/utils/ai/copilot.spec.ts have been updated to cover the Azure OpenAI provider instantiation and the handling of its specific configuration parameters. Tests for other providers have also been made more explicit.

Other information

This implementation relies on parsing the API version from the user-provided Base URL/API Host string and uses a naming convention (deployment- prefix) for Azure models to integrate with the existing system structure with minimal disruption. Ensure UI labels/placeholders clearly guide the user on these specific Azure configuration steps.

@ysfscream ysfscream added desktop MQTTX Desktop test labels Apr 16, 2025
@ysfscream ysfscream added this to the v1.12.0 milestone Apr 16, 2025
@ysfscream ysfscream requested review from Red-Asuka and Copilot April 16, 2025 05:59
@ysfscream ysfscream self-assigned this Apr 16, 2025
@ysfscream ysfscream added this to MQTTX Apr 16, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

tests/unit/utils/ai/copilot.spec.ts:123

  • The test for the Azure API host placeholder uses a template-like string with '${resourceName}'. If this string is intended as a literal placeholder, consider clarifying it in both the test and documentation. Otherwise, update the expected value to match the actual dynamic output.
expect(azureHostExample).to.equal('https://${resourceName}.openai.azure.com')

tests/unit/utils/ai/copilot.spec.ts:217

  • The fallback test for a misconfigured Azure OpenAI provider only checks for the absence of an error. It would be beneficial to assert that the returned provider instance is actually the OpenAI instance to better confirm the fallback behavior.
getModelProvider({ model: 'deployment-gpt-4o', baseURL: '', apiKey: 'test-key-azure', providerType: 'Azure OpenAI', })

@ysfscream ysfscream moved this to In Progress in MQTTX Apr 16, 2025
@Red-Asuka Red-Asuka merged commit dabf2dc into main Apr 16, 2025
4 checks passed
@Red-Asuka Red-Asuka deleted the ysf/desktop branch April 16, 2025 09:38
@github-project-automation github-project-automation bot moved this from In Progress to Done in MQTTX Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop MQTTX Desktop test
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants