mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
Add Cloudflare AI provider support and enhance connection management
- Introduced Cloudflare AI as a new provider with specific configurations in providerModels.js and providers.js. - Updated DefaultExecutor to handle account ID resolution for Cloudflare AI connections. - Enhanced AddApiKeyModal and EditConnectionModal to include account ID input for Cloudflare AI. - Implemented validation for Cloudflare AI API key connections in testUtils.js and route.js. - Updated UI components to reflect changes in provider management and connection handling.
This commit is contained in:
@@ -95,6 +95,29 @@ export async function POST(request) {
|
||||
});
|
||||
}
|
||||
|
||||
if (provider === "cloudflare-ai") {
|
||||
const { providerSpecificData } = body;
|
||||
const accountId = providerSpecificData?.accountId;
|
||||
if (!accountId) {
|
||||
return NextResponse.json({ valid: false, error: "Missing Account ID" });
|
||||
}
|
||||
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/chat/completions`;
|
||||
const cfRes = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
model: getDefaultModel("cloudflare-ai"),
|
||||
messages: [{ role: "user", content: "test" }],
|
||||
max_tokens: 1,
|
||||
}),
|
||||
});
|
||||
isValid = cfRes.status !== 401 && cfRes.status !== 403 && cfRes.status !== 404;
|
||||
return NextResponse.json({
|
||||
valid: isValid,
|
||||
error: isValid ? null : "Invalid API token or Account ID",
|
||||
});
|
||||
}
|
||||
|
||||
if (provider === "azure") {
|
||||
const { providerSpecificData } = body;
|
||||
const endpoint = (providerSpecificData?.azureEndpoint || "").replace(/\/$/, "");
|
||||
|
||||
Reference in New Issue
Block a user