@adaline/openai 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,17 +2,17 @@ import { z } from 'zod';
2
2
  import { RangeConfigItem, CHAT_CONFIG, SelectBooleanConfigItem, SelectStringConfigItem, ObjectSchemaConfigItem, ChatModelSchema, EmbeddingModelSchema, MultiStringConfigItem, ProviderError, urlWithoutTrailingSlash, InvalidModelRequestError, removeUndefinedEntries, getMimeTypeFromBase64, InvalidConfigError, InvalidMessagesError, InvalidToolsError, ModelResponseError, ModelError, InvalidEmbeddingRequestsError } from '@adaline/provider';
3
3
  import { ResponseSchema, SystemRoleLiteral, UserRoleLiteral, AssistantRoleLiteral, ToolRoleLiteral, TextModalityLiteral, ImageModalityLiteral, ToolCallModalityLiteral, ToolResponseModalityLiteral, EmbeddingTextModalityLiteral, EmbeddingTokenModalityLiteral, Config, Base64ImageContentTypeLiteral, UrlImageContentTypeLiteral, Message, Tool, createTextContent, createToolCallContent, EmbeddingRequests, Base64EmbeddingLiteral, FloatEmbeddingLiteral, createPartialTextMessage, createPartialToolCallMessage } from '@adaline/types';
4
4
 
5
- var en=Object.defineProperty,on=Object.defineProperties;var tn=Object.getOwnPropertyDescriptors;var Xo=Object.getOwnPropertySymbols;var nn=Object.prototype.hasOwnProperty,sn=Object.prototype.propertyIsEnumerable;var an=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n);var Qo=(n,e,t)=>e in n?en(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,M=(n,e)=>{for(var t in e||(e={}))nn.call(e,t)&&Qo(n,t,e[t]);if(Xo)for(var t of Xo(e))sn.call(e,t)&&Qo(n,t,e[t]);return n},G=(n,e)=>on(n,tn(e));var A=(n,e,t)=>new Promise((o,s)=>{var a=l=>{try{i(t.next(l));}catch(h){s(h);}},d=l=>{try{i(t.throw(l));}catch(h){s(h);}},i=l=>l.done?o(l.value):Promise.resolve(l.value).then(a,d);i((t=t.apply(n,e)).next());}),rn=function(n,e){this[0]=n,this[1]=e;},ee=(n,e,t)=>{var o=(d,i,l,h)=>{try{var c=t[d](i),g=(i=c.value)instanceof rn,y=c.done;Promise.resolve(g?i[0]:i).then(O=>g?o(d==="return"?d:"next",i[1]?{done:O.done,value:O.value}:O,l,h):l({value:O,done:y})).catch(O=>o("throw",O,l,h));}catch(O){h(O);}},s=d=>a[d]=i=>new Promise((l,h)=>o(d,i,l,h)),a={};return t=t.apply(n,e),a[an("asyncIterator")]=()=>a,s("next"),s("throw"),s("return"),a};var je=RangeConfigItem({param:"temperature",title:CHAT_CONFIG.TEMPERATURE.title,description:CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),Fe=n=>RangeConfigItem({param:"max_tokens",title:CHAT_CONFIG.MAX_TOKENS.title,description:CHAT_CONFIG.MAX_TOKENS.description,min:0,max:n,step:1,default:0}),De=n=>MultiStringConfigItem({param:"stop",title:CHAT_CONFIG.STOP(n).title,description:CHAT_CONFIG.STOP(n).description,max:n}),Ne=RangeConfigItem({param:"top_p",title:CHAT_CONFIG.TOP_P.title,description:CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),$e=RangeConfigItem({param:"frequency_penalty",title:CHAT_CONFIG.FREQUENCY_PENALTY.title,description:CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Ue=RangeConfigItem({param:"presence_penalty",title:CHAT_CONFIG.PRESENCE_PENALTY.title,description:CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),He=RangeConfigItem({param:"seed",title:CHAT_CONFIG.SEED.title,description:CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Ve=SelectBooleanConfigItem({param:"logprobs",title:CHAT_CONFIG.LOG_PROBS.title,description:CHAT_CONFIG.LOG_PROBS.description,default:!1}),Ke=RangeConfigItem({param:"top_logprobs",title:CHAT_CONFIG.TOP_LOG_PROBS.title,description:CHAT_CONFIG.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),Je=SelectStringConfigItem({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","required","none"]});var D=(n,e)=>z.object({temperature:je.schema,maxTokens:Fe(n).schema,stop:De(e).schema,topP:Ne.schema,frequencyPenalty:$e.schema,presencePenalty:Ue.schema,seed:He.schema.transform(t=>t===0?void 0:t),logProbs:Ve.schema,topLogProbs:Ke.schema,toolChoice:Je.schema}),N=(n,e)=>({temperature:je.def,maxTokens:Fe(n).def,stop:De(e).def,topP:Ne.def,frequencyPenalty:$e.def,presencePenalty:Ue.def,seed:He.def,logProbs:Ve.def,topLogProbs:Ke.def,toolChoice:Je.def});var Zo=ObjectSchemaConfigItem({param:"response_schema",title:CHAT_CONFIG.RESPONSE_SCHEMA.title,description:CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:ResponseSchema}),et=SelectStringConfigItem({param:"response_format",title:CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),te=(n,e)=>G(M({},N(n,e)),{responseFormat:et.def,responseSchema:Zo.def}),ne=(n,e)=>D(n,e).extend({responseFormat:et.schema,responseSchema:Zo.schema});var tt=RangeConfigItem({param:"temperature",title:CHAT_CONFIG.TEMPERATURE.title,description:CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),nt=n=>RangeConfigItem({param:"max_completion_tokens",title:CHAT_CONFIG.MAX_TOKENS.title,description:CHAT_CONFIG.MAX_TOKENS.description,min:0,max:n,step:1,default:0}),st=(n,e)=>G(M({},te(n,e)),{temperature:tt.def,maxTokens:nt(n).def}),at=(n,e)=>ne(n,e).extend({temperature:tt.schema,maxTokens:nt(n).schema});var rt=SelectStringConfigItem({param:"response_format",title:CHAT_CONFIG.RESPONSE_FORMAT.title,description:CHAT_CONFIG.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),lt=(n,e)=>G(M({},N(n,e)),{responseFormat:rt.def}),pt=(n,e)=>D(n,e).extend({responseFormat:rt.schema});var We=SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),Ye=n=>RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:n,step:1,default:n});var ae=()=>z.object({encodingFormat:We.schema}),ie=()=>({encodingFormat:We.def});var mt=n=>ae().extend({dimensions:Ye(n).schema}),dt=n=>G(M({},ie()),{dimensions:Ye(n).def});var m={base:(n,e)=>({def:N(n,e),schema:D(n,e)}),responseFormat:(n,e)=>({def:lt(n,e),schema:pt(n,e)}),responseSchema:(n,e)=>({def:te(n,e),schema:ne(n,e)}),oSeries:(n,e)=>({def:st(n,e),schema:at(n,e)})},q={base:()=>({def:ie(),schema:ae()}),dimensions:n=>({def:dt(n),schema:mt(n)})};var _=z.enum([SystemRoleLiteral,UserRoleLiteral,AssistantRoleLiteral,ToolRoleLiteral]),T={system:SystemRoleLiteral,user:UserRoleLiteral,assistant:AssistantRoleLiteral,tool:ToolRoleLiteral},$=z.enum([UserRoleLiteral,AssistantRoleLiteral]),U={user:UserRoleLiteral,assistant:AssistantRoleLiteral};var b=[TextModalityLiteral,ImageModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral],P=z.enum([TextModalityLiteral,ImageModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral]),V=[TextModalityLiteral],K=z.enum([TextModalityLiteral]),S=[TextModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral],x=z.enum([TextModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral]);var de=z.object({token:z.string(),logprob:z.number(),bytes:z.array(z.number()).nullable()}),_t=z.object({content:z.array(de.extend({top_logprobs:z.array(de)})).nullable().optional(),refusal:z.array(de.extend({top_logprobs:z.array(de)})).nullable().optional()}).nullable(),yn=z.array(z.object({id:z.string().min(1),type:z.enum(["function"]),function:z.object({name:z.string(),arguments:z.string()})})),Tt=z.object({id:z.string(),object:z.literal("chat.completion"),created:z.number(),model:z.string(),system_fingerprint:z.string().nullable(),choices:z.array(z.object({index:z.number(),message:z.object({role:z.string(),content:z.string().nullable().optional(),tool_calls:yn.optional(),refusal:z.string().nullable().optional()}),logprobs:_t.optional(),finish_reason:z.string()})),usage:z.object({prompt_tokens:z.number(),completion_tokens:z.number(),total_tokens:z.number()})}),Mn=z.array(z.object({index:z.number().int(),id:z.string().min(1).optional(),type:z.enum(["function"]).optional(),function:z.object({name:z.string().min(1).optional(),arguments:z.string().optional()}).optional()})),gt=z.object({id:z.string(),object:z.string(),created:z.number(),model:z.string(),system_fingerprint:z.string().nullable(),choices:z.array(z.object({index:z.number(),delta:z.object({content:z.string().nullable().optional(),tool_calls:Mn.optional(),refusal:z.string().nullable().optional()}).or(z.object({})),logprobs:_t,finish_reason:z.string().nullable()})),usage:z.object({prompt_tokens:z.number(),completion_tokens:z.number(),total_tokens:z.number()}).nullable().optional()});var On=z.object({type:z.literal("function"),function:z.object({name:z.string().min(1),description:z.string().min(1).optional(),strict:z.boolean().optional(),parameters:z.any()})}),Cn=z.enum(["none","auto","required"]),bn=z.object({type:z.literal("function"),function:z.object({name:z.string().min(1)})}),Pn=z.object({type:z.enum(["text","json_object"])}).or(z.object({type:z.literal("json_schema"),json_schema:z.object({name:z.string().min(1),description:z.string().min(1).optional(),strict:z.boolean().optional(),schema:z.any()})})),Qe=z.object({text:z.string().min(1),type:z.literal("text")}),In=z.object({type:z.literal("image_url"),image_url:z.object({url:z.string().url().min(1),detail:z.enum(["low","high","auto"]).optional()})}),Sn=z.object({id:z.string().min(1),type:z.literal("function"),function:z.object({name:z.string().min(1),arguments:z.string().min(1)})}),xn=z.object({role:z.literal("system"),content:z.string().min(1).or(z.array(Qe).min(1))}),An=z.object({role:z.literal("user"),content:z.string().min(1).or(z.array(z.union([Qe,In])).min(1))}),En=z.object({role:z.literal("assistant"),content:z.string().min(1).or(z.array(Qe).min(1)).optional(),tool_calls:z.array(Sn).min(1).optional()}),Rn=z.object({role:z.literal("tool"),tool_call_id:z.string().min(1),content:z.string().min(1)}),wn=z.union([xn,An,En,Rn]),ce=z.object({model:z.string().min(1).optional(),messages:z.array(wn).min(1),frequency_penalty:z.number().min(-2).max(2).nullable().optional(),logprobs:z.boolean().nullable().optional(),top_logprobs:z.number().min(0).max(20).nullable().optional(),max_tokens:z.number().min(0).nullable().optional(),presence_penalty:z.number().min(-2).max(2).nullable().optional(),response_format:Pn.optional(),seed:z.number().nullable().optional(),stop:z.string().or(z.array(z.string()).max(4)).nullable().optional(),temperature:z.number().min(0).max(2).nullable().optional(),top_p:z.number().min(0).max(1).nullable().optional(),tools:z.array(On).optional(),tool_choice:Cn.or(bn).optional()});var yt=ce.omit({max_tokens:!0}).extend({max_completion_tokens:z.number().min(0).nullable().optional()});var vn="openai",B=class{constructor(){this.version="v1";this.name=vn;this.chatModelFactories={[no]:{model:fe,modelOptions:bt,modelSchema:so},[Ze]:{model:he,modelOptions:Ot,modelSchema:eo},[oo]:{model:ue,modelOptions:Ct,modelSchema:to},[ao]:{model:_e,modelOptions:Pt,modelSchema:io},[ro]:{model:Te,modelOptions:It,modelSchema:lo},[po]:{model:ge,modelOptions:St,modelSchema:mo},[co]:{model:ye,modelOptions:xt,modelSchema:ho},[uo]:{model:Me,modelOptions:At,modelSchema:fo},[_o]:{model:Oe,modelOptions:Et,modelSchema:To},[go]:{model:Ce,modelOptions:Rt,modelSchema:yo},[Co]:{model:Pe,modelOptions:Gt,modelSchema:bo},[So]:{model:Se,modelOptions:qt,modelSchema:xo},[Ao]:{model:xe,modelOptions:kt,modelSchema:Eo},[Po]:{model:Ie,modelOptions:vt,modelSchema:Io},[Mo]:{model:be,modelOptions:wt,modelSchema:Oo},[qo]:{model:Re,modelOptions:Bt,modelSchema:ko},[Lo]:{model:we,modelOptions:jt,modelSchema:zo},[Bo]:{model:Ge,modelOptions:Ft,modelSchema:jo},[Ro]:{model:Ae,modelOptions:Lt,modelSchema:wo},[Go]:{model:Ee,modelOptions:zt,modelSchema:vo}};this.embeddingModelFactories={[Fo]:{model:ve,modelOptions:Dt,modelSchema:Do},[No]:{model:qe,modelOptions:Nt,modelSchema:$o},[Uo]:{model:ke,modelOptions:$t,modelSchema:Ho}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new ProviderError({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
5
+ var Xt=Object.defineProperty,Zt=Object.defineProperties;var en=Object.getOwnPropertyDescriptors;var Qo=Object.getOwnPropertySymbols;var on=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable;var nn=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n);var Xo=(n,e,t)=>e in n?Xt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,M=(n,e)=>{for(var t in e||(e={}))on.call(e,t)&&Xo(n,t,e[t]);if(Qo)for(var t of Qo(e))tn.call(e,t)&&Xo(n,t,e[t]);return n},v=(n,e)=>Zt(n,en(e));var A=(n,e,t)=>new Promise((o,s)=>{var a=l=>{try{i(t.next(l));}catch(h){s(h);}},d=l=>{try{i(t.throw(l));}catch(h){s(h);}},i=l=>l.done?o(l.value):Promise.resolve(l.value).then(a,d);i((t=t.apply(n,e)).next());}),sn=function(n,e){this[0]=n,this[1]=e;},te=(n,e,t)=>{var o=(d,i,l,h)=>{try{var c=t[d](i),O=(i=c.value)instanceof sn,g=c.done;Promise.resolve(O?i[0]:i).then(y=>O?o(d==="return"?d:"next",i[1]?{done:y.done,value:y.value}:y,l,h):l({value:y,done:g})).catch(y=>o("throw",y,l,h));}catch(y){h(y);}},s=d=>a[d]=i=>new Promise((l,h)=>o(d,i,l,h)),a={};return t=t.apply(n,e),a[nn("asyncIterator")]=()=>a,s("next"),s("throw"),s("return"),a};var je=RangeConfigItem({param:"temperature",title:CHAT_CONFIG.TEMPERATURE.title,description:CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),De=n=>RangeConfigItem({param:"max_completion_tokens",title:CHAT_CONFIG.MAX_TOKENS.title,description:CHAT_CONFIG.MAX_TOKENS.description,min:0,max:n,step:1,default:0}),Fe=n=>MultiStringConfigItem({param:"stop",title:CHAT_CONFIG.STOP(n).title,description:CHAT_CONFIG.STOP(n).description,max:n}),$e=RangeConfigItem({param:"top_p",title:CHAT_CONFIG.TOP_P.title,description:CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),Ne=RangeConfigItem({param:"frequency_penalty",title:CHAT_CONFIG.FREQUENCY_PENALTY.title,description:CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Ue=RangeConfigItem({param:"presence_penalty",title:CHAT_CONFIG.PRESENCE_PENALTY.title,description:CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),He=RangeConfigItem({param:"seed",title:CHAT_CONFIG.SEED.title,description:CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Ve=SelectBooleanConfigItem({param:"logprobs",title:CHAT_CONFIG.LOG_PROBS.title,description:CHAT_CONFIG.LOG_PROBS.description,default:!1}),Ke=RangeConfigItem({param:"top_logprobs",title:CHAT_CONFIG.TOP_LOG_PROBS.title,description:CHAT_CONFIG.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),Je=SelectStringConfigItem({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","required","none"]});var N=(n,e)=>z.object({temperature:je.schema,maxTokens:De(n).schema,stop:Fe(e).schema,topP:$e.schema,frequencyPenalty:Ne.schema,presencePenalty:Ue.schema,seed:He.schema.transform(t=>t===0?void 0:t),logProbs:Ve.schema,topLogProbs:Ke.schema,toolChoice:Je.schema}),U=(n,e)=>({temperature:je.def,maxTokens:De(n).def,stop:Fe(e).def,topP:$e.def,frequencyPenalty:Ne.def,presencePenalty:Ue.def,seed:He.def,logProbs:Ve.def,topLogProbs:Ke.def,toolChoice:Je.def});var Zo=ObjectSchemaConfigItem({param:"response_schema",title:CHAT_CONFIG.RESPONSE_SCHEMA.title,description:CHAT_CONFIG.RESPONSE_SCHEMA.description,objectSchema:ResponseSchema}),et=SelectStringConfigItem({param:"response_format",title:CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.title,description:CHAT_CONFIG.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),se=(n,e)=>v(M({},U(n,e)),{responseFormat:et.def,responseSchema:Zo.def}),ae=(n,e)=>N(n,e).extend({responseFormat:et.schema,responseSchema:Zo.schema});var tt=RangeConfigItem({param:"temperature",title:CHAT_CONFIG.TEMPERATURE.title,description:CHAT_CONFIG.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),nt=(n,e)=>v(M({},se(n,e)),{temperature:tt.def}),st=(n,e)=>ae(n,e).extend({temperature:tt.schema});var it=SelectStringConfigItem({param:"response_format",title:CHAT_CONFIG.RESPONSE_FORMAT.title,description:CHAT_CONFIG.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),rt=(n,e)=>v(M({},U(n,e)),{responseFormat:it.def}),lt=(n,e)=>N(n,e).extend({responseFormat:it.schema});var We=SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),Ye=n=>RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:n,step:1,default:n});var ie=()=>z.object({encodingFormat:We.schema}),re=()=>({encodingFormat:We.def});var pt=n=>ie().extend({dimensions:Ye(n).schema}),mt=n=>v(M({},re()),{dimensions:Ye(n).def});var m={base:(n,e)=>({def:U(n,e),schema:N(n,e)}),responseFormat:(n,e)=>({def:rt(n,e),schema:lt(n,e)}),responseSchema:(n,e)=>({def:se(n,e),schema:ae(n,e)}),oSeries:(n,e)=>({def:nt(n,e),schema:st(n,e)})},k={base:()=>({def:re(),schema:ie()}),dimensions:n=>({def:mt(n),schema:pt(n)})};var gn="openai",D=class{constructor(){this.version="v1";this.name=gn;this.chatModelFactories={[oo]:{model:me,modelOptions:ut,modelSchema:to},[Qe]:{model:le,modelOptions:ct,modelSchema:Xe},[Ze]:{model:pe,modelOptions:ht,modelSchema:eo},[no]:{model:de,modelOptions:ft,modelSchema:so},[ao]:{model:ce,modelOptions:_t,modelSchema:io},[ro]:{model:he,modelOptions:Tt,modelSchema:lo},[po]:{model:ue,modelOptions:gt,modelSchema:mo},[co]:{model:fe,modelOptions:yt,modelSchema:ho},[uo]:{model:_e,modelOptions:Mt,modelSchema:fo},[_o]:{model:Te,modelOptions:Ot,modelSchema:To},[Mo]:{model:ye,modelOptions:bt,modelSchema:Oo},[Po]:{model:Oe,modelOptions:St,modelSchema:So},[Io]:{model:Ce,modelOptions:It,modelSchema:xo},[Co]:{model:Me,modelOptions:Pt,modelSchema:bo},[go]:{model:ge,modelOptions:Ct,modelSchema:yo},[Go]:{model:Se,modelOptions:Et,modelSchema:vo},[qo]:{model:Ie,modelOptions:Rt,modelSchema:ko},[Lo]:{model:xe,modelOptions:wt,modelSchema:zo},[Ao]:{model:be,modelOptions:xt,modelSchema:Eo},[Ro]:{model:Pe,modelOptions:At,modelSchema:wo}};this.embeddingModelFactories={[Bo]:{model:Ae,modelOptions:Gt,modelSchema:jo},[Do]:{model:Ee,modelOptions:vt,modelSchema:Fo},[$o]:{model:Re,modelOptions:qt,modelSchema:No}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new ProviderError({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
6
6
  [${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[t].model,s=this.chatModelFactories[t].modelOptions.parse(e);return new o(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}embeddingModel(e){let t=e.modelName;if(!(t in this.embeddingModelFactories))throw new ProviderError({info:`OpenAI embedding model: ${t} not found`,cause:new Error(`OpenAI embedding model: ${t} not found, available embedding models:
7
- [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};B.baseUrl="https://api.openai.com/v1";var u=z.object({modelName:z.string(),apiKey:z.string(),baseUrl:z.string().url().optional(),completeChatUrl:z.string().url().optional(),streamChatUrl:z.string().url().optional(),organization:z.string().optional()}),f=class{constructor(e,t){this.version="v1";let o=u.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=urlWithoutTrailingSlash(o.baseUrl||B.baseUrl),this.streamChatUrl=urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return M({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let t=i=>{let l=/(\d+)(h|m|s|ms)/g,h={h:36e5,m:6e4,s:1e3,ms:1},c,g=0;for(;(c=l.exec(i))!==null;){let y=parseInt(c[1]),O=c[2];g+=y*h[O];}return g},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let d=Math.max(o,s);return {shouldRetry:a,delayMs:d}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let t=ce.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let a={};o.response_format&&(a.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(a.responseSchema={name:o.response_format.json_schema.name,description:o.response_format.json_schema.description||"",strict:o.response_format.json_schema.strict,schema:o.response_format.json_schema.schema})),o.tool_choice&&(typeof o.tool_choice=="string"?a.toolChoice=o.tool_choice:a.toolChoice=o.tool_choice.function.name),a.seed=o.seed,a.maxTokens=o.max_tokens,a.temperature=o.temperature,a.topP=o.top_p,a.presencePenalty=o.presence_penalty,a.frequencyPenalty=o.frequency_penalty,a.stop=o.stop,a.logProbs=o.logprobs,a.topLogProbs=o.top_logprobs;let d=Config().parse(removeUndefinedEntries(a)),i=[],l={};o.messages.forEach(c=>{let g=c.role;switch(g){case"system":{let y=c.content;if(typeof y=="string")i.push({role:g,content:[{modality:TextModalityLiteral,value:y}]});else {let O=y.map(I=>({modality:TextModalityLiteral,value:I.text}));i.push({role:g,content:O});}}break;case"user":{let y=c.content;if(typeof y=="string")i.push({role:g,content:[{modality:TextModalityLiteral,value:y}]});else {let O=y.map(I=>I.type==="text"?{modality:TextModalityLiteral,value:I.text}:I.image_url.url.startsWith("data:")?{modality:ImageModalityLiteral,detail:I.image_url.detail||"auto",value:{type:Base64ImageContentTypeLiteral,base64:I.image_url.url,media_type:getMimeTypeFromBase64(I.image_url.url)}}:{modality:ImageModalityLiteral,detail:I.image_url.detail||"auto",value:{type:UrlImageContentTypeLiteral,url:I.image_url.url}});i.push({role:g,content:O});}}break;case"assistant":{let y=[];if(!c.content&&!c.tool_calls)throw new InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(c.content){let O=c.content;typeof O=="string"?y.push({modality:TextModalityLiteral,value:O}):O.forEach(I=>{y.push({modality:TextModalityLiteral,value:I.text});});}c.tool_calls&&c.tool_calls.forEach((I,Zt)=>{let Be={modality:ToolCallModalityLiteral,id:I.id,index:Zt,name:I.function.name,arguments:I.function.arguments};y.push(Be),l[Be.id]=Be;}),i.push({role:g,content:y});}break;case"tool":{let y=c;i.push({role:g,content:[{modality:ToolResponseModalityLiteral,id:y.tool_call_id,index:l[y.tool_call_id].index,name:l[y.tool_call_id].name,data:y.content}]});}break}});let h=[];return o.tools&&o.tools.forEach(c=>{h.push({type:"function",definition:{schema:{name:c.function.name,description:c.function.description||"",strict:c.function.strict,parameters:c.function.parameters}}});}),{modelName:s,config:d,messages:i,tools:h.length>0?h:void 0}}transformConfig(e,t,o){let s=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let d=a.data;s!==void 0&&(d.toolChoice=s),Object.keys(d).forEach(l=>{if(!(l in this.modelSchema.config.def))throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
8
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(d).reduce((l,h)=>{let c=this.modelSchema.config.def[h],g=c.param,y=d[h];return g==="max_tokens"&&c.type==="range"&&y===0?l[g]=c.max:l[g]=y,l},{});if(i.top_logprobs&&!i.logprobs)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in i&&i.tool_choice!==void 0){let l=i.tool_choice;if(!o||o&&o.length===0)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let h=this.modelSchema.config.def.toolChoice;if(!h.choices.includes(l))if(o.map(c=>c.definition.schema.name).includes(l))i.tool_choice={type:"function",function:{name:l}};else throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${l}' is not part of provided 'tools' names or
7
+ [${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};D.baseUrl="https://api.openai.com/v1";var _=z.enum([SystemRoleLiteral,UserRoleLiteral,AssistantRoleLiteral,ToolRoleLiteral]),T={system:SystemRoleLiteral,user:UserRoleLiteral,assistant:AssistantRoleLiteral,tool:ToolRoleLiteral},H=z.enum([UserRoleLiteral,AssistantRoleLiteral]),V={user:UserRoleLiteral,assistant:AssistantRoleLiteral};var P=[TextModalityLiteral,ImageModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral],S=z.enum([TextModalityLiteral,ImageModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral]),J=[TextModalityLiteral],W=z.enum([TextModalityLiteral]),I=[TextModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral],x=z.enum([TextModalityLiteral,ToolCallModalityLiteral,ToolResponseModalityLiteral]);var ke=z.object({token:z.string(),logprob:z.number(),bytes:z.array(z.number()).nullable()}),jt=z.object({content:z.array(ke.extend({top_logprobs:z.array(ke)})).nullable().optional(),refusal:z.array(ke.extend({top_logprobs:z.array(ke)})).nullable().optional()}).nullable(),yn=z.array(z.object({id:z.string().min(1),type:z.enum(["function"]),function:z.object({name:z.string(),arguments:z.string()})})),Dt=z.object({id:z.string(),object:z.literal("chat.completion"),created:z.number(),model:z.string(),system_fingerprint:z.string().nullable(),choices:z.array(z.object({index:z.number(),message:z.object({role:z.string(),content:z.string().nullable().optional(),tool_calls:yn.optional(),refusal:z.string().nullable().optional()}),logprobs:jt.optional(),finish_reason:z.string()})),usage:z.object({prompt_tokens:z.number(),completion_tokens:z.number(),total_tokens:z.number()})}),Mn=z.array(z.object({index:z.number().int(),id:z.string().min(1).optional(),type:z.enum(["function"]).optional(),function:z.object({name:z.string().min(1).optional(),arguments:z.string().optional()}).optional()})),Ft=z.object({id:z.string(),object:z.string(),created:z.number(),model:z.string(),system_fingerprint:z.string().nullable(),choices:z.array(z.object({index:z.number(),delta:z.object({content:z.string().nullable().optional(),tool_calls:Mn.optional(),refusal:z.string().nullable().optional()}).or(z.object({})),logprobs:jt,finish_reason:z.string().nullable()})),usage:z.object({prompt_tokens:z.number(),completion_tokens:z.number(),total_tokens:z.number()}).nullable().optional()});var On=z.object({type:z.literal("function"),function:z.object({name:z.string().min(1),description:z.string().min(1).optional(),strict:z.boolean().optional(),parameters:z.any()})}),Cn=z.enum(["none","auto","required"]),bn=z.object({type:z.literal("function"),function:z.object({name:z.string().min(1)})}),Pn=z.object({type:z.enum(["text","json_object"])}).or(z.object({type:z.literal("json_schema"),json_schema:z.object({name:z.string().min(1),description:z.string().min(1).optional(),strict:z.boolean().optional(),schema:z.any()})})),Ho=z.object({text:z.string().min(1),type:z.literal("text")}),Sn=z.object({type:z.literal("image_url"),image_url:z.object({url:z.string().url().min(1),detail:z.enum(["low","high","auto"]).optional()})}),In=z.object({id:z.string().min(1),type:z.literal("function"),function:z.object({name:z.string().min(1),arguments:z.string().min(1)})}),xn=z.object({role:z.literal("system"),content:z.string().min(1).or(z.array(Ho).min(1))}),An=z.object({role:z.literal("user"),content:z.string().min(1).or(z.array(z.union([Ho,Sn])).min(1))}),En=z.object({role:z.literal("assistant"),content:z.string().min(1).or(z.array(Ho).min(1)).optional(),tool_calls:z.array(In).min(1).optional()}),Rn=z.object({role:z.literal("tool"),tool_call_id:z.string().min(1),content:z.string().min(1)}),wn=z.union([xn,An,En,Rn]),Le=z.object({model:z.string().min(1).optional(),messages:z.array(wn).min(1),frequency_penalty:z.number().min(-2).max(2).nullable().optional(),logprobs:z.boolean().nullable().optional(),top_logprobs:z.number().min(0).max(20).nullable().optional(),max_completion_tokens:z.number().min(0).nullable().optional(),presence_penalty:z.number().min(-2).max(2).nullable().optional(),response_format:Pn.optional(),seed:z.number().nullable().optional(),stop:z.string().or(z.array(z.string()).max(4)).nullable().optional(),temperature:z.number().min(0).max(2).nullable().optional(),top_p:z.number().min(0).max(1).nullable().optional(),tools:z.array(On).optional(),tool_choice:Cn.or(bn).optional()});var $t=Le;var u=z.object({modelName:z.string(),apiKey:z.string(),baseUrl:z.string().url().optional(),completeChatUrl:z.string().url().optional(),streamChatUrl:z.string().url().optional(),organization:z.string().optional()}),f=class{constructor(e,t){this.version="v1";let o=u.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=urlWithoutTrailingSlash(o.baseUrl||D.baseUrl),this.streamChatUrl=urlWithoutTrailingSlash(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=urlWithoutTrailingSlash(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return M({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let t=i=>{let l=/(\d+)(h|m|s|ms)/g,h={h:36e5,m:6e4,s:1e3,ms:1},c,O=0;for(;(c=l.exec(i))!==null;){let g=parseInt(c[1]),y=c[2];O+=g*h[y];}return O},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let d=Math.max(o,s);return {shouldRetry:a,delayMs:d}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let t=Le.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let a={};o.response_format&&(a.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(a.responseSchema={name:o.response_format.json_schema.name,description:o.response_format.json_schema.description||"",strict:o.response_format.json_schema.strict,schema:o.response_format.json_schema.schema})),o.tool_choice&&(typeof o.tool_choice=="string"?a.toolChoice=o.tool_choice:a.toolChoice=o.tool_choice.function.name),a.seed=o.seed,a.maxTokens=o.max_completion_tokens,a.temperature=o.temperature,a.topP=o.top_p,a.presencePenalty=o.presence_penalty,a.frequencyPenalty=o.frequency_penalty,a.stop=o.stop,a.logProbs=o.logprobs,a.topLogProbs=o.top_logprobs;let d=Config().parse(removeUndefinedEntries(a)),i=[],l={};o.messages.forEach(c=>{let O=c.role;switch(O){case"system":{let g=c.content;if(typeof g=="string")i.push({role:O,content:[{modality:TextModalityLiteral,value:g}]});else {let y=g.map(C=>({modality:TextModalityLiteral,value:C.text}));i.push({role:O,content:y});}}break;case"user":{let g=c.content;if(typeof g=="string")i.push({role:O,content:[{modality:TextModalityLiteral,value:g}]});else {let y=g.map(C=>C.type==="text"?{modality:TextModalityLiteral,value:C.text}:C.image_url.url.startsWith("data:")?{modality:ImageModalityLiteral,detail:C.image_url.detail||"auto",value:{type:Base64ImageContentTypeLiteral,base64:C.image_url.url,media_type:getMimeTypeFromBase64(C.image_url.url)}}:{modality:ImageModalityLiteral,detail:C.image_url.detail||"auto",value:{type:UrlImageContentTypeLiteral,url:C.image_url.url}});i.push({role:O,content:y});}}break;case"assistant":{let g=[];if(!c.content&&!c.tool_calls)throw new InvalidModelRequestError({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(c.content){let y=c.content;typeof y=="string"?g.push({modality:TextModalityLiteral,value:y}):y.forEach(C=>{g.push({modality:TextModalityLiteral,value:C.text});});}c.tool_calls&&c.tool_calls.forEach((C,E)=>{let z={modality:ToolCallModalityLiteral,id:C.id,index:E,name:C.function.name,arguments:C.function.arguments};g.push(z),l[z.id]=z;}),i.push({role:O,content:g});}break;case"tool":{let g=c;i.push({role:O,content:[{modality:ToolResponseModalityLiteral,id:g.tool_call_id,index:l[g.tool_call_id].index,name:l[g.tool_call_id].name,data:g.content}]});}break}});let h=[];return o.tools&&o.tools.forEach(c=>{h.push({type:"function",definition:{schema:{name:c.function.name,description:c.function.description||"",strict:c.function.strict,parameters:c.function.parameters}}});}),{modelName:s,config:d,messages:i,tools:h.length>0?h:void 0}}transformConfig(e,t,o){let s=e.toolChoice;delete e.toolChoice;let a=this.modelSchema.config.schema.safeParse(e);if(!a.success)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:a.error});let d=a.data;s!==void 0&&(d.toolChoice=s),Object.keys(d).forEach(l=>{if(!(l in this.modelSchema.config.def))throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${l}',
8
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(d).reduce((l,h)=>{let c=this.modelSchema.config.def[h],O=c.param,g=d[h];return O==="max_completion_tokens"&&c.type==="range"&&g===0?l[O]=c.max:l[O]=g,l},{});if(i.top_logprobs&&!i.logprobs)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in i&&i.tool_choice!==void 0){let l=i.tool_choice;if(!o||o&&o.length===0)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let h=this.modelSchema.config.def.toolChoice;if(!h.choices.includes(l))if(o.map(c=>c.definition.schema.name).includes(l))i.tool_choice={type:"function",function:{name:l}};else throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${l}' is not part of provided 'tools' names or
9
9
  one of [${h.choices.join(", ")}]`)})}}if("response_format"in i&&i.response_format!==void 0){let l=i.response_format;if(l==="json_schema")if("response_schema"in i)i.response_format={type:"json_schema",json_schema:i.response_schema},delete i.response_schema;else throw new InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else i.response_format={type:l};}return i}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let t=e.map(s=>{let a=Message().safeParse(s);if(!a.success)throw new InvalidMessagesError({info:"Invalid messages",cause:a.error});return a.data});return t.forEach(s=>{s.content.forEach(a=>{if(!this.modelSchema.modalities.includes(a.modality))throw new InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${a.modality}',
10
10
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),t.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
11
11
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:t.map(s=>{switch(s.role){case SystemRoleLiteral:{let a=[];return s.content.forEach(d=>{if(d.modality===TextModalityLiteral)a.push({type:"text",text:d.value});else throw new InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:a}}case AssistantRoleLiteral:{let a=[],d=[];return s.content.forEach(i=>{if(i.modality===TextModalityLiteral)a.push({type:"text",text:i.value});else if(i.modality===ToolCallModalityLiteral)d.push({id:i.id,type:"function",function:{name:i.name,arguments:i.arguments}});else throw new InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${i.modality}'`)})}),M({role:this.modelSchema.roles[s.role],content:a},d.length>0?{tool_calls:d}:{})}case UserRoleLiteral:{let a=[],d=[];s.content.forEach(l=>{if(l.modality===TextModalityLiteral)a.push({type:"text",text:l.value});else if(l.modality===ImageModalityLiteral)d.push({type:"image_url",image_url:{url:l.value.type==="url"?l.value.url:l.value.base64,detail:l.detail}});else throw new InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${l.modality}'`)})});let i=[...a,...d];return {role:this.modelSchema.roles[s.role],content:i}}case ToolRoleLiteral:{if(s.content.length!==1)throw new InvalidMessagesError({info:`Invalid message for role : '${s.role}'`,cause:new Error(`role : '${s.role}' must have exactly one content item`)});if(s.content[0].modality!==ToolResponseModalityLiteral)throw new InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' must have content with modality : '${ToolResponseModalityLiteral}'`)});let a=s.content[0];return {role:this.modelSchema.roles[s.role],tool_call_id:a.id,content:a.data}}default:throw new InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
12
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(ToolCallModalityLiteral))throw new InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let a=Tool().safeParse(s);if(!a.success)throw new InvalidToolsError({info:"Invalid tools",cause:a.error});return a.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let d=o?this.transformTools(o):{};return new Promise(i=>{i(M(M(M(M({},this.getDefaultParams()),s),a),d));})})}transformCompleteChatResponse(e){let t=Tt.safeParse(e);if(t.success){if(t.data.choices.length===0)throw new ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,s=[{role:AssistantRoleLiteral,content:[]}],a=o.choices[0].message;a.content&&s[0].content.push(createTextContent(a.content)),a.refusal&&s[0].content.push(createTextContent(a.refusal)),a.tool_calls&&a.tool_calls.forEach((h,c)=>{s[0].content.push(createToolCallContent(c,h.id,h.function.name,h.function.arguments));});let d={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},i=[],l=o.choices[0].logprobs;return l&&(l.content&&i.push(...l.content.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))}))),l.refusal&&i.push(...l.refusal.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))})))),{messages:s,usage:d,logProbs:i}}throw new ModelResponseError({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let d=o?this.transformTools(o):{};return new Promise(i=>{i(M(M(M(M({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),a),d));})})}transformStreamChatResponseChunk(e,t){return ee(this,null,function*(){var s,a;let o=(t+e).split(`
13
- `).filter(d=>d.trim()!=="");for(let d of o){if(d==="data: [DONE]")return;if(d.startsWith("data: {")&&d.endsWith("}")){let i;try{i=JSON.parse(d.substring(6));}catch(h){throw new ModelResponseError({info:`Malformed JSON received in stream : ${i}`,cause:h})}let l=gt.safeParse(i);if(l.success){let h={partialMessages:[]},c=l.data;if(c.choices.length>0){let g=c.choices[0].delta;if(g!==void 0&&Object.keys(g).length!==0){if("content"in g&&g.content!==null)h.partialMessages.push(createPartialTextMessage(AssistantRoleLiteral,g.content));else if("refusal"in g&&g.refusal!==null)h.partialMessages.push(createPartialTextMessage(AssistantRoleLiteral,g.refusal));else if("tool_calls"in g&&g.tool_calls!==void 0){let y=g.tool_calls.at(0);h.partialMessages.push(createPartialToolCallMessage(AssistantRoleLiteral,y.index,y.id,(s=y.function)==null?void 0:s.name,(a=y.function)==null?void 0:a.arguments));}}}c.usage&&(h.usage={promptTokens:c.usage.prompt_tokens,completionTokens:c.usage.completion_tokens,totalTokens:c.usage.total_tokens}),yield {partialResponse:h,buffer:t};}else throw new ModelResponseError({info:"Invalid response from model",cause:l.error})}}})}};var v=class extends f{constructor(e,t){super(e,t);}transformModelRequest(e){let t=yt.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=G(M({},o),{max_tokens:o.max_completion_tokens});return delete s.max_completion_tokens,super.transformModelRequest(s)}transformTools(e){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support 'tools'.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support 'tools'.`)})}getStreamChatUrl(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}getStreamChatHeaders(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}getStreamChatData(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}transformStreamChatResponseChunk(e,t){return ee(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}};var Ze="gpt-3.5-turbo-0125",Jn="The latest GPT-3.5 Turbo model with higher accuracy at responding in requested formats and a fix for a bug which caused a text encoding issue for non-English language function calls. Training data up to Sept 2021.",eo=ChatModelSchema(_,x).parse({name:Ze,description:Jn,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),Ot=u,he=class extends f{constructor(e){super(eo,e);}};var oo="gpt-3.5-turbo-1106",Yn="The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. Training data up to Sept 2021.",to=ChatModelSchema(_,x).parse({name:oo,description:Yn,maxInputTokens:4092,maxOutputTokens:16385,roles:T,modalities:S,config:{def:m.responseFormat(16385,4).def,schema:m.responseFormat(16385,4).schema}}),Ct=u,ue=class extends f{constructor(e){super(to,e);}};var no="gpt-3.5-turbo",Qn="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",so=ChatModelSchema(_,x).parse({name:no,description:Qn,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),bt=u,fe=class extends f{constructor(e){super(so,e);}};var ao="gpt-4-0125-preview",es="The latest GPT-4 model intended to reduce cases of \u201Claziness\u201D where the model doesn\u2019t complete a task. Training data up to Apr 2023.",io=ChatModelSchema(_,x).parse({name:ao,description:es,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),Pt=u,_e=class extends f{constructor(e){super(io,e);}};var ro="gpt-4-0613",ts="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",lo=ChatModelSchema(_,x).parse({name:ro,description:ts,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),It=u,Te=class extends f{constructor(e){super(lo,e);}};var po="gpt-4-1106-preview",ss="GPT-4 Turbo model featuring improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. This preview model is not yet suited for production traffic. Training data up to Apr 2023.",mo=ChatModelSchema(_,x).parse({name:po,description:ss,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),St=u,ge=class extends f{constructor(e){super(mo,e);}};var co="gpt-4-turbo-2024-04-09",is="GPT-4 Turbo with Vision model. Vision requests can now use JSON mode and function calling. gpt-4-turbo currently points to this version. Training data up to Dec 2023.",ho=ChatModelSchema(_,P).parse({name:co,description:is,maxInputTokens:128e3,maxOutputTokens:4096,roles:T,modalities:b,config:{def:m.responseFormat(4096,4).def,schema:m.responseFormat(4096,4).schema}}),xt=u,ye=class extends f{constructor(e){super(ho,e);}};var uo="gpt-4-turbo-preview",ls="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",fo=ChatModelSchema(_,x).parse({name:uo,description:ls,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),At=u,Me=class extends f{constructor(e){super(fo,e);}};var _o="gpt-4-turbo",ms="The latest GPT-4 Turbo model with vision capabilities. Vision requests can now use JSON mode and function calling. Currently points to gpt-4-turbo-2024-04-09. Training data up to Dec 2023.",To=ChatModelSchema(_,P).parse({name:_o,description:ms,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),Et=u,Oe=class extends f{constructor(e){super(To,e);}};var go="gpt-4",cs="Currently points to gpt-4-0613. Training data up to Sept 2021.",yo=ChatModelSchema(_,x).parse({name:go,description:cs,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:S,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),Rt=u,Ce=class extends f{constructor(e){super(yo,e);}};var Mo="gpt-4o-2024-05-13",us="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Oo=ChatModelSchema(_,P).parse({name:Mo,description:us,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),wt=u,be=class extends f{constructor(e){super(Oo,e);}};var Co="gpt-4o-2024-08-06",_s="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",bo=ChatModelSchema(_,P).parse({name:Co,description:_s,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),Gt=u,Pe=class extends f{constructor(e){super(bo,e);}};var Po="gpt-4o-mini-2024-07-18",gs="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Io=ChatModelSchema(_,P).parse({name:Po,description:gs,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),vt=u,Ie=class extends f{constructor(e){super(Io,e);}};var So="gpt-4o-mini",Ms="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",xo=ChatModelSchema(_,P).parse({name:So,description:Ms,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),qt=u,Se=class extends f{constructor(e){super(xo,e);}};var Ao="gpt-4o",Cs="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",Eo=ChatModelSchema(_,P).parse({name:Ao,description:Cs,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:b,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),kt=u,xe=class extends f{constructor(e){super(Eo,e);}};var Ro="o1-2024-12-17",Ps="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",wo=ChatModelSchema(_,P).parse({name:Ro,description:Ps,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:b,config:{def:m.responseFormat(1e5,4).def,schema:m.responseFormat(1e5,4).schema}}),Lt=u,Ae=class extends f{constructor(e){super(wo,e);}};var Go="o1-mini-2024-09-12",Ss="Enhanced version of o1-mini optimized for faster reasoning in coding, math, and science. Training data up to September 2024.",vo=ChatModelSchema($,K).parse({name:Go,description:Ss,maxInputTokens:128e3,maxOutputTokens:65536,roles:U,modalities:V,config:{def:m.oSeries(65536,4).def,schema:m.oSeries(65536,4).schema}}),zt=u,Ee=class extends v{constructor(e){super(vo,e);}};var qo="o1-mini",As="Faster and cheaper reasoning model particularly good at coding, math, and science. Training data up to Oct 2023.",ko=ChatModelSchema($,K).parse({name:qo,description:As,maxInputTokens:128e3,maxOutputTokens:4092,roles:U,modalities:V,config:{def:m.oSeries(4092,4).def,schema:m.oSeries(4092,4).schema}}),Bt=u,Re=class extends v{constructor(e){super(ko,e);}};var Lo="o1-preview",Rs="Reasoning model designed to solve hard problems across domains. Training data up to Oct 2023.",zo=ChatModelSchema($,K).parse({name:Lo,description:Rs,maxInputTokens:128e3,maxOutputTokens:4092,roles:U,modalities:V,config:{def:m.oSeries(4092,4).def,schema:m.oSeries(4092,4).schema}}),jt=u,we=class extends v{constructor(e){super(zo,e);}};var Bo="o1",Gs="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",jo=ChatModelSchema(_,P).parse({name:Bo,description:Gs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:b,config:{def:m.oSeries(1e5,4).def,schema:m.oSeries(1e5,4).schema}}),Ft=u,Ge=class extends v{constructor(e){super(jo,e);}};var W=[EmbeddingTextModalityLiteral,EmbeddingTokenModalityLiteral],Y=z.enum([EmbeddingTextModalityLiteral,EmbeddingTokenModalityLiteral]);var Wt=z.object({object:z.literal("list"),model:z.string(),data:z.array(z.object({index:z.number(),object:z.literal("embedding"),embedding:z.array(z.number()).or(z.string().base64())})),usage:z.object({prompt_tokens:z.number().nonnegative(),total_tokens:z.number().nonnegative()})});var qs=z.string().min(1).or(z.array(z.string().min(1)).min(1)).or(z.array(z.number().int().nonnegative()).min(1)).or(z.array(z.array(z.number().int().nonnegative()).min(1)).min(1)),Yt=z.object({model:z.string().min(1).optional(),input:qs,encoding_format:z.enum(["float","base64"]).optional(),dimensions:z.number().int().min(1).optional()});var F=z.object({modelName:z.string(),apiKey:z.string(),baseUrl:z.string().url().optional(),getEmbeddingsUrl:z.string().url().optional()}),L=class{constructor(e,t){this.version="v1";let o=F.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=urlWithoutTrailingSlash(o.baseUrl||B.baseUrl),this.getEmbeddingsUrl=urlWithoutTrailingSlash(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let t=i=>{let l=/(\d+)(h|m|s|ms)/g,h={h:36e5,m:6e4,s:1e3,ms:1},c,g=0;for(;(c=l.exec(i))!==null;){let y=parseInt(c[1]),O=c[2];g+=y*h[O];}return g},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let d=Math.max(o,s);return {shouldRetry:a,delayMs:d}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=Yt.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model,a={encodingFormat:o.encoding_format,dimensions:o.dimensions},d=Config().parse(removeUndefinedEntries(a)),i,l;return typeof o.input=="string"?l=EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?l=EmbeddingTextModalityLiteral:l=EmbeddingTokenModalityLiteral,l===EmbeddingTextModalityLiteral?typeof o.input=="string"?i={modality:l,requests:[o.input]}:i={modality:l,requests:o.input}:typeof o.input[0]=="number"?i={modality:l,requests:[o.input]}:i={modality:l,requests:o.input},{modelName:s,config:d,embeddingRequests:i}}transformConfig(e,t){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(d=>{if(!this.modelSchema.config.def[d])throw new InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${d}',
14
- available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((d,i)=>{let h=this.modelSchema.config.def[i].param,c=s[i];return d[h]=c,d},{})}transformEmbeddingRequests(e){let t=EmbeddingRequests().safeParse(e);if(!t.success)throw new InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:t.error});return {input:t.data.requests}}getGetEmbeddingsUrl(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return A(this,null,function*(){return new Promise(o=>{o(M(M(M({},this.getDefaultParams()),this.transformConfig(e,t)),this.transformEmbeddingRequests(t)));})})}transformGetEmbeddingsResponse(e){let t,o=Wt.safeParse(e);if(o.success){let s=o.data;t=typeof s.data[0].embedding=="string"?Base64EmbeddingLiteral:FloatEmbeddingLiteral;let a=s.data.map(d=>typeof d.embedding=="string"?{index:d.index,embedding:d.embedding}:{index:d.index,embedding:d.embedding});return {encodingFormat:t,embeddings:a,usage:{totalTokens:s.usage.total_tokens}}}throw new ModelResponseError({info:"Invalid response from model",cause:o.error})}};var Fo="text-embedding-ada-002",Hs="Most capable 2nd generation embedding model, replacing 16 first generation models",Do=EmbeddingModelSchema(Y).parse({name:Fo,description:Hs,modalities:W,maxInputTokens:8192,maxOutputTokens:1536,config:{def:q.base().def,schema:q.base().schema}}),Dt=F,ve=class extends L{constructor(e){super(Do,e);}};var No="text-embedding-3-small",Ks="Increased performance over 2nd generation ada embedding model",$o=EmbeddingModelSchema(Y).parse({name:No,description:Ks,modalities:W,maxInputTokens:8192,maxOutputTokens:1536,config:{def:q.dimensions(1536).def,schema:q.dimensions(1536).schema}}),Nt=F,qe=class extends L{constructor(e){super($o,e);}};var Uo="text-embedding-3-large",Ws="Most capable embedding model for both english and non-english tasks",Ho=EmbeddingModelSchema(Y).parse({name:Uo,description:Ws,modalities:W,maxInputTokens:8192,maxOutputTokens:3072,config:{def:q.dimensions(3072).def,schema:q.dimensions(3072).schema}}),$t=F,ke=class extends L{constructor(e){super(Ho,e);}};
12
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(ToolCallModalityLiteral))throw new InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let a=Tool().safeParse(s);if(!a.success)throw new InvalidToolsError({info:"Invalid tools",cause:a.error});return a.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let d=o?this.transformTools(o):{};return new Promise(i=>{i(M(M(M(M({},this.getDefaultParams()),s),a),d));})})}transformCompleteChatResponse(e){let t=Dt.safeParse(e);if(t.success){if(t.data.choices.length===0)throw new ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(t.data)}`)});let o=t.data,s=[{role:AssistantRoleLiteral,content:[]}],a=o.choices[0].message;a.content&&s[0].content.push(createTextContent(a.content)),a.refusal&&s[0].content.push(createTextContent(a.refusal)),a.tool_calls&&a.tool_calls.forEach((h,c)=>{s[0].content.push(createToolCallContent(c,h.id,h.function.name,h.function.arguments));});let d={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},i=[],l=o.choices[0].logprobs;return l&&(l.content&&i.push(...l.content.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))}))),l.refusal&&i.push(...l.refusal.map(h=>({token:h.token,logProb:h.logprob,bytes:h.bytes,topLogProbs:h.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))})))),{messages:s,usage:d,logProbs:i}}throw new ModelResponseError({info:"Invalid response from model",cause:t.error})}getStreamChatUrl(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,t,o){return A(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,t,o){return A(this,null,function*(){let s=this.transformConfig(e,t,o),a=this.transformMessages(t);if(a.messages&&a.messages.length===0)throw new InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let d=o?this.transformTools(o):{};return new Promise(i=>{i(M(M(M(M({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),a),d));})})}transformStreamChatResponseChunk(e,t){return te(this,null,function*(){var i,l;let o=t+e,s=[],a="",d=0;for(;d<o.length;){let h=o.indexOf(`
13
+ `,d);if(h===-1){a=o.substring(d);break}else {let c=o.substring(d,h).trim();c&&s.push(c),d=h+1;}}for(let h of s){if(h==="data: [DONE]")return;if(h.startsWith("data: ")){let c=h.substring(6);try{let O=JSON.parse(c),g=Ft.safeParse(O);if(g.success){let y={partialMessages:[]},C=g.data;if(C.choices.length>0){let E=C.choices[0].delta;if(E!==void 0&&Object.keys(E).length!==0){if("content"in E&&E.content!==null)y.partialMessages.push(createPartialTextMessage(AssistantRoleLiteral,E.content));else if("refusal"in E&&E.refusal!==null)y.partialMessages.push(createPartialTextMessage(AssistantRoleLiteral,E.refusal));else if("tool_calls"in E&&E.tool_calls!==void 0){let z=E.tool_calls.at(0);y.partialMessages.push(createPartialToolCallMessage(AssistantRoleLiteral,z.index,z.id,(i=z.function)==null?void 0:i.name,(l=z.function)==null?void 0:l.arguments));}}}C.usage&&(y.usage={promptTokens:C.usage.prompt_tokens,completionTokens:C.usage.completion_tokens,totalTokens:C.usage.total_tokens}),yield {partialResponse:y,buffer:a};}else throw new ModelResponseError({info:"Invalid response from model",cause:g.error})}catch(O){throw new ModelResponseError({info:`Malformed JSON received in stream: ${c}`,cause:O})}}}yield {partialResponse:{partialMessages:[]},buffer:a};})}};var q=class extends f{constructor(e,t){super(e,t);}transformModelRequest(e){let t=$t.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=v(M({},o),{max_tokens:o.max_completion_tokens});return delete s.max_completion_tokens,super.transformModelRequest(s)}transformTools(e){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support 'tools'.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support 'tools'.`)})}getStreamChatUrl(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}getStreamChatHeaders(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}getStreamChatData(e,t,o){return A(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}transformStreamChatResponseChunk(e,t){return te(this,null,function*(){throw new ModelError({info:`Model: '${this.modelSchema.name}' does not support streaming.`,cause:new Error(`Model: '${this.modelSchema.name}' does not support streaming.`)})})}};var Qe="gpt-3.5-turbo-0125",Vn="The latest GPT-3.5 Turbo model with higher accuracy at responding in requested formats and a fix for a bug which caused a text encoding issue for non-English language function calls. Training data up to Sept 2021.",Xe=ChatModelSchema(_,x).parse({name:Qe,description:Vn,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),ct=u,le=class extends f{constructor(e){super(Xe,e);}};var Ze="gpt-3.5-turbo-1106",Jn="The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. Training data up to Sept 2021.",eo=ChatModelSchema(_,x).parse({name:Ze,description:Jn,maxInputTokens:4092,maxOutputTokens:16385,roles:T,modalities:I,config:{def:m.responseFormat(16385,4).def,schema:m.responseFormat(16385,4).schema}}),ht=u,pe=class extends f{constructor(e){super(eo,e);}};var oo="gpt-3.5-turbo",Yn="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",to=ChatModelSchema(_,x).parse({name:oo,description:Yn,maxInputTokens:4092,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),ut=u,me=class extends f{constructor(e){super(to,e);}};var no="gpt-4-0125-preview",Xn="The latest GPT-4 model intended to reduce cases of \u201Claziness\u201D where the model doesn\u2019t complete a task. Training data up to Apr 2023.",so=ChatModelSchema(_,x).parse({name:no,description:Xn,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),ft=u,de=class extends f{constructor(e){super(so,e);}};var ao="gpt-4-0613",es="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",io=ChatModelSchema(_,x).parse({name:ao,description:es,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),_t=u,ce=class extends f{constructor(e){super(io,e);}};var ro="gpt-4-1106-preview",ts="GPT-4 Turbo model featuring improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. Returns a maximum of 4,096 output tokens. This preview model is not yet suited for production traffic. Training data up to Apr 2023.",lo=ChatModelSchema(_,x).parse({name:ro,description:ts,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),Tt=u,he=class extends f{constructor(e){super(lo,e);}};var po="gpt-4-turbo-2024-04-09",ss="GPT-4 Turbo with Vision model. Vision requests can now use JSON mode and function calling. gpt-4-turbo currently points to this version. Training data up to Dec 2023.",mo=ChatModelSchema(_,S).parse({name:po,description:ss,maxInputTokens:128e3,maxOutputTokens:4096,roles:T,modalities:P,config:{def:m.responseFormat(4096,4).def,schema:m.responseFormat(4096,4).schema}}),gt=u,ue=class extends f{constructor(e){super(mo,e);}};var co="gpt-4-turbo-preview",is="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.",ho=ChatModelSchema(_,x).parse({name:co,description:is,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),yt=u,fe=class extends f{constructor(e){super(ho,e);}};var uo="gpt-4-turbo",ls="The latest GPT-4 Turbo model with vision capabilities. Vision requests can now use JSON mode and function calling. Currently points to gpt-4-turbo-2024-04-09. Training data up to Dec 2023.",fo=ChatModelSchema(_,S).parse({name:uo,description:ls,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseFormat(4092,4).def,schema:m.responseFormat(4092,4).schema}}),Mt=u,_e=class extends f{constructor(e){super(fo,e);}};var _o="gpt-4",ms="Currently points to gpt-4-0613. Training data up to Sept 2021.",To=ChatModelSchema(_,x).parse({name:_o,description:ms,maxInputTokens:8192,maxOutputTokens:4092,roles:T,modalities:I,config:{def:m.base(4092,4).def,schema:m.base(4092,4).schema}}),Ot=u,Te=class extends f{constructor(e){super(To,e);}};var go="gpt-4o-2024-05-13",cs="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",yo=ChatModelSchema(_,S).parse({name:go,description:cs,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),Ct=u,ge=class extends f{constructor(e){super(yo,e);}};var Mo="gpt-4o-2024-08-06",us="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Oo=ChatModelSchema(_,S).parse({name:Mo,description:us,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),bt=u,ye=class extends f{constructor(e){super(Oo,e);}};var Co="gpt-4o-mini-2024-07-18",_s="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",bo=ChatModelSchema(_,S).parse({name:Co,description:_s,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),Pt=u,Me=class extends f{constructor(e){super(bo,e);}};var Po="gpt-4o-mini",gs="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",So=ChatModelSchema(_,S).parse({name:Po,description:gs,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),St=u,Oe=class extends f{constructor(e){super(So,e);}};var Io="gpt-4o",Ms="Most advanced, multimodal flagship model that is cheaper and faster than GPT-4 Turbo. Currently points to gpt-4o-2024-05-13. Training data up to Oct 2023.",xo=ChatModelSchema(_,S).parse({name:Io,description:Ms,maxInputTokens:128e3,maxOutputTokens:4092,roles:T,modalities:P,config:{def:m.responseSchema(4092,4).def,schema:m.responseSchema(4092,4).schema}}),It=u,Ce=class extends f{constructor(e){super(xo,e);}};var Ao="o1-2024-12-17",Cs="A stable release model for production use, offering robust performance and advanced features. Training data up to December 2024.",Eo=ChatModelSchema(_,S).parse({name:Ao,description:Cs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:P,config:{def:m.oSeries(1e5,4).def,schema:m.oSeries(1e5,4).schema}}),xt=u,be=class extends f{constructor(e){super(Eo,e);}};var Ro="o1-mini-2024-09-12",Ps="Enhanced version of o1-mini optimized for faster reasoning in coding, math, and science. Training data up to September 2024.",wo=ChatModelSchema(H,W).parse({name:Ro,description:Ps,maxInputTokens:128e3,maxOutputTokens:65536,roles:V,modalities:J,config:{def:m.oSeries(65536,4).def,schema:m.oSeries(65536,4).schema}}),At=u,Pe=class extends q{constructor(e){super(wo,e);}};var Go="o1-mini",Is="Faster and cheaper reasoning model particularly good at coding, math, and science. Training data up to Oct 2023.",vo=ChatModelSchema(H,W).parse({name:Go,description:Is,maxInputTokens:128e3,maxOutputTokens:4092,roles:V,modalities:J,config:{def:m.oSeries(4092,4).def,schema:m.oSeries(4092,4).schema}}),Et=u,Se=class extends q{constructor(e){super(vo,e);}};var qo="o1-preview",As="Reasoning model designed to solve hard problems across domains. Training data up to Oct 2023.",ko=ChatModelSchema(H,W).parse({name:qo,description:As,maxInputTokens:128e3,maxOutputTokens:4092,roles:V,modalities:J,config:{def:m.oSeries(4092,4).def,schema:m.oSeries(4092,4).schema}}),Rt=u,Ie=class extends q{constructor(e){super(ko,e);}};var Lo="o1",Rs="Highly capable general-purpose reasoning model with advanced capabilities in language, coding, and reasoning. Training data up to Oct 2023.",zo=ChatModelSchema(_,S).parse({name:Lo,description:Rs,maxInputTokens:2e5,maxOutputTokens:1e5,roles:T,modalities:P,config:{def:m.oSeries(1e5,4).def,schema:m.oSeries(1e5,4).schema}}),wt=u,xe=class extends q{constructor(e){super(zo,e);}};var Q=[EmbeddingTextModalityLiteral,EmbeddingTokenModalityLiteral],X=z.enum([EmbeddingTextModalityLiteral,EmbeddingTokenModalityLiteral]);var Jt=z.object({object:z.literal("list"),model:z.string(),data:z.array(z.object({index:z.number(),object:z.literal("embedding"),embedding:z.array(z.number()).or(z.string().base64())})),usage:z.object({prompt_tokens:z.number().nonnegative(),total_tokens:z.number().nonnegative()})});var Gs=z.string().min(1).or(z.array(z.string().min(1)).min(1)).or(z.array(z.number().int().nonnegative()).min(1)).or(z.array(z.array(z.number().int().nonnegative()).min(1)).min(1)),Wt=z.object({model:z.string().min(1).optional(),input:Gs,encoding_format:z.enum(["float","base64"]).optional(),dimensions:z.number().int().min(1).optional()});var $=z.object({modelName:z.string(),apiKey:z.string(),baseUrl:z.string().url().optional(),getEmbeddingsUrl:z.string().url().optional()}),B=class{constructor(e,t){this.version="v1";let o=$.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=urlWithoutTrailingSlash(o.baseUrl||D.baseUrl),this.getEmbeddingsUrl=urlWithoutTrailingSlash(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let t=i=>{let l=/(\d+)(h|m|s|ms)/g,h={h:36e5,m:6e4,s:1e3,ms:1},c,O=0;for(;(c=l.exec(i))!==null;){let g=parseInt(c[1]),y=c[2];O+=g*h[y];}return O},o=0,s=0,a=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let d=Math.max(o,s);return {shouldRetry:a,delayMs:d}}getTokenCount(e){return e.requests.reduce((t,o)=>t+o.length,0)}transformModelRequest(e){let t=Wt.safeParse(e);if(!t.success)throw new InvalidModelRequestError({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model,a={encodingFormat:o.encoding_format,dimensions:o.dimensions},d=Config().parse(removeUndefinedEntries(a)),i,l;return typeof o.input=="string"?l=EmbeddingTextModalityLiteral:typeof o.input[0]=="string"?l=EmbeddingTextModalityLiteral:l=EmbeddingTokenModalityLiteral,l===EmbeddingTextModalityLiteral?typeof o.input=="string"?i={modality:l,requests:[o.input]}:i={modality:l,requests:o.input}:typeof o.input[0]=="number"?i={modality:l,requests:[o.input]}:i={modality:l,requests:o.input},{modelName:s,config:d,embeddingRequests:i}}transformConfig(e,t){let o=this.modelSchema.config.schema.safeParse(e);if(!o.success)throw new InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(d=>{if(!this.modelSchema.config.def[d])throw new InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${d}',
14
+ available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((d,i)=>{let h=this.modelSchema.config.def[i].param,c=s[i];return d[h]=c,d},{})}transformEmbeddingRequests(e){let t=EmbeddingRequests().safeParse(e);if(!t.success)throw new InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:t.error});return {input:t.data.requests}}getGetEmbeddingsUrl(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return A(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return A(this,null,function*(){return new Promise(o=>{o(M(M(M({},this.getDefaultParams()),this.transformConfig(e,t)),this.transformEmbeddingRequests(t)));})})}transformGetEmbeddingsResponse(e){let t,o=Jt.safeParse(e);if(o.success){let s=o.data;t=typeof s.data[0].embedding=="string"?Base64EmbeddingLiteral:FloatEmbeddingLiteral;let a=s.data.map(d=>typeof d.embedding=="string"?{index:d.index,embedding:d.embedding}:{index:d.index,embedding:d.embedding});return {encodingFormat:t,embeddings:a,usage:{totalTokens:s.usage.total_tokens}}}throw new ModelResponseError({info:"Invalid response from model",cause:o.error})}};var Bo="text-embedding-ada-002",Ns="Most capable 2nd generation embedding model, replacing 16 first generation models",jo=EmbeddingModelSchema(X).parse({name:Bo,description:Ns,modalities:Q,maxInputTokens:8192,maxOutputTokens:1536,config:{def:k.base().def,schema:k.base().schema}}),Gt=$,Ae=class extends B{constructor(e){super(jo,e);}};var Do="text-embedding-3-small",Hs="Increased performance over 2nd generation ada embedding model",Fo=EmbeddingModelSchema(X).parse({name:Do,description:Hs,modalities:Q,maxInputTokens:8192,maxOutputTokens:1536,config:{def:k.dimensions(1536).def,schema:k.dimensions(1536).schema}}),vt=$,Ee=class extends B{constructor(e){super(Fo,e);}};var $o="text-embedding-3-large",Ks="Most capable embedding model for both english and non-english tasks",No=EmbeddingModelSchema(X).parse({name:$o,description:Ks,modalities:Q,maxInputTokens:8192,maxOutputTokens:3072,config:{def:k.dimensions(3072).def,schema:k.dimensions(3072).schema}}),qt=$,Re=class extends B{constructor(e){super(No,e);}};
15
15
 
16
- export { f as BaseChatModel, u as BaseChatModelOptions, L as BaseEmbeddingModel, F as BaseEmbeddingModelOptions, v as BaseOSeriesChatModel, N as ChatModelBaseConfigDef, D as ChatModelBaseConfigSchema, st as ChatModelOSeriesConfigDef, at as ChatModelOSeriesConfigSchema, lt as ChatModelResponseFormatConfigDef, pt as ChatModelResponseFormatConfigSchema, te as ChatModelResponseSchemaConfigDef, ne as ChatModelResponseSchemaConfigSchema, ie as EmbeddingModelBaseConfigDef, ae as EmbeddingModelBaseConfigSchema, dt as EmbeddingModelDimensionsConfigDef, mt as EmbeddingModelDimensionsConfigSchema, fe as GPT_3_5_Turbo, no as GPT_3_5_TurboLiteral, bt as GPT_3_5_TurboOptions, so as GPT_3_5_TurboSchema, he as GPT_3_5_Turbo_0125, Ze as GPT_3_5_Turbo_0125Literal, Ot as GPT_3_5_Turbo_0125Options, eo as GPT_3_5_Turbo_0125Schema, ue as GPT_3_5_Turbo_1106, oo as GPT_3_5_Turbo_1106Literal, Ct as GPT_3_5_Turbo_1106Options, to as GPT_3_5_Turbo_1106Schema, Ce as GPT_4, go as GPT_4Literal, Rt as GPT_4Options, yo as GPT_4Schema, _e as GPT_4_0125_Preview, ao as GPT_4_0125_PreviewLiteral, Pt as GPT_4_0125_PreviewOptions, io as GPT_4_0125_PreviewSchema, Te as GPT_4_0613, ro as GPT_4_0613Literal, It as GPT_4_0613Options, lo as GPT_4_0613Schema, ge as GPT_4_1106_Preview, po as GPT_4_1106_PreviewLiteral, St as GPT_4_1106_PreviewOptions, mo as GPT_4_1106_PreviewSchema, Oe as GPT_4_Turbo, _o as GPT_4_TurboLiteral, Et as GPT_4_TurboOptions, To as GPT_4_TurboSchema, ye as GPT_4_Turbo_2024_04_09, co as GPT_4_Turbo_2024_04_09Literal, xt as GPT_4_Turbo_2024_04_09Options, ho as GPT_4_Turbo_2024_04_09Schema, Me as GPT_4_Turbo_Preview, uo as GPT_4_Turbo_PreviewLiteral, At as GPT_4_Turbo_PreviewOptions, fo as GPT_4_Turbo_PreviewSchema, xe as GPT_4o, Ao as GPT_4oLiteral, kt as GPT_4oOptions, Eo as GPT_4oSchema, be as GPT_4o_2024_05_13, Mo as GPT_4o_2024_05_13Literal, wt as GPT_4o_2024_05_13Options, Oo as GPT_4o_2024_05_13Schema, Pe as GPT_4o_2024_08_06, Co as GPT_4o_2024_08_06Literal, Gt as GPT_4o_2024_08_06Options, bo as GPT_4o_2024_08_06Schema, Se as GPT_4o_Mini, So as GPT_4o_MiniLiteral, qt as GPT_4o_MiniOptions, xo as GPT_4o_MiniSchema, Ie as GPT_4o_Mini_2024_07_18, Po as GPT_4o_Mini_2024_07_18Literal, vt as GPT_4o_Mini_2024_07_18Options, Io as GPT_4o_Mini_2024_07_18Schema, Ge as O1, Bo as O1Literal, Ft as O1Options, jo as O1Schema, Ae as O1_2024_12_17, Ro as O1_2024_12_17Literal, Lt as O1_2024_12_17Options, wo as O1_2024_12_17Schema, Re as O1_Mini, qo as O1_MiniLiteral, Bt as O1_MiniOptions, ko as O1_MiniSchema, Ee as O1_Mini_2024_09_12, Go as O1_Mini_2024_09_12Literal, zt as O1_Mini_2024_09_12Options, vo as O1_Mini_2024_09_12Schema, we as O1_Preview, Lo as O1_PreviewLiteral, jt as O1_PreviewOptions, zo as O1_PreviewSchema, B as OpenAI, m as OpenAIChatModelConfigs, b as OpenAIChatModelModalities, P as OpenAIChatModelModalitiesEnum, $ as OpenAIChatModelOSSeriesRoles, U as OpenAIChatModelOSSeriesRolesMap, _ as OpenAIChatModelRoles, T as OpenAIChatModelRolesMap, V as OpenAIChatModelTextModalities, K as OpenAIChatModelTextModalitiesEnum, S as OpenAIChatModelTextToolModalities, x as OpenAIChatModelTextToolModalitiesEnum, yt as OpenAIChatOSeriesRequest, ce as OpenAIChatRequest, En as OpenAIChatRequestAssistantMessage, In as OpenAIChatRequestImageContent, wn as OpenAIChatRequestMessage, Pn as OpenAIChatRequestResponseFormat, xn as OpenAIChatRequestSystemMessage, Qe as OpenAIChatRequestTextContent, On as OpenAIChatRequestTool, Sn as OpenAIChatRequestToolCallContent, Cn as OpenAIChatRequestToolChoiceEnum, bn as OpenAIChatRequestToolChoiceFunction, Rn as OpenAIChatRequestToolMessage, An as OpenAIChatRequestUserMessage, Tt as OpenAICompleteChatResponse, q as OpenAIEmbeddingModelConfigs, W as OpenAIEmbeddingModelModalities, Y as OpenAIEmbeddingModelModalitiesEnum, Yt as OpenAIEmbeddingRequest, qs as OpenAIEmbeddingRequestInput, Wt as OpenAIGetEmbeddingsResponse, gt as OpenAIStreamChatResponse, yn as OpenAIToolCallsCompleteChatResponse, Mn as OpenAIToolCallsStreamChatResponse, vn as ProviderLiteral, ke as Text_Embedding_3_Large, Uo as Text_Embedding_3_LargeLiteral, Ho as Text_Embedding_3_LargeSchema, $t as Text_Embedding_3_Large_Options, qe as Text_Embedding_3_Small, No as Text_Embedding_3_SmallLiteral, $o as Text_Embedding_3_SmallSchema, Nt as Text_Embedding_3_Small_Options, ve as Text_Embedding_Ada002, Fo as Text_Embedding_Ada002Literal, Do as Text_Embedding_Ada002Schema, Dt as Text_Embedding_Ada002_Options, Ye as dimensions, We as encodingFormat, $e as frequencyPenalty, Ve as logProbs, Fe as maxTokens, Ue as presencePenalty, He as seed, De as stop, je as temperature, Je as toolChoice, Ke as topLogProbs, Ne as topP };
16
+ export { f as BaseChatModel, u as BaseChatModelOptions, B as BaseEmbeddingModel, $ as BaseEmbeddingModelOptions, q as BaseOSeriesChatModel, U as ChatModelBaseConfigDef, N as ChatModelBaseConfigSchema, nt as ChatModelOSeriesConfigDef, st as ChatModelOSeriesConfigSchema, rt as ChatModelResponseFormatConfigDef, lt as ChatModelResponseFormatConfigSchema, se as ChatModelResponseSchemaConfigDef, ae as ChatModelResponseSchemaConfigSchema, re as EmbeddingModelBaseConfigDef, ie as EmbeddingModelBaseConfigSchema, mt as EmbeddingModelDimensionsConfigDef, pt as EmbeddingModelDimensionsConfigSchema, me as GPT_3_5_Turbo, oo as GPT_3_5_TurboLiteral, ut as GPT_3_5_TurboOptions, to as GPT_3_5_TurboSchema, le as GPT_3_5_Turbo_0125, Qe as GPT_3_5_Turbo_0125Literal, ct as GPT_3_5_Turbo_0125Options, Xe as GPT_3_5_Turbo_0125Schema, pe as GPT_3_5_Turbo_1106, Ze as GPT_3_5_Turbo_1106Literal, ht as GPT_3_5_Turbo_1106Options, eo as GPT_3_5_Turbo_1106Schema, Te as GPT_4, _o as GPT_4Literal, Ot as GPT_4Options, To as GPT_4Schema, de as GPT_4_0125_Preview, no as GPT_4_0125_PreviewLiteral, ft as GPT_4_0125_PreviewOptions, so as GPT_4_0125_PreviewSchema, ce as GPT_4_0613, ao as GPT_4_0613Literal, _t as GPT_4_0613Options, io as GPT_4_0613Schema, he as GPT_4_1106_Preview, ro as GPT_4_1106_PreviewLiteral, Tt as GPT_4_1106_PreviewOptions, lo as GPT_4_1106_PreviewSchema, _e as GPT_4_Turbo, uo as GPT_4_TurboLiteral, Mt as GPT_4_TurboOptions, fo as GPT_4_TurboSchema, ue as GPT_4_Turbo_2024_04_09, po as GPT_4_Turbo_2024_04_09Literal, gt as GPT_4_Turbo_2024_04_09Options, mo as GPT_4_Turbo_2024_04_09Schema, fe as GPT_4_Turbo_Preview, co as GPT_4_Turbo_PreviewLiteral, yt as GPT_4_Turbo_PreviewOptions, ho as GPT_4_Turbo_PreviewSchema, Ce as GPT_4o, Io as GPT_4oLiteral, It as GPT_4oOptions, xo as GPT_4oSchema, ge as GPT_4o_2024_05_13, go as GPT_4o_2024_05_13Literal, Ct as GPT_4o_2024_05_13Options, yo as GPT_4o_2024_05_13Schema, ye as GPT_4o_2024_08_06, Mo as GPT_4o_2024_08_06Literal, bt as GPT_4o_2024_08_06Options, Oo as GPT_4o_2024_08_06Schema, Oe as GPT_4o_Mini, Po as GPT_4o_MiniLiteral, St as GPT_4o_MiniOptions, So as GPT_4o_MiniSchema, Me as GPT_4o_Mini_2024_07_18, Co as GPT_4o_Mini_2024_07_18Literal, Pt as GPT_4o_Mini_2024_07_18Options, bo as GPT_4o_Mini_2024_07_18Schema, xe as O1, Lo as O1Literal, wt as O1Options, zo as O1Schema, be as O1_2024_12_17, Ao as O1_2024_12_17Literal, xt as O1_2024_12_17Options, Eo as O1_2024_12_17Schema, Se as O1_Mini, Go as O1_MiniLiteral, Et as O1_MiniOptions, vo as O1_MiniSchema, Pe as O1_Mini_2024_09_12, Ro as O1_Mini_2024_09_12Literal, At as O1_Mini_2024_09_12Options, wo as O1_Mini_2024_09_12Schema, Ie as O1_Preview, qo as O1_PreviewLiteral, Rt as O1_PreviewOptions, ko as O1_PreviewSchema, D as OpenAI, m as OpenAIChatModelConfigs, P as OpenAIChatModelModalities, S as OpenAIChatModelModalitiesEnum, H as OpenAIChatModelOSSeriesRoles, V as OpenAIChatModelOSSeriesRolesMap, _ as OpenAIChatModelRoles, T as OpenAIChatModelRolesMap, J as OpenAIChatModelTextModalities, W as OpenAIChatModelTextModalitiesEnum, I as OpenAIChatModelTextToolModalities, x as OpenAIChatModelTextToolModalitiesEnum, $t as OpenAIChatOSeriesRequest, Le as OpenAIChatRequest, En as OpenAIChatRequestAssistantMessage, Sn as OpenAIChatRequestImageContent, wn as OpenAIChatRequestMessage, Pn as OpenAIChatRequestResponseFormat, xn as OpenAIChatRequestSystemMessage, Ho as OpenAIChatRequestTextContent, On as OpenAIChatRequestTool, In as OpenAIChatRequestToolCallContent, Cn as OpenAIChatRequestToolChoiceEnum, bn as OpenAIChatRequestToolChoiceFunction, Rn as OpenAIChatRequestToolMessage, An as OpenAIChatRequestUserMessage, Dt as OpenAICompleteChatResponse, k as OpenAIEmbeddingModelConfigs, Q as OpenAIEmbeddingModelModalities, X as OpenAIEmbeddingModelModalitiesEnum, Wt as OpenAIEmbeddingRequest, Gs as OpenAIEmbeddingRequestInput, Jt as OpenAIGetEmbeddingsResponse, Ft as OpenAIStreamChatResponse, yn as OpenAIToolCallsCompleteChatResponse, Mn as OpenAIToolCallsStreamChatResponse, gn as ProviderLiteral, Re as Text_Embedding_3_Large, $o as Text_Embedding_3_LargeLiteral, No as Text_Embedding_3_LargeSchema, qt as Text_Embedding_3_Large_Options, Ee as Text_Embedding_3_Small, Do as Text_Embedding_3_SmallLiteral, Fo as Text_Embedding_3_SmallSchema, vt as Text_Embedding_3_Small_Options, Ae as Text_Embedding_Ada002, Bo as Text_Embedding_Ada002Literal, jo as Text_Embedding_Ada002Schema, Gt as Text_Embedding_Ada002_Options, Ye as dimensions, We as encodingFormat, Ne as frequencyPenalty, Ve as logProbs, De as maxTokens, Ue as presencePenalty, He as seed, Fe as stop, je as temperature, Je as toolChoice, Ke as topLogProbs, $e as topP };
17
17
  //# sourceMappingURL=index.mjs.map
18
18
  //# sourceMappingURL=index.mjs.map