mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:14:33 +00:00
Conditional azure openai endpoint usage
This commit is contained in:
committed by
Ayaan Zaidi
parent
06a3175cd1
commit
4ed12c18a0
@@ -211,7 +211,7 @@ function resolveAliasError(params: {
|
||||
return `Alias ${normalized} already points to ${existingKey}.`;
|
||||
}
|
||||
|
||||
function buildOpenAiHeaders(apiKey: string) {
|
||||
function buildAzureOpenAiHeaders(apiKey: string) {
|
||||
const headers: Record<string, string> = {};
|
||||
if (apiKey) {
|
||||
headers["api-key"] = apiKey;
|
||||
@@ -219,6 +219,14 @@ function buildOpenAiHeaders(apiKey: string) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
function buildOpenAiHeaders(apiKey: string) {
|
||||
const headers: Record<string, string> = {};
|
||||
if (apiKey) {
|
||||
headers.Authorization = `Bearer ${apiKey}`;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
function buildAnthropicHeaders(apiKey: string) {
|
||||
const headers: Record<string, string> = {
|
||||
"anthropic-version": "2023-06-01",
|
||||
@@ -311,16 +319,34 @@ async function requestOpenAiVerification(params: {
|
||||
modelId: params.modelId,
|
||||
endpointPath: "chat/completions",
|
||||
});
|
||||
return await requestVerification({
|
||||
endpoint,
|
||||
headers: buildOpenAiHeaders(params.apiKey),
|
||||
body: {
|
||||
messages: [{ role: "user", content: "Hi" }],
|
||||
temperature: 1,
|
||||
max_completion_tokens: DEFAULT_MAX_TOKENS,
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
const isBaseUrlAzureUrl = isAzureUrl(params.baseUrl);
|
||||
const headers = isBaseUrlAzureUrl
|
||||
? buildAzureOpenAiHeaders(params.apiKey)
|
||||
: buildOpenAiHeaders(params.apiKey);
|
||||
if (isBaseUrlAzureUrl) {
|
||||
return await requestVerification({
|
||||
endpoint,
|
||||
headers,
|
||||
body: {
|
||||
messages: [{ role: "user", content: "Hi" }],
|
||||
temperature: 1,
|
||||
max_completion_tokens: DEFAULT_MAX_TOKENS,
|
||||
stream: false,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return await requestVerification({
|
||||
endpoint,
|
||||
headers,
|
||||
body: {
|
||||
model: params.modelId,
|
||||
messages: [{ role: "user", content: "Hi" }],
|
||||
temperature: 1,
|
||||
max_tokens: 1,
|
||||
stream: false,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function requestAnthropicVerification(params: {
|
||||
|
||||
Reference in New Issue
Block a user