feat: add Azure OpenAI provider support
This commit is contained in:
@@ -63,6 +63,35 @@ export async function POST(request) {
|
||||
});
|
||||
}
|
||||
|
||||
if (provider === "azure") {
|
||||
const { providerSpecificData } = body;
|
||||
const endpoint = (providerSpecificData?.azureEndpoint || "").replace(/\/$/, "");
|
||||
const deployment = providerSpecificData?.deployment || "gpt-4";
|
||||
const apiVersion = providerSpecificData?.apiVersion || "2024-10-01-preview";
|
||||
const organization = providerSpecificData?.organization;
|
||||
|
||||
const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
|
||||
const headers = {
|
||||
"api-key": apiKey,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
if (organization) headers["OpenAI-Organization"] = organization;
|
||||
|
||||
const azureRes = await fetch(url, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
messages: [{ role: "user", content: "test" }],
|
||||
max_tokens: 1,
|
||||
}),
|
||||
});
|
||||
isValid = azureRes.status !== 401 && azureRes.status !== 403;
|
||||
return NextResponse.json({
|
||||
valid: isValid,
|
||||
error: isValid ? null : "Invalid API key or Azure configuration",
|
||||
});
|
||||
}
|
||||
|
||||
switch (provider) {
|
||||
case "openai":
|
||||
const openaiRes = await fetch("https://api.openai.com/v1/models", {
|
||||
|
||||
Reference in New Issue
Block a user