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:
@@ -367,6 +367,19 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
|
||||
|
||||
try {
|
||||
switch (connection.provider) {
|
||||
case "cloudflare-ai": {
|
||||
const psd = connection.providerSpecificData || {};
|
||||
const accountId = psd.accountId;
|
||||
if (!accountId) return { valid: false, error: "Missing Account ID" };
|
||||
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/chat/completions`;
|
||||
const res = await fetchWithConnectionProxy(url, {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${connection.apiKey}`, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ model: getDefaultModel("cloudflare-ai"), messages: [{ role: "user", content: "test" }], max_tokens: 1 }),
|
||||
}, effectiveProxy);
|
||||
const valid = res.status !== 401 && res.status !== 403 && res.status !== 404;
|
||||
return { valid, error: valid ? null : "Invalid API token or Account ID" };
|
||||
}
|
||||
case "azure": {
|
||||
const psd = connection.providerSpecificData || {};
|
||||
const endpoint = (psd.azureEndpoint || "").replace(/\/$/, "");
|
||||
|
||||
@@ -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