pass in the format of "provider/model"
This commit is contained in:
parent
73ee3e047a
commit
73b5db9410
4 changed files with 24 additions and 5 deletions
|
|
@ -72,6 +72,7 @@ export function createLlmApi(
|
|||
} else {
|
||||
config = {
|
||||
provider: model.provider as any,
|
||||
model: model.model,
|
||||
apiKey: model.apiKey,
|
||||
apiBase: model.apiBase,
|
||||
requestOptions: model.requestOptions,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ export class AiSdkApi implements BaseLlmApi {
|
|||
|
||||
constructor(config: AiSdkConfig) {
|
||||
this.config = config;
|
||||
if (!config.model) {
|
||||
throw new Error(
|
||||
"AI SDK provider requires a model in the format '<provider>/<model>' (e.g., 'openai/gpt-4o')",
|
||||
);
|
||||
}
|
||||
const [providerId, ...modelParts] = config.model.split("/");
|
||||
this.providerId = providerId;
|
||||
this.modelId = modelParts.join("/");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import dotenv from "dotenv";
|
||||
import { z } from "zod";
|
||||
import { AiSdkApi } from "./apis/AiSdk.js";
|
||||
import { AnthropicApi } from "./apis/Anthropic.js";
|
||||
import { AskSageApi } from "./apis/AskSage.js";
|
||||
import { AzureApi } from "./apis/Azure.js";
|
||||
|
|
@ -164,6 +165,8 @@ export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined {
|
|||
// Return undefined for native HuggingFace endpoints
|
||||
// (handled by HuggingFaceInferenceAPI class in core)
|
||||
return undefined;
|
||||
case "ai-sdk":
|
||||
return new AiSdkApi(config);
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
|
@ -182,14 +185,16 @@ export {
|
|||
} from "openai/resources/index";
|
||||
|
||||
// export
|
||||
export { AiSdkApi } from "./apis/AiSdk.js";
|
||||
export type { BaseLlmApi } from "./apis/base.js";
|
||||
export type {
|
||||
LLMConfig,
|
||||
AskSageTool,
|
||||
AskSageToolChoice,
|
||||
AskSageToolCall,
|
||||
AiSdkConfig,
|
||||
AskSageResponse,
|
||||
AskSageTokenResponse,
|
||||
AskSageTool,
|
||||
AskSageToolCall,
|
||||
AskSageToolChoice,
|
||||
LLMConfig,
|
||||
} from "./types.js";
|
||||
|
||||
export {
|
||||
|
|
@ -200,4 +205,4 @@ export {
|
|||
} from "./apis/AnthropicUtils.js";
|
||||
|
||||
export { isResponsesModel } from "./apis/openaiResponses.js";
|
||||
export { parseDataUrl, extractBase64FromDataUrl } from "./util/url.js";
|
||||
export { extractBase64FromDataUrl, parseDataUrl } from "./util/url.js";
|
||||
|
|
|
|||
|
|
@ -249,6 +249,13 @@ export const VertexAIConfigSchema = BasePlusConfig.extend({
|
|||
});
|
||||
export type VertexAIConfig = z.infer<typeof VertexAIConfigSchema>;
|
||||
|
||||
export const AiSdkConfigSchema = BasePlusConfig.extend({
|
||||
provider: z.literal("ai-sdk"),
|
||||
model: z.string(),
|
||||
providerOptions: z.record(z.unknown()).optional(),
|
||||
});
|
||||
export type AiSdkConfig = z.infer<typeof AiSdkConfigSchema>;
|
||||
|
||||
// Discriminated union
|
||||
export const LLMConfigSchema = z.discriminatedUnion("provider", [
|
||||
OpenAIConfigSchema,
|
||||
|
|
@ -268,5 +275,6 @@ export const LLMConfigSchema = z.discriminatedUnion("provider", [
|
|||
ContinueProxyConfigSchema,
|
||||
CometAPIConfigSchema,
|
||||
AskSageConfigSchema,
|
||||
AiSdkConfigSchema,
|
||||
]);
|
||||
export type LLMConfig = z.infer<typeof LLMConfigSchema>;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue