@friendliai/ai-provider
Version:
Learn how to use the FriendliAI provider for the Vercel AI SDK.
101 lines (96 loc) • 3.92 kB
text/typescript
import { LanguageModelV1 } from '@ai-sdk/provider';
import { FetchFunction } from '@ai-sdk/provider-utils';
import { OpenAICompatibleChatSettings } from '@ai-sdk/openai-compatible';
import { z } from 'zod';
declare const FriendliAIServerlessModelIds: readonly ["meta-llama-3.1-8b-instruct", "meta-llama-3.1-70b-instruct", "meta-llama-3.3-70b-instruct", "deepseek-r1"];
type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
type FriendliAIBetaChatModelId = 'llama-3.2-11b-vision-instruct' | (string & {});
interface FriendliAISharedSettings {
/**
* Sets the endpoint to which the request will be sent.
* auto: automatically selected based on model_id
* dedicated: Fixed to "/dedicated/v1"
* serverless: automatically selected as one of "/serverless/beta", "/serverless/v1", or "/serverless/tools/v1"
* Ignored if baseURL is specified.
*/
endpoint?: 'auto' | 'dedicated' | 'serverless';
}
interface FriendliAIChatSettings extends FriendliAISharedSettings, OpenAICompatibleChatSettings {
/**
* BETA FEATURE: Include the model's training loss in the response.
*/
tools?: Array<{
type: 'web:url' | 'web:search' | 'math:calendar' | 'math:statistics' | 'math:calculator' | 'code:python-interpreter';
}>;
/**
* Whether to enable parallel function calling during tool use. Default to true.
*/
parallelToolCalls?: boolean;
/**
* BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
*/
regex?: RegExp;
}
interface FriendliAIProviderSettings {
/**
* FriendliAI API key. (FRIENDLI__TOKEN)
*/
apiKey?: string;
/**
* Base URL for the API calls.
*/
baseURL?: string;
/**
* Custom headers to include in the requests.
*/
headers?: Record<string, string>;
/**
* FriendliAI Team ID.
*/
teamId?: string;
/**
* Custom fetch implementation. You can use it as a middleware to intercept requests,
* or to provide a custom fetch implementation for e.g. testing.
*/
fetch?: FetchFunction;
}
interface FriendliAIProvider {
/**
* Creates a model for text generation.
*/
(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
/**
* A model that has not yet been officially released
*/
beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
/**
* Creates a chat model for text generation.
*/
chat(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
chatModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
/**
* Creates a completion model for text generation.
*/
completion(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
completionModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
/**
* Creates a text embedding model for text generation.
*/
embedding(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
textEmbeddingModel(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
}
/**
Create an FriendliAI provider instance.
*/
declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
declare const friendli: FriendliAIProvider;
declare const friendliaiErrorSchema: z.ZodObject<{
message: z.ZodString;
}, "strip", z.ZodTypeAny, {
message: string;
}, {
message: string;
}>;
type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, friendli };