mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
feat: add Azure OpenAI provider support
This commit is contained in:
@@ -14,6 +14,12 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
priority: 1,
|
||||
apiKey: "",
|
||||
});
|
||||
const [azureData, setAzureData] = useState({
|
||||
azureEndpoint: "",
|
||||
apiVersion: "2024-10-01-preview",
|
||||
deployment: "",
|
||||
organization: "",
|
||||
});
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [testResult, setTestResult] = useState(null);
|
||||
const [validating, setValidating] = useState(false);
|
||||
@@ -27,12 +33,22 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
priority: connection.priority || 1,
|
||||
apiKey: "",
|
||||
});
|
||||
// Load Azure-specific data if present
|
||||
if (connection.provider === "azure" && connection.providerSpecificData) {
|
||||
setAzureData({
|
||||
azureEndpoint: connection.providerSpecificData.azureEndpoint || "",
|
||||
apiVersion: connection.providerSpecificData.apiVersion || "2024-10-01-preview",
|
||||
deployment: connection.providerSpecificData.deployment || "",
|
||||
organization: connection.providerSpecificData.organization || "",
|
||||
});
|
||||
}
|
||||
setTestResult(null);
|
||||
setValidationResult(null);
|
||||
}
|
||||
}, [connection]);
|
||||
|
||||
const isOAuth = connection?.authType === "oauth";
|
||||
const isAzure = connection?.provider === "azure";
|
||||
const isCompatible = connection
|
||||
? (isOpenAICompatibleProvider(connection.provider) || isAnthropicCompatibleProvider(connection.provider))
|
||||
: false;
|
||||
@@ -60,7 +76,11 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
const res = await fetch("/api/providers/validate", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ provider: connection.provider, apiKey: formData.apiKey }),
|
||||
body: JSON.stringify({
|
||||
provider: connection.provider,
|
||||
apiKey: formData.apiKey,
|
||||
...(isAzure ? { providerSpecificData: azureData } : {}),
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
setValidationResult(data.valid ? "success" : "failed");
|
||||
@@ -89,7 +109,11 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
const res = await fetch("/api/providers/validate", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ provider: connection.provider, apiKey: formData.apiKey }),
|
||||
body: JSON.stringify({
|
||||
provider: connection.provider,
|
||||
apiKey: formData.apiKey,
|
||||
...(isAzure ? { providerSpecificData: azureData } : {}),
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
isValid = !!data.valid;
|
||||
@@ -106,6 +130,17 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
updates.lastErrorAt = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Add Azure-specific data if this is an Azure connection
|
||||
if (isAzure) {
|
||||
updates.providerSpecificData = {
|
||||
azureEndpoint: azureData.azureEndpoint,
|
||||
apiVersion: azureData.apiVersion,
|
||||
deployment: azureData.deployment,
|
||||
organization: azureData.organization,
|
||||
};
|
||||
}
|
||||
|
||||
await onSave(updates);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
@@ -162,7 +197,43 @@ export default function EditConnectionModal({ isOpen, connection, proxyPools, on
|
||||
</>
|
||||
)}
|
||||
|
||||
{!isCompatible && (
|
||||
{isAzure && (
|
||||
<div className="bg-sidebar/50 p-4 rounded-lg border border-accent/20">
|
||||
<h3 className="font-semibold mb-3 text-sm">Azure OpenAI Configuration</h3>
|
||||
<div className="flex flex-col gap-3">
|
||||
<Input
|
||||
label="Azure Endpoint"
|
||||
value={azureData.azureEndpoint}
|
||||
onChange={(e) => setAzureData({ ...azureData, azureEndpoint: e.target.value })}
|
||||
placeholder="https://your-resource.openai.azure.com"
|
||||
hint="Your Azure OpenAI resource endpoint URL"
|
||||
/>
|
||||
<Input
|
||||
label="Deployment Name"
|
||||
value={azureData.deployment}
|
||||
onChange={(e) => setAzureData({ ...azureData, deployment: e.target.value })}
|
||||
placeholder="gpt-4"
|
||||
hint="The deployment name in your Azure resource"
|
||||
/>
|
||||
<Input
|
||||
label="API Version"
|
||||
value={azureData.apiVersion}
|
||||
onChange={(e) => setAzureData({ ...azureData, apiVersion: e.target.value })}
|
||||
placeholder="2024-10-01-preview"
|
||||
hint="Azure OpenAI API version to use"
|
||||
/>
|
||||
<Input
|
||||
label="Organization"
|
||||
value={azureData.organization}
|
||||
onChange={(e) => setAzureData({ ...azureData, organization: e.target.value })}
|
||||
placeholder="Organization ID"
|
||||
hint="Required for billing"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isCompatible && !isAzure && (
|
||||
<div className="flex items-center gap-3">
|
||||
<Button onClick={handleTest} variant="secondary" disabled={testing}>
|
||||
{testing ? "Testing..." : "Test Connection"}
|
||||
@@ -202,3 +273,4 @@ EditConnectionModal.propTypes = {
|
||||
onSave: PropTypes.func.isRequired,
|
||||
onClose: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user