@adaline/azure 0.3.0 → 0.4.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.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +40 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,81 +2,80 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
var Ma=Object.defineProperty;var mt=Object.getOwnPropertySymbols;var Ea=Object.prototype.hasOwnProperty,Ca=Object.prototype.propertyIsEnumerable;var dt=(t,e,o)=>e in t?Ma(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,
|
|
6
|
-
Message: ${Ga(o)}`),this.name=ve,this.info=e,this.cause=o,this.name=s!=null?s:ve,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof ht}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},W="system",U="user",M="assistant",Y="tool",Ia=[W,U,M,Y],xe=zod.z.enum(Ia),ja=[M],Aa=zod.z.enum(ja),k="image",Me="base64",ka=["png","jpeg","webp","gif"],La=zod.z.object({type:zod.z.literal(Me),base64:zod.z.string(),media_type:zod.z.enum(ka)}),Ee="url",Ra=zod.z.object({type:zod.z.literal(Ee),url:zod.z.string()}),za=zod.z.discriminatedUnion("type",[La,Ra]),$a=["low","medium","high","auto"],Fa=zod.z.enum($a),Ua=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(k),detail:Fa,value:za,metadata:t}),y="text",_t=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(y),value:zod.z.string(),metadata:t}),Ce="partial-text",gt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ce),value:zod.z.string(),metadata:t}),E="tool-call",ft=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(E),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),we="partial-tool-call",bt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(we),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),G="tool-response",qa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),Na=[y,k,E,G],Tt=zod.z.enum(Na),Ba=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_t(t),Ua(e),ft(o),qa(s)]),Da=[Ce,we];zod.z.enum(Da);var Ka=(t=zod.z.undefined(),e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[gt(t),bt(e)]);var Z=(t=xe,e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Ba(e,o,s,i)),metadata:m}),Ge=(t=Aa,e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ka(e,o),metadata:s});var Ie=(t,e)=>Z().parse({role:t,content:[_t().parse({modality:y,value:e})]});var yt=(t,e,o,s,i)=>Z().parse({role:t,content:[ft().parse({modality:E,index:e,id:o,name:s,arguments:i})]});var je=(t,e)=>Ge().parse({role:t,partialContent:gt().parse({modality:Ce,value:e})}),Ot=(t,e,o,s,i)=>Ge().parse({role:t,partialContent:bt().parse({modality:we,index:e,id:o,name:s,arguments:i})});var Ae=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,Ha=["object","array","number","string","boolean","enum"],pt=zod.z.enum(Ha),Va=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([pt,zod.z.array(zod.z.union([pt,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),Ja=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Va),additionalProperties:zod.z.literal(!1)}),Pt=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:Ja}).optional(),Wa="function";var Ya=zod.z.enum(["object","array","number","string","boolean","null"]),Za=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ya.optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Za).optional(),required:zod.z.array(zod.z.string()).optional()});var Xa=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var Qa=zod.z.enum(["function"]),en=zod.z.object({type:Qa,definition:zod.z.object({schema:Xa})}),tn=[Wa];zod.z.enum(tn);var St=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[en.extend({metadata:t})]),L="text",D="token",on=[L,D],vt=zod.z.enum(on),an=zod.z.array(zod.z.string().min(1)),nn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),xt=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(L),metadata:t,requests:an}),zod.z.object({modality:zod.z.literal(D),metadata:t,requests:nn})]),ke="float",sn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Le="base64",rn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ct=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(ke),embeddings:zod.z.array(sn),usage:ct.optional()}),zod.z.object({encodingFormat:zod.z.literal(Le),embeddings:zod.z.array(rn),usage:ct.optional()})]);var Mt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ut=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),ln=ut.extend({topLogProbs:zod.z.array(ut)}),Et=zod.z.array(ln);zod.z.object({messages:zod.z.array(Z()),usage:Mt.optional(),logProbs:Et.optional()});zod.z.object({partialMessages:zod.z.array(Ge()),usage:Mt.optional(),logProbs:Et.optional()});var mn=Object.defineProperty,Ct=Object.getOwnPropertySymbols,dn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,wt=(t,e,o)=>e in t?mn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,X=(t,e)=>{for(var o in e||(e={}))dn.call(e,o)&&wt(t,o,e[o]);if(Ct)for(var o of Ct(e))pn.call(e,o)&&wt(t,o,e[o]);return t},Gt="ProviderError",K=class $t extends I{constructor({info:e,cause:o}){super({info:e,cause:o},Gt),this.name=Gt,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof $t}},It="ModelError",Q=class Ft extends I{constructor({info:e,cause:o}){super({info:e,cause:o},It),this.name=It,this.info=e,this.cause=o;}static isModelError(e){return e instanceof Ft}},jt="ModelResponseError",H=class Ut extends I{constructor({info:e,cause:o}){super({info:e,cause:o},jt),this.name=jt,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof Ut}},At="InvalidModelRequestError",ee=class qt extends I{constructor({info:e,cause:o}){super({info:e,cause:o},At),this.name=At,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof qt}},kt="InvalidConfigError",j=class Nt extends I{constructor({info:e,cause:o}){super({info:e,cause:o},kt),this.name=kt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof Nt}},Lt="InvalidMessagesError",C=class Bt extends I{constructor({info:e,cause:o}){super({info:e,cause:o},Lt),this.name=Lt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof Bt}},Rt="InvalidToolsError",Re=class Dt extends I{constructor({info:e,cause:o}){super({info:e,cause:o},Rt),this.name=Rt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof Dt}},zt="InvalidEmbeddingRequestsError",Kt=class Ht extends I{constructor({info:e,cause:o}){super({info:e,cause:o},zt),this.name=zt,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof Ht}},ze="multi-string",Vt=zod.z.object({type:zod.z.literal(ze),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),cn=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Jt=t=>({def:Vt.parse(X({type:ze},t)),schema:cn(t.max)}),$e="range",Wt=zod.z.object({type:zod.z.literal($e),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),un=(t,e,o,s)=>zod.z.number().min(t).max(e).step(o).default(s).optional(),w=t=>({def:Wt.parse(X({type:$e},t)),schema:un(t.min,t.max,t.step,t.default)}),Fe="select-string",Yt=zod.z.object({type:zod.z.literal(Fe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),hn=(t,e)=>zod.z.enum(e).nullable().default(t).optional(),te=t=>({def:Yt.parse(X({type:Fe},t)),schema:hn(t.default,t.choices)}),Ue="object-schema",Zt=zod.z.object({type:zod.z.literal(Ue),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),_n=t=>t.optional(),Xt=t=>({def:Zt.parse(X({type:Ue},t)),schema:_n(t.objectSchema)}),qe="select-boolean",Qt=zod.z.object({type:zod.z.literal(qe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),gn=t=>zod.z.boolean().nullable().default(t).optional(),eo=t=>({def:Qt.parse(X({type:qe},t)),schema:gn(t.default)}),fn=[$e,ze,Fe,Ue,qe];zod.z.enum(fn);var to=zod.z.discriminatedUnion("type",[Wt,Vt,Yt,Qt,Zt]),O=(t=xe,e=Tt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let m=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),ne=(t=vt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,s;let i=Object.keys(e.def),m=Object.keys((s=(o=e.schema)==null?void 0:o.shape)!=null?s:{});return i.every(r=>m.includes(r))&&m.every(r=>i.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var bn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Tn={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},yn=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),On={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},Pn={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Sn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},vn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},xn={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Mn={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},En={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},Cn={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},wn={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},Gn={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},In={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},jn={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},An={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},kn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},g={TEMPERATURE:bn,MAX_TOKENS:Tn,STOP:yn,TOP_A:On,TOP_P:Pn,TOP_K:Sn,MIN_P:vn,FREQUENCY_PENALTY:xn,PRESENCE_PENALTY:Mn,REPETITION_PENALTY:Cn,SEED:En,LOG_PROBS:wn,TOP_LOG_PROBS:Gn,ECHO:In,RESPONSE_FORMAT:jn,RESPONSE_FORMAT_WITH_SCHEMA:An,RESPONSE_SCHEMA:kn};var Ne=t=>Object.fromEntries(Object.entries(t).filter(([e,o])=>o!=null));var oo=t=>t.split(";")[0].split("/")[1],V=t=>t==null?void 0:t.replace(/\/$/,"");var Ln=Object.defineProperty,Rn=Object.defineProperties,zn=Object.getOwnPropertyDescriptors,ao=Object.getOwnPropertySymbols,$n=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable,Un=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),no=(t,e,o)=>e in t?Ln(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,S=(t,e)=>{for(var o in e||(e={}))$n.call(e,o)&&no(t,o,e[o]);if(ao)for(var o of ao(e))Fn.call(e,o)&&no(t,o,e[o]);return t},ie=(t,e)=>Rn(t,zn(e)),A=(t,e,o)=>new Promise((s,i)=>{var m=c=>{try{d(o.next(c));}catch(p){i(p);}},r=c=>{try{d(o.throw(c));}catch(p){i(p);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,r);d((o=o.apply(t,e)).next());}),qn=function(t,e){this[0]=t,this[1]=e;},Nn=(t,e,o)=>{var s=(r,d,c,p)=>{try{var h=o[r](d),_=(d=h.value)instanceof qn,P=h.done;Promise.resolve(_?d[0]:d).then(T=>_?s(r==="return"?r:"next",d[1]?{done:T.done,value:T.value}:T,c,p):c({value:T,done:P})).catch(T=>s("throw",T,c,p));}catch(T){p(T);}},i=r=>m[r]=d=>new Promise((c,p)=>s(r,d,c,p)),m={};return o=o.apply(t,e),m[Un("asyncIterator")]=()=>m,i("next"),i("throw"),i("return"),m},so=w({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),io=t=>w({param:"max_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),ro=t=>Jt({param:"stop",title:g.STOP(t).title,description:g.STOP(t).description,max:t}),lo=w({param:"top_p",title:g.TOP_P.title,description:g.TOP_P.description,min:0,max:1,step:.01,default:1}),mo=w({param:"frequency_penalty",title:g.FREQUENCY_PENALTY.title,description:g.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),po=w({param:"presence_penalty",title:g.PRESENCE_PENALTY.title,description:g.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),co=w({param:"seed",title:g.SEED.title,description:g.SEED.description,min:0,max:1e6,step:1,default:0}),uo=eo({param:"logprobs",title:g.LOG_PROBS.title,description:g.LOG_PROBS.description,default:!1}),ho=w({param:"top_logprobs",title:g.TOP_LOG_PROBS.title,description:g.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),_o=te({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"]}),Be=(t,e)=>zod.z.object({temperature:so.schema,maxTokens:io(t).schema,stop:ro(e).schema,topP:lo.schema,frequencyPenalty:mo.schema,presencePenalty:po.schema,seed:co.schema.transform(o=>o===0?void 0:o),logProbs:uo.schema,topLogProbs:ho.schema,toolChoice:_o.schema}),De=(t,e)=>({temperature:so.def,maxTokens:io(t).def,stop:ro(e).def,topP:lo.def,frequencyPenalty:mo.def,presencePenalty:po.def,seed:co.def,logProbs:uo.def,topLogProbs:ho.def,toolChoice:_o.def}),go=te({param:"response_format",title:g.RESPONSE_FORMAT.title,description:g.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Bn=(t,e)=>ie(S({},De(t,e)),{responseFormat:go.def}),Dn=(t,e)=>Be(t,e).extend({responseFormat:go.schema}),fo=Xt({param:"response_schema",title:g.RESPONSE_SCHEMA.title,description:g.RESPONSE_SCHEMA.description,objectSchema:Pt}),bo=te({param:"response_format",title:g.RESPONSE_FORMAT_WITH_SCHEMA.title,description:g.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),To=(t,e)=>ie(S({},De(t,e)),{responseFormat:bo.def,responseSchema:fo.def}),yo=(t,e)=>Be(t,e).extend({responseFormat:bo.schema,responseSchema:fo.schema}),Oo=w({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Po=t=>w({param:"max_completion_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Kn=(t,e)=>ie(S({},To(t,e)),{temperature:Oo.def,maxTokens:Po(t).def}),Hn=(t,e)=>yo(t,e).extend({temperature:Oo.schema,maxTokens:Po(t).schema}),So=te({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),vo=t=>w({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:t,step:1,default:t}),xo=()=>zod.z.object({encodingFormat:So.schema}),Mo=()=>({encodingFormat:So.def}),Vn=t=>xo().extend({dimensions:vo(t).schema}),Jn=t=>ie(S({},Mo()),{dimensions:vo(t).def}),u={base:(t,e)=>({def:De(t,e),schema:Be(t,e)}),responseFormat:(t,e)=>({def:Bn(t,e),schema:Dn(t,e)}),responseSchema:(t,e)=>({def:To(t,e),schema:yo(t,e)}),oSeries:(t,e)=>({def:Kn(t,e),schema:Hn(t,e)})},J={base:()=>({def:Mo(),schema:xo()}),dimensions:t=>({def:Jn(t),schema:Vn(t)})},v=zod.z.enum([W,U,M,Y]),x={system:W,user:U,assistant:M,tool:Y},Eo=zod.z.enum([U,M]),Co={user:U,assistant:M},q=[y,k,E,G],N=zod.z.enum([y,k,E,G]),wo=[y],Go=zod.z.enum([y]),R=[y,E,G],z=zod.z.enum([y,E,G]),se=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Io=zod.z.object({content:zod.z.array(se.extend({top_logprobs:zod.z.array(se)})).nullable().optional(),refusal:zod.z.array(se.extend({top_logprobs:zod.z.array(se)})).nullable().optional()}).nullable(),Wn=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),Yn=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Wn.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Io.optional(),finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()})}),Zn=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),Xn=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Zn.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Io,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()}),Qn=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),es=zod.z.enum(["none","auto","required"]),ts=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),os=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),Ke=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),as=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),ns=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),ss=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Ke).min(1))}),is=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ke,as])).min(1))}),rs=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Ke).min(1)).optional(),tool_calls:zod.z.array(ns).min(1).optional()}),ls=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),ms=zod.z.union([ss,is,rs,ls]),jo=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ms).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:os.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Qn).optional(),tool_choice:es.or(ts).optional()});jo.omit({max_tokens:!0}).extend({max_completion_tokens:zod.z.number().min(0).nullable().optional()});var ds=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),Ao=class{constructor(t,e){this.version="v1";let o=ds.parse(e);this.modelSchema=t,this.apiKey=o.apiKey,this.baseUrl=V(o.baseUrl),this.streamChatUrl=V(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=V(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return S({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(t){let e=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,h=0;for(;(p=d.exec(r))!==null;){let _=parseInt(p[1]),P=p[2];h+=_*c[P];}return h},o=0,s=0,i=!0;t["x-ratelimit-reset-requests"]&&(o=e(t["x-ratelimit-reset-requests"])),t["x-ratelimit-reset-tokens"]&&(s=e(t["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:i,delayMs:m}}getTokenCount(t){return t.reduce((e,o)=>e+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let e=jo.safeParse(t);if(!e.success)throw new ee({info:"Invalid model request",cause:e.error});let o=e.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new ee({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};o.response_format&&(i.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(i.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"?i.toolChoice=o.tool_choice:i.toolChoice=o.tool_choice.function.name),i.seed=o.seed,i.maxTokens=o.max_tokens,i.temperature=o.temperature,i.topP=o.top_p,i.presencePenalty=o.presence_penalty,i.frequencyPenalty=o.frequency_penalty,i.stop=o.stop,i.logProbs=o.logprobs,i.topLogProbs=o.top_logprobs;let m=Ae().parse(Ne(i)),r=[],d={};o.messages.forEach(p=>{let h=p.role;switch(h){case"system":{let _=p.content;if(typeof _=="string")r.push({role:h,content:[{modality:y,value:_}]});else {let P=_.map(T=>({modality:y,value:T.text}));r.push({role:h,content:P});}}break;case"user":{let _=p.content;if(typeof _=="string")r.push({role:h,content:[{modality:y,value:_}]});else {let P=_.map(T=>T.type==="text"?{modality:y,value:T.text}:T.image_url.url.startsWith("data:")?{modality:k,detail:T.image_url.detail||"auto",value:{type:Me,base64:T.image_url.url,media_type:oo(T.image_url.url)}}:{modality:k,detail:T.image_url.detail||"auto",value:{type:Ee,url:T.image_url.url}});r.push({role:h,content:P});}}break;case"assistant":{let _=[];if(!p.content&&!p.tool_calls)throw new ee({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(p.content){let P=p.content;typeof P=="string"?_.push({modality:y,value:P}):P.forEach(T=>{_.push({modality:y,value:T.text});});}p.tool_calls&&p.tool_calls.forEach((P,T)=>{let Pe={modality:E,id:P.id,index:T,name:P.function.name,arguments:P.function.arguments};_.push(Pe),d[Pe.id]=Pe;}),r.push({role:h,content:_});}break;case"tool":{let _=p;r.push({role:h,content:[{modality:G,id:_.tool_call_id,index:d[_.tool_call_id].index,name:d[_.tool_call_id].name,data:_.content}]});}break}});let c=[];return o.tools&&o.tools.forEach(p=>{c.push({type:"function",definition:{schema:{name:p.function.name,description:p.function.description||"",strict:p.function.strict,parameters:p.function.parameters}}});}),{modelName:s,config:m,messages:r,tools:c.length>0?c:void 0}}transformConfig(t,e,o){let s=t.toolChoice;delete t.toolChoice;let i=this.modelSchema.config.schema.safeParse(t);if(!i.success)throw new j({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:i.error});let m=i.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new j({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${d}',
|
|
7
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((d,c)=>{let p=this.modelSchema.config.def[c],h=p.param,_=m[c];return h==="max_tokens"&&p.type==="range"&&_===0?d[h]=p.max:d[h]=_,d},{});if(r.top_logprobs&&!r.logprobs)throw new
|
|
8
|
-
one of [${c.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let d=r.response_format;if(d==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new
|
|
5
|
+
var Ma=Object.defineProperty;var mt=Object.getOwnPropertySymbols;var Ea=Object.prototype.hasOwnProperty,Ca=Object.prototype.propertyIsEnumerable;var dt=(t,e,o)=>e in t?Ma(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,xe=(t,e)=>{for(var o in e||(e={}))Ea.call(e,o)&&dt(t,o,e[o]);if(mt)for(var o of mt(e))Ca.call(e,o)&&dt(t,o,e[o]);return t};var wa=t=>{let e=new WeakSet;return JSON.stringify(t,(o,s)=>{if(typeof s=="object"&&s!==null){if(e.has(s))return;e.add(s);}return s})},Ga=t=>t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:wa(t),Me="GatewayBaseError",A=class ht extends Error{constructor({info:e,cause:o},s){super(`[${s!=null?s:Me}]: ${e}
|
|
6
|
+
Message: ${Ga(o)}`),this.name=Me,this.info=e,this.cause=o,this.name=s!=null?s:Me,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof ht}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},J="system",U="user",M="assistant",W="tool",Ia=[J,U,M,W],Ee=zod.z.enum(Ia),Aa=[M],ka=zod.z.enum(Aa),L="image",Ce="base64",ja=["png","jpeg","webp","gif"],La=zod.z.object({type:zod.z.literal(Ce),base64:zod.z.string(),media_type:zod.z.enum(ja)}),we="url",Ra=zod.z.object({type:zod.z.literal(we),url:zod.z.string()}),za=zod.z.discriminatedUnion("type",[La,Ra]),$a=["low","medium","high","auto"],Fa=zod.z.enum($a),Ua=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(L),detail:Fa,value:za,metadata:t}),y="text",_t=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(y),value:zod.z.string(),metadata:t}),Ge="partial-text",gt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ge),value:zod.z.string(),metadata:t}),E="tool-call",ft=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(E),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:t}),Ie="partial-tool-call",bt=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ie),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:t}),G="tool-response",qa=(t=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(G),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:t}),Na=[y,L,E,G],Tt=zod.z.enum(Na),Ba=(t=zod.z.undefined(),e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[_t(t),Ua(e),ft(o),qa(s)]),Da=[Ge,Ie];zod.z.enum(Da);var Ka=(t=zod.z.undefined(),e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[gt(t),bt(e)]);var Y=(t=Ee,e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),i=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:t,content:zod.z.array(Ba(e,o,s,i)),metadata:m}),Ae=(t=ka,e=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:t,partialContent:Ka(e,o),metadata:s});var ke=(t,e)=>Y().parse({role:t,content:[_t().parse({modality:y,value:e})]});var yt=(t,e,o,s,i)=>Y().parse({role:t,content:[ft().parse({modality:E,index:e,id:o,name:s,arguments:i})]});var je=(t,e)=>Ae().parse({role:t,partialContent:gt().parse({modality:Ge,value:e})}),Ot=(t,e,o,s,i)=>Ae().parse({role:t,partialContent:bt().parse({modality:Ie,index:e,id:o,name:s,arguments:i})});var Le=(t=zod.z.record(zod.z.string(),zod.z.any()).optional())=>t,Ha=["object","array","number","string","boolean","enum"],pt=zod.z.enum(Ha),Va=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([pt,zod.z.array(zod.z.union([pt,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),Ja=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Va),additionalProperties:zod.z.literal(!1)}),Pt=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:Ja}).optional(),Wa="function";var Ya=zod.z.enum(["object","array","number","string","boolean","null"]),Za=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ya.optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional()});zod.z.object({type:zod.z.enum(["object"]),title:zod.z.string().optional(),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(Za).optional(),required:zod.z.array(zod.z.string()).optional()});var Xa=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),parameters:zod.z.any(),strict:zod.z.boolean().optional()});var Qa=zod.z.enum(["function"]),en=zod.z.object({type:Qa,definition:zod.z.object({schema:Xa})}),tn=[Wa];zod.z.enum(tn);var St=(t=zod.z.undefined())=>zod.z.discriminatedUnion("type",[en.extend({metadata:t})]),R="text",D="token",on=[R,D],vt=zod.z.enum(on),an=zod.z.array(zod.z.string().min(1)),nn=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),xt=(t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(R),metadata:t,requests:an}),zod.z.object({modality:zod.z.literal(D),metadata:t,requests:nn})]),Re="float",sn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),ze="base64",rn=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),ct=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Re),embeddings:zod.z.array(sn),usage:ct.optional()}),zod.z.object({encodingFormat:zod.z.literal(ze),embeddings:zod.z.array(rn),usage:ct.optional()})]);var Mt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ut=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),ln=ut.extend({topLogProbs:zod.z.array(ut)}),Et=zod.z.array(ln);zod.z.object({messages:zod.z.array(Y()),usage:Mt.optional(),logProbs:Et.optional()});zod.z.object({partialMessages:zod.z.array(Ae()),usage:Mt.optional(),logProbs:Et.optional()});var mn=Object.defineProperty,Ct=Object.getOwnPropertySymbols,dn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,wt=(t,e,o)=>e in t?mn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,Z=(t,e)=>{for(var o in e||(e={}))dn.call(e,o)&&wt(t,o,e[o]);if(Ct)for(var o of Ct(e))pn.call(e,o)&&wt(t,o,e[o]);return t},Gt="ProviderError",ae=class $t extends A{constructor({info:e,cause:o}){super({info:e,cause:o},Gt),this.name=Gt,this.info=e,this.cause=o;}static isProviderError(e){return e instanceof $t}},It="ModelError",X=class Ft extends A{constructor({info:e,cause:o}){super({info:e,cause:o},It),this.name=It,this.info=e,this.cause=o;}static isModelError(e){return e instanceof Ft}},At="ModelResponseError",K=class Ut extends A{constructor({info:e,cause:o}){super({info:e,cause:o},At),this.name=At,this.cause=o,this.info=e;}static isModelResponseError(e){return e instanceof Ut}},kt="InvalidModelRequestError",Q=class qt extends A{constructor({info:e,cause:o}){super({info:e,cause:o},kt),this.name=kt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof qt}},jt="InvalidConfigError",k=class Nt extends A{constructor({info:e,cause:o}){super({info:e,cause:o},jt),this.name=jt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof Nt}},Lt="InvalidMessagesError",C=class Bt extends A{constructor({info:e,cause:o}){super({info:e,cause:o},Lt),this.name=Lt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof Bt}},Rt="InvalidToolsError",$e=class Dt extends A{constructor({info:e,cause:o}){super({info:e,cause:o},Rt),this.name=Rt,this.cause=o,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof Dt}},zt="InvalidEmbeddingRequestsError",Kt=class Ht extends A{constructor({info:e,cause:o}){super({info:e,cause:o},zt),this.name=zt,this.info=e,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof Ht}},Fe="multi-string",Vt=zod.z.object({type:zod.z.literal(Fe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),cn=t=>zod.z.array(zod.z.string()).max(t).default([]).optional(),Jt=t=>({def:Vt.parse(Z({type:Fe},t)),schema:cn(t.max)}),Ue="range",Wt=zod.z.object({type:zod.z.literal(Ue),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),un=(t,e,o,s)=>zod.z.number().min(t).max(e).step(o).default(s).optional(),w=t=>({def:Wt.parse(Z({type:Ue},t)),schema:un(t.min,t.max,t.step,t.default)}),qe="select-string",Yt=zod.z.object({type:zod.z.literal(qe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string().min(1).nullable(),choices:zod.z.array(zod.z.string().min(1))}),hn=(t,e)=>zod.z.enum(e).nullable().default(t).optional(),ee=t=>({def:Yt.parse(Z({type:qe},t)),schema:hn(t.default,t.choices)}),Ne="object-schema",Zt=zod.z.object({type:zod.z.literal(Ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),_n=t=>t.optional(),Xt=t=>({def:Zt.parse(Z({type:Ne},t)),schema:_n(t.objectSchema)}),Be="select-boolean",Qt=zod.z.object({type:zod.z.literal(Be),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.boolean().nullable()}),gn=t=>zod.z.boolean().nullable().default(t).optional(),eo=t=>({def:Qt.parse(Z({type:Be},t)),schema:gn(t.default)}),fn=[Ue,Fe,qe,Ne,Be];zod.z.enum(fn);var to=zod.z.discriminatedUnion("type",[Wt,Vt,Yt,Qt,Zt]),O=(t=Ee,e=Tt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(t,zod.z.string().min(1).optional()),modalities:zod.z.array(e).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,i;let m=Object.keys(o.def),r=Object.keys((i=(s=o.schema)==null?void 0:s.shape)!=null?i:{});return m.every(d=>r.includes(d))&&r.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),ne=(t=vt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(t).nonempty(),maxInputTokens:zod.z.number().int().positive().min(1),maxOutputTokens:zod.z.number().int().positive().min(1),config:zod.z.object({def:zod.z.record(zod.z.string().min(1),to),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(e=>{var o,s;let i=Object.keys(e.def),m=Object.keys((s=(o=e.schema)==null?void 0:o.shape)!=null?s:{});return i.every(r=>m.includes(r))&&m.every(r=>i.includes(r))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});zod.z.record(zod.z.string());zod.z.record(zod.z.union([zod.z.boolean(),zod.z.string(),zod.z.number(),zod.z.object({}),zod.z.array(zod.z.any()),zod.z.null(),zod.z.undefined()]));zod.z.string().url();var bn={type:"range",title:"Temperature",description:"Adjusts the model's creativity level. With a setting of 0, the model strictly picks the most probable next word. For endeavors that benefit from a dash of inventiveness, consider dialing it up to 0.7 or higher, enabling the model to produce text that's unexpectedly fresh."},Tn={type:"range",title:"Max tokens",description:"Specify the total tokens for generation, where one token approximates four English characters. Setting this to 0 defaults to the model's maximum capacity."},yn=t=>({type:"multi",title:"Stop sequence",description:`Enter up to ${t} sequences that will halt additional text output. The generated text will exclude these sequences.`}),On={type:"range",title:"Top A",description:"Considers only the top tokens that have 'sufficiently high' probabilities relative to the most likely token, functioning like a dynamic Top-P. A lower Top-A value narrows down the token choices based on the highest probability token, while a higher Top-A value refines the filtering without necessarily impacting the creativity of the output."},Pn={type:"range",title:"Top P",description:"Selects a subset of likely tokens for generation, restricting choices to the top-P fraction of possibilities, such as the top 10% when P=0.1. This approach can limit the variety of the output. By default, it's set to 1, indicating no restriction. It's advised to adjust this parameter or temperature to modulate output diversity, but not to modify both simultaneously."},Sn={type:"range",title:"Top K",description:"Select only from the highest K probabilities for each following word, effectively eliminating the less likely 'long tail' options."},vn={type:"range",title:"Min P",description:"Specifies the minimum probability a token must have to be considered, in relation to the probability of the most likely token. (This value varies based on the confidence level of the top token.) For example, if Min-P is set to 0.1, only tokens with at least 1/10th the probability of the highest-ranked token will be considered."},xn={type:"range",title:"Frequency penalty",description:"Minimize redundancy. By assigning a penalty to frequently used tokens within the text, the likelihood of repeating identical phrases is reduced. The default setting for this penalty is zero."},Mn={type:"range",title:"Presence penalty",description:"Enhance the introduction of novel subjects by reducing the preference for tokens that have already appeared in the text, thus boosting the chances of exploring fresh topics. The standard setting for this is zero."},En={type:"range",title:"Seed",description:"When seed is fixed to a specific value, the model makes a best effort to provide the same response for repeated requests. Deterministic output isn't guaranteed. Also, changing the model or parameter settings, such as the temperature, can cause variations in the response even when you use the same seed value. By default, a random seed value is used."},Cn={type:"range",title:"Repetition penalty",description:"Reduces the likelihood of repeating tokens from the input. Increasing this value makes the model less prone to repetition, but setting it too high may lead to less coherent output, often resulting in run-on sentences missing smaller words. The token penalty is scaled according to the original token's probability."},wn={type:"boolean",title:"Log probs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned."},Gn={type:"range",title:"Top log probs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used."},In={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},An={type:"select",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt."},kn={type:"select",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to."},jn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},g={TEMPERATURE:bn,MAX_TOKENS:Tn,STOP:yn,TOP_A:On,TOP_P:Pn,TOP_K:Sn,MIN_P:vn,FREQUENCY_PENALTY:xn,PRESENCE_PENALTY:Mn,REPETITION_PENALTY:Cn,SEED:En,LOG_PROBS:wn,TOP_LOG_PROBS:Gn,ECHO:In,RESPONSE_FORMAT:An,RESPONSE_FORMAT_WITH_SCHEMA:kn,RESPONSE_SCHEMA:jn};var De=t=>Object.fromEntries(Object.entries(t).filter(([e,o])=>o!=null));var oo=t=>t.split(";")[0].split("/")[1],H=t=>t==null?void 0:t.replace(/\/$/,"");var b=zod.z.object({apiKey:zod.z.string().min(1),deploymentName:zod.z.string().min(1),resourceName:zod.z.string().min(1).optional(),baseUrl:zod.z.string().optional()});var Ln=Object.defineProperty,Rn=Object.defineProperties,zn=Object.getOwnPropertyDescriptors,ao=Object.getOwnPropertySymbols,$n=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable,Un=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),no=(t,e,o)=>e in t?Ln(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,S=(t,e)=>{for(var o in e||(e={}))$n.call(e,o)&&no(t,o,e[o]);if(ao)for(var o of ao(e))Fn.call(e,o)&&no(t,o,e[o]);return t},ie=(t,e)=>Rn(t,zn(e)),j=(t,e,o)=>new Promise((s,i)=>{var m=c=>{try{d(o.next(c));}catch(p){i(p);}},r=c=>{try{d(o.throw(c));}catch(p){i(p);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,r);d((o=o.apply(t,e)).next());}),qn=function(t,e){this[0]=t,this[1]=e;},Nn=(t,e,o)=>{var s=(r,d,c,p)=>{try{var h=o[r](d),_=(d=h.value)instanceof qn,P=h.done;Promise.resolve(_?d[0]:d).then(T=>_?s(r==="return"?r:"next",d[1]?{done:T.done,value:T.value}:T,c,p):c({value:T,done:P})).catch(T=>s("throw",T,c,p));}catch(T){p(T);}},i=r=>m[r]=d=>new Promise((c,p)=>s(r,d,c,p)),m={};return o=o.apply(t,e),m[Un("asyncIterator")]=()=>m,i("next"),i("throw"),i("return"),m},so=w({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),io=t=>w({param:"max_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),ro=t=>Jt({param:"stop",title:g.STOP(t).title,description:g.STOP(t).description,max:t}),lo=w({param:"top_p",title:g.TOP_P.title,description:g.TOP_P.description,min:0,max:1,step:.01,default:1}),mo=w({param:"frequency_penalty",title:g.FREQUENCY_PENALTY.title,description:g.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),po=w({param:"presence_penalty",title:g.PRESENCE_PENALTY.title,description:g.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),co=w({param:"seed",title:g.SEED.title,description:g.SEED.description,min:0,max:1e6,step:1,default:0}),uo=eo({param:"logprobs",title:g.LOG_PROBS.title,description:g.LOG_PROBS.description,default:!1}),ho=w({param:"top_logprobs",title:g.TOP_LOG_PROBS.title,description:g.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),_o=ee({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"]}),Ke=(t,e)=>zod.z.object({temperature:so.schema,maxTokens:io(t).schema,stop:ro(e).schema,topP:lo.schema,frequencyPenalty:mo.schema,presencePenalty:po.schema,seed:co.schema.transform(o=>o===0?void 0:o),logProbs:uo.schema,topLogProbs:ho.schema,toolChoice:_o.schema}),He=(t,e)=>({temperature:so.def,maxTokens:io(t).def,stop:ro(e).def,topP:lo.def,frequencyPenalty:mo.def,presencePenalty:po.def,seed:co.def,logProbs:uo.def,topLogProbs:ho.def,toolChoice:_o.def}),go=ee({param:"response_format",title:g.RESPONSE_FORMAT.title,description:g.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Bn=(t,e)=>ie(S({},He(t,e)),{responseFormat:go.def}),Dn=(t,e)=>Ke(t,e).extend({responseFormat:go.schema}),fo=Xt({param:"response_schema",title:g.RESPONSE_SCHEMA.title,description:g.RESPONSE_SCHEMA.description,objectSchema:Pt}),bo=ee({param:"response_format",title:g.RESPONSE_FORMAT_WITH_SCHEMA.title,description:g.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),To=(t,e)=>ie(S({},He(t,e)),{responseFormat:bo.def,responseSchema:fo.def}),yo=(t,e)=>Ke(t,e).extend({responseFormat:bo.schema,responseSchema:fo.schema}),Oo=w({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Po=t=>w({param:"max_completion_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:t,step:1,default:0}),Kn=(t,e)=>ie(S({},To(t,e)),{temperature:Oo.def,maxTokens:Po(t).def}),Hn=(t,e)=>yo(t,e).extend({temperature:Oo.schema,maxTokens:Po(t).schema}),So=ee({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),vo=t=>w({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:t,step:1,default:t}),xo=()=>zod.z.object({encodingFormat:So.schema}),Mo=()=>({encodingFormat:So.def}),Vn=t=>xo().extend({dimensions:vo(t).schema}),Jn=t=>ie(S({},Mo()),{dimensions:vo(t).def}),u={base:(t,e)=>({def:He(t,e),schema:Ke(t,e)}),responseFormat:(t,e)=>({def:Bn(t,e),schema:Dn(t,e)}),responseSchema:(t,e)=>({def:To(t,e),schema:yo(t,e)}),oSeries:(t,e)=>({def:Kn(t,e),schema:Hn(t,e)})},V={base:()=>({def:Mo(),schema:xo()}),dimensions:t=>({def:Jn(t),schema:Vn(t)})},v=zod.z.enum([J,U,M,W]),x={system:J,user:U,assistant:M,tool:W},Eo=zod.z.enum([U,M]),Co={user:U,assistant:M},q=[y,L,E,G],N=zod.z.enum([y,L,E,G]),wo=[y],Go=zod.z.enum([y]),z=[y,E,G],$=zod.z.enum([y,E,G]),se=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),Io=zod.z.object({content:zod.z.array(se.extend({top_logprobs:zod.z.array(se)})).nullable().optional(),refusal:zod.z.array(se.extend({top_logprobs:zod.z.array(se)})).nullable().optional()}).nullable(),Wn=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),Yn=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Wn.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:Io.optional(),finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()})}),Zn=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),Xn=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Zn.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:Io,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()}),Qn=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),es=zod.z.enum(["none","auto","required"]),ts=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),os=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),Ve=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),as=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),ns=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),ss=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(Ve).min(1))}),is=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([Ve,as])).min(1))}),rs=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(Ve).min(1)).optional(),tool_calls:zod.z.array(ns).min(1).optional()}),ls=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),ms=zod.z.union([ss,is,rs,ls]),Ao=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(ms).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:os.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Qn).optional(),tool_choice:es.or(ts).optional()});Ao.omit({max_tokens:!0}).extend({max_completion_tokens:zod.z.number().min(0).nullable().optional()});var ds=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),ko=class{constructor(t,e){this.version="v1";let o=ds.parse(e);this.modelSchema=t,this.apiKey=o.apiKey,this.baseUrl=H(o.baseUrl),this.streamChatUrl=H(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=H(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return S({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(t){let e=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,h=0;for(;(p=d.exec(r))!==null;){let _=parseInt(p[1]),P=p[2];h+=_*c[P];}return h},o=0,s=0,i=!0;t["x-ratelimit-reset-requests"]&&(o=e(t["x-ratelimit-reset-requests"])),t["x-ratelimit-reset-tokens"]&&(s=e(t["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:i,delayMs:m}}getTokenCount(t){return t.reduce((e,o)=>e+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let e=Ao.safeParse(t);if(!e.success)throw new Q({info:"Invalid model request",cause:e.error});let o=e.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new Q({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};o.response_format&&(i.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(i.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"?i.toolChoice=o.tool_choice:i.toolChoice=o.tool_choice.function.name),i.seed=o.seed,i.maxTokens=o.max_tokens,i.temperature=o.temperature,i.topP=o.top_p,i.presencePenalty=o.presence_penalty,i.frequencyPenalty=o.frequency_penalty,i.stop=o.stop,i.logProbs=o.logprobs,i.topLogProbs=o.top_logprobs;let m=Le().parse(De(i)),r=[],d={};o.messages.forEach(p=>{let h=p.role;switch(h){case"system":{let _=p.content;if(typeof _=="string")r.push({role:h,content:[{modality:y,value:_}]});else {let P=_.map(T=>({modality:y,value:T.text}));r.push({role:h,content:P});}}break;case"user":{let _=p.content;if(typeof _=="string")r.push({role:h,content:[{modality:y,value:_}]});else {let P=_.map(T=>T.type==="text"?{modality:y,value:T.text}:T.image_url.url.startsWith("data:")?{modality:L,detail:T.image_url.detail||"auto",value:{type:Ce,base64:T.image_url.url,media_type:oo(T.image_url.url)}}:{modality:L,detail:T.image_url.detail||"auto",value:{type:we,url:T.image_url.url}});r.push({role:h,content:P});}}break;case"assistant":{let _=[];if(!p.content&&!p.tool_calls)throw new Q({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(p.content){let P=p.content;typeof P=="string"?_.push({modality:y,value:P}):P.forEach(T=>{_.push({modality:y,value:T.text});});}p.tool_calls&&p.tool_calls.forEach((P,T)=>{let ve={modality:E,id:P.id,index:T,name:P.function.name,arguments:P.function.arguments};_.push(ve),d[ve.id]=ve;}),r.push({role:h,content:_});}break;case"tool":{let _=p;r.push({role:h,content:[{modality:G,id:_.tool_call_id,index:d[_.tool_call_id].index,name:d[_.tool_call_id].name,data:_.content}]});}break}});let c=[];return o.tools&&o.tools.forEach(p=>{c.push({type:"function",definition:{schema:{name:p.function.name,description:p.function.description||"",strict:p.function.strict,parameters:p.function.parameters}}});}),{modelName:s,config:m,messages:r,tools:c.length>0?c:void 0}}transformConfig(t,e,o){let s=t.toolChoice;delete t.toolChoice;let i=this.modelSchema.config.schema.safeParse(t);if(!i.success)throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:i.error});let m=i.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${d}',
|
|
7
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(m).reduce((d,c)=>{let p=this.modelSchema.config.def[c],h=p.param,_=m[c];return h==="max_tokens"&&p.type==="range"&&_===0?d[h]=p.max:d[h]=_,d},{});if(r.top_logprobs&&!r.logprobs)throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in r&&r.tool_choice!==void 0){let d=r.tool_choice;if(!o||o&&o.length===0)throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(o&&o.length>0){let c=this.modelSchema.config.def.toolChoice;if(!c.choices.includes(d))if(o.map(p=>p.definition.schema.name).includes(d))r.tool_choice={type:"function",function:{name:d}};else throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
|
|
8
|
+
one of [${c.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let d=r.response_format;if(d==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else r.response_format={type:d};}return r}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=t.map(o=>{let s=Y().safeParse(o);if(!s.success)throw new C({info:"Invalid messages",cause:s.error});return s.data});return e.forEach(o=>{o.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new C({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support modality : '${s.modality}',
|
|
9
9
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),e.forEach(o=>{if(!Object.keys(this.modelSchema.roles).includes(o.role))throw new C({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support role : '${o.role}',
|
|
10
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:e.map(o=>{switch(o.role){case
|
|
11
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(E))throw new
|
|
12
|
-
`).filter(m=>m.trim()!=="");for(let m of i){if(m==="data: [DONE]")return;if(m.startsWith("data: {")&&m.endsWith("}")){let r;try{r=JSON.parse(m.substring(6));}catch(c){throw new
|
|
13
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,m)=>{let r=this.modelSchema.config.def[m].param,d=s[m];return i[r]=d,i},{})}transformEmbeddingRequests(t){let e=xt().safeParse(t);if(!e.success)throw new Kt({info:"Invalid embedding requests",cause:e.error});return {input:e.data.requests}}getGetEmbeddingsUrl(t,e){return
|
|
14
|
-
${this.chatModelLiterals().join(", ")}`)});
|
|
15
|
-
${this.chatModelLiterals().join(", ")}`)});return this.chatModelFactories[e].modelSchema}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModel(e,o){if(!(e in this.embeddingModelFactories))throw new K({info:`Azure embedding model: ${e} not found`,cause:new Error(`Azure embedding model: ${e} not found, available embedding models:
|
|
16
|
-
${this.embeddingModelLiterals().join(", ")}`)});let s=this.embeddingModelFactories[e].model,i=Se({},o),m=this.embeddingModelFactories[e].modelOptions.parse(i);return new s(m)}embeddingModelSchema(e){if(!(e in this.embeddingModelFactories))throw new K({info:`Azure embedding model: ${e} not found`,cause:new Error(`Azure embedding model: ${e} not found, available embedding models:
|
|
10
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:e.map(o=>{switch(o.role){case J:{let s=[];return o.content.forEach(i=>{if(i.modality===y)s.push({type:"text",text:i.value});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${i.modality}'`)})}),{role:this.modelSchema.roles[o.role],content:s}}case M:{let s=[],i=[];return o.content.forEach(m=>{if(m.modality===y)s.push({type:"text",text:m.value});else if(m.modality===E)i.push({id:m.id,type:"function",function:{name:m.name,arguments:m.arguments}});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${m.modality}'`)})}),S({role:this.modelSchema.roles[o.role],content:s},i.length>0?{tool_calls:i}:{})}case U:{let s=[],i=[];o.content.forEach(r=>{if(r.modality===y)s.push({type:"text",text:r.value});else if(r.modality===L)i.push({type:"image_url",image_url:{url:r.value.type==="url"?r.value.url:r.value.base64,detail:r.detail}});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${o.role}' cannot have content with modality : '${r.modality}'`)})});let m=[...s,...i];return {role:this.modelSchema.roles[o.role],content:m}}case W:{if(o.content.length!==1)throw new C({info:`Invalid message for role : '${o.role}'`,cause:new Error(`role : '${o.role}' must have exactly one content item`)});if(o.content[0].modality!==G)throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${o.role}' must have content with modality : '${G}'`)});let s=o.content[0];return {role:this.modelSchema.roles[o.role],tool_call_id:s.id,content:s.data}}default:throw new C({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`role : '${o.role}' is not supported,
|
|
11
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(E))throw new $e({info:`Invalid tool 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' does not support tool modality : '${E}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(e=>{let o=St().safeParse(e);if(!o.success)throw new $e({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({type:"function",function:e.definition.schema}))}}getCompleteChatUrl(t,e,o){return j(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return j(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return j(this,null,function*(){let s=this.transformConfig(t,e,o),i=this.transformMessages(e);if(i.messages&&i.messages.length===0)throw new C({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(S(S(S(S({},this.getDefaultParams()),s),i),m));})})}transformCompleteChatResponse(t){let e=Yn.safeParse(t);if(e.success){if(e.data.choices.length===0)throw new K({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,s=[],i=o.choices[0].message;i.content&&s.push(ke(M,i.content)),i.refusal&&s.push(ke(M,i.refusal)),i.tool_calls&&i.tool_calls.forEach((c,p)=>{s.push(yt(M,p,c.id,c.function.name,c.function.arguments));});let m={promptTokens:o.usage.prompt_tokens,completionTokens:o.usage.completion_tokens,totalTokens:o.usage.total_tokens},r=[],d=o.choices[0].logprobs;return d&&(d.content&&r.push(...d.content.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))}))),d.refusal&&r.push(...d.refusal.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes}))})))),{messages:s,usage:m,logProbs:r}}throw new K({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return j(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return j(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return j(this,null,function*(){let s=this.transformConfig(t,e,o),i=this.transformMessages(e);if(i.messages&&i.messages.length===0)throw new C({info:"Messages are required",cause:new Error("Messages are required")});let m=o?this.transformTools(o):{};return new Promise(r=>{r(S(S(S(S({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),i),m));})})}transformStreamChatResponseChunk(t,e){return Nn(this,null,function*(){var o,s;let i=(e+t).split(`
|
|
12
|
+
`).filter(m=>m.trim()!=="");for(let m of i){if(m==="data: [DONE]")return;if(m.startsWith("data: {")&&m.endsWith("}")){let r;try{r=JSON.parse(m.substring(6));}catch(c){throw new K({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${r}`)})}let d=Xn.safeParse(r);if(d.success){let c={partialMessages:[]},p=d.data;if(p.choices.length>0){let h=p.choices[0].delta;if(h!==void 0&&Object.keys(h).length!==0){if("content"in h&&h.content!==null)c.partialMessages.push(je(M,h.content));else if("refusal"in h&&h.refusal!==null)c.partialMessages.push(je(M,h.refusal));else if("tool_calls"in h&&h.tool_calls!==void 0){let _=h.tool_calls.at(0);c.partialMessages.push(Ot(M,_.index,_.id,(o=_.function)==null?void 0:o.name,(s=_.function)==null?void 0:s.arguments));}}}p.usage&&(c.usage={promptTokens:p.usage.prompt_tokens,completionTokens:p.usage.completion_tokens,totalTokens:p.usage.total_tokens}),yield {partialResponse:c,buffer:e};}else throw new K({info:"Invalid response from model",cause:d.error})}}})}};var ps="gpt-3.5-turbo-0125",cs="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.",jo=O(v,$).parse({name:ps,description:cs,maxInputTokens:4092,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema}});var us="gpt-3.5-turbo-1106",hs="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.",Lo=O(v,$).parse({name:us,description:hs,maxInputTokens:4092,maxOutputTokens:16385,roles:x,modalities:z,config:{def:u.responseFormat(16385,4).def,schema:u.responseFormat(16385,4).schema}});var _s="gpt-3.5-turbo",gs="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.",Ro=O(v,$).parse({name:_s,description:gs,maxInputTokens:4092,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema}});var fs="gpt-4-0125-preview",bs="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.";O(v,$).parse({name:fs,description:bs,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema}});var Ts="gpt-4-0613",ys="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.",zo=O(v,$).parse({name:Ts,description:ys,maxInputTokens:8192,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema}});var Os="gpt-4-1106-preview",Ps="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.",$o=O(v,$).parse({name:Os,description:Ps,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema}});var Ss="gpt-4-turbo-2024-04-09",vs="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.",Fo=O(v,N).parse({name:Ss,description:vs,maxInputTokens:128e3,maxOutputTokens:4096,roles:x,modalities:q,config:{def:u.responseFormat(4096,4).def,schema:u.responseFormat(4096,4).schema}});var xs="gpt-4-turbo-preview",Ms="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.";O(v,$).parse({name:xs,description:Ms,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema}});var Es="gpt-4-turbo",Cs="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.";O(v,N).parse({name:Es,description:Cs,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema}});var ws="gpt-4",Gs="Currently points to gpt-4-0613. Training data up to Sept 2021.",Uo=O(v,$).parse({name:ws,description:Gs,maxInputTokens:8192,maxOutputTokens:4092,roles:x,modalities:z,config:{def:u.base(4092,4).def,schema:u.base(4092,4).schema}});var Is="gpt-4o-2024-08-06",As="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",qo=O(v,N).parse({name:Is,description:As,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema}});var ks="gpt-4o-mini",js="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.",No=O(v,N).parse({name:ks,description:js,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema}});var Ls="gpt-4o",Rs="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=O(v,N).parse({name:Ls,description:Rs,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseFormat(4092,4).def,schema:u.responseFormat(4092,4).schema}});var zs="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.",Do=O(v,N).parse({name:zs,description:$s,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema}});var Fs="gpt-4o-2024-05-13",Us="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.",Ko=O(v,N).parse({name:Fs,description:Us,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:q,config:{def:u.responseSchema(4092,4).def,schema:u.responseSchema(4092,4).schema}});var qs="o1-mini",Ns="Faster and cheaper reasoning model particularly good at coding, math, and science. Training data up to Oct 2023.";O(Eo,Go).parse({name:qs,description:Ns,maxInputTokens:128e3,maxOutputTokens:4092,roles:Co,modalities:wo,config:{def:u.oSeries(4092,4).def,schema:u.oSeries(4092,4).schema}});var Bs="o1-preview",Ds="Reasoning model designed to solve hard problems across domains. Training data up to Oct 2023.";O(Eo,Go).parse({name:Bs,description:Ds,maxInputTokens:128e3,maxOutputTokens:4092,roles:Co,modalities:wo,config:{def:u.oSeries(4092,4).def,schema:u.oSeries(4092,4).schema}});var Je=[R,D],We=zod.z.enum([R,D]),Ks=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()})}),Hs=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)).or(zod.z.array(zod.z.number().int().nonnegative()).min(1)).or(zod.z.array(zod.z.array(zod.z.number().int().nonnegative()).min(1)).min(1)),Vs=zod.z.object({model:zod.z.string().min(1).optional(),input:Hs,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()}),Js=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),Ho=class{constructor(t,e){this.version="v1";let o=Js.parse(e);this.modelSchema=t,this.apiKey=o.apiKey,this.baseUrl=H(o.baseUrl),this.getEmbeddingsUrl=H(o.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(t){let e=r=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,h=0;for(;(p=d.exec(r))!==null;){let _=parseInt(p[1]),P=p[2];h+=_*c[P];}return h},o=0,s=0,i=!0;t["x-ratelimit-reset-requests"]&&(o=e(t["x-ratelimit-reset-requests"])),t["x-ratelimit-reset-tokens"]&&(s=e(t["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:i,delayMs:m}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=Vs.safeParse(t);if(!e.success)throw new Q({info:"Invalid model request",cause:e.error});let o=e.data,s=o.model,i={encodingFormat:o.encoding_format,dimensions:o.dimensions},m=Le().parse(De(i)),r,d;return typeof o.input=="string"?d=R:typeof o.input[0]=="string"?d=R:d=D,d===R?typeof o.input=="string"?r={modality:d,requests:[o.input]}:r={modality:d,requests:o.input}:typeof o.input[0]=="number"?r={modality:d,requests:[o.input]}:r={modality:d,requests:o.input},{modelName:s,config:m,embeddingRequests:r}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:o.error});let s=o.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new k({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${i}',
|
|
13
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,m)=>{let r=this.modelSchema.config.def[m].param,d=s[m];return i[r]=d,i},{})}transformEmbeddingRequests(t){let e=xt().safeParse(t);if(!e.success)throw new Kt({info:"Invalid embedding requests",cause:e.error});return {input:e.data.requests}}getGetEmbeddingsUrl(t,e){return j(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,e){return j(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,e){return j(this,null,function*(){return new Promise(o=>{o(S(S(S({},this.getDefaultParams()),this.transformConfig(t,e)),this.transformEmbeddingRequests(e)));})})}transformGetEmbeddingsResponse(t){let e,o=Ks.safeParse(t);if(o.success){let s=o.data;e=typeof s.data[0].embedding=="string"?ze:Re;let i=s.data.map(m=>typeof m.embedding=="string"?{index:m.index,embedding:m.embedding}:{index:m.index,embedding:m.embedding});return {encodingFormat:e,embeddings:i,usage:{totalTokens:s.usage.total_tokens}}}throw new K({info:"Invalid response from model",cause:o.error})}},Ws="text-embedding-ada-002",Ys="Most capable 2nd generation embedding model, replacing 16 first generation models",Vo=ne(We).parse({name:Ws,description:Ys,modalities:Je,maxInputTokens:8192,maxOutputTokens:1536,config:{def:V.base().def,schema:V.base().schema}});var Zs="text-embedding-3-small",Xs="Increased performance over 2nd generation ada embedding model",Jo=ne(We).parse({name:Zs,description:Xs,modalities:Je,maxInputTokens:8192,maxOutputTokens:1536,config:{def:V.dimensions(1536).def,schema:V.dimensions(1536).schema}});var Qs="text-embedding-3-large",ei="Most capable embedding model for both english and non-english tasks",Wo=ne(We).parse({name:Qs,description:ei,modalities:Je,maxInputTokens:8192,maxOutputTokens:3072,config:{def:V.dimensions(3072).def,schema:V.dimensions(3072).schema}});var f=class extends ko{constructor(o,s){let i=b.parse(s),m;if(i.baseUrl)m=i.baseUrl;else if(i.resourceName)m=B.azureUrl(i.resourceName,"openai");else throw new X({info:"Either 'baseUrl' or 'resourceName' must be provided",cause:new Error("Either 'baseUrl' or 'resourceName' must be provided")});let r="2024-06-01",d=`${m}/openai/deployments/${i.deploymentName}`;super(o,{apiKey:i.apiKey,baseUrl:d,completeChatUrl:`${d}/chat/completions?api-version=${r}`,streamChatUrl:`${d}/chat/completions?api-version=${r}`});this.version="v1";this.modelSchema=o,this.azureApiKey=i.apiKey,this.azureApiVersion=r;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}};var Yo="gpt-4o",le=Bo,Zo=b,re=class extends f{constructor(e){super(le,e);}};var Xo="gpt-4o-mini",Ye=No,Qo=b,me=class extends f{constructor(e){super(Ye,e);}};var ea="gpt-4o-mini-2024-07-18",Ze=Do,ta=b,de=class extends f{constructor(e){super(Ze,e);}};var oa="gpt-4o-2024-08-06",Xe=qo,aa=b,pe=class extends f{constructor(e){super(Xe,e);}};var na="gpt-4o-2024-05-13",Qe=Ko,sa=b,ce=class extends f{constructor(e){super(Qe,e);}};var ia="gpt-4",et=Uo,ra=b,ue=class extends f{constructor(e){super(et,e);}};var la="gpt-4-turbo-2024-04-09",tt=Fo,ma=b,he=class extends f{constructor(e){super(tt,e);}};var da="gpt-4-1106-preview",ot=$o,pa=b,_e=class extends f{constructor(e){super(ot,e);}};var ca="gpt-4-0613",at=zo,ua=b,ge=class extends f{constructor(e){super(at,e);}};var ha="gpt-3-5-turbo",nt=Ro,_a=b,fe=class extends f{constructor(e){super(nt,e);}};var ga="gpt-3-5-turbo-1106",st=Lo,fa=b,be=class extends f{constructor(e){super(st,e);}};var ba="gpt-3-5-turbo-0125",it=jo,Ta=b,Te=class extends f{constructor(e){super(it,e);}};var F=zod.z.object({apiKey:zod.z.string().min(1),resourceName:zod.z.string().min(1).optional(),baseUrl:zod.z.string().optional(),deploymentName:zod.z.string().min(1)});var I=class extends Ho{constructor(o,s){let i=F.parse(s),m;if(i.baseUrl)m=i.baseUrl;else if(i.resourceName)m=B.azureUrl(i.resourceName,"openai");else throw new X({info:"Either 'baseUrl' or 'resourceName' must be provided",cause:new Error("Either 'baseUrl' or 'resourceName' must be provided")});let r="2024-06-01",d=`${m}/openai/deployments/${i.deploymentName}`;super(o,{apiKey:i.apiKey,baseUrl:d,getEmbeddingsUrl:`${d}/embeddings?api-version=${r}`});this.version="v1";this.modelSchema=o,this.azureApiKey=i.apiKey,this.azureApiVersion=r;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}};var ya="text-embedding-3-large",Oe=Wo,Oa=F,ye=class extends I{constructor(e){super(Oe,e);}};var Pa="text-embedding-ada-002",rt=Vo,Sa=F,Pe=class extends I{constructor(e){super(rt,e);}};var va="text-embedding-3-small",lt=Jo,xa=F,Se=class extends I{constructor(e){super(lt,e);}};var ti="azure",B=class{constructor(){this.version="v1";this.name=ti;this.chatModelFactories={[Yo]:{model:re,modelOptions:Zo,modelSchema:le},[Xo]:{model:me,modelOptions:Qo,modelSchema:Ye},[ea]:{model:de,modelOptions:ta,modelSchema:Ze},[oa]:{model:pe,modelOptions:aa,modelSchema:Xe},[na]:{model:ce,modelOptions:sa,modelSchema:Qe},[ia]:{model:ue,modelOptions:ra,modelSchema:et},[la]:{model:he,modelOptions:ma,modelSchema:tt},[da]:{model:_e,modelOptions:pa,modelSchema:ot},[ca]:{model:ge,modelOptions:ua,modelSchema:at},[ga]:{model:be,modelOptions:fa,modelSchema:st},[ba]:{model:Te,modelOptions:Ta,modelSchema:it},[ha]:{model:fe,modelOptions:_a,modelSchema:nt}};this.embeddingModelFactories={[ya]:{model:ye,modelOptions:Oa,modelSchema:Oe},[Pa]:{model:Pe,modelOptions:Sa,modelSchema:rt},[va]:{model:Se,modelOptions:xa,modelSchema:lt}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModel(e,o){let s=xe({deploymentName:e},o),i=le;return i.name=s.deploymentName,new f(i,s)}chatModelSchema(e){if(!(e in this.chatModelFactories))throw new ae({info:`Azure chat model: ${e} not found`,cause:new Error(`Azure chat model: ${e} not found, available chat models:
|
|
14
|
+
${this.chatModelLiterals().join(", ")}`)});return this.chatModelFactories[e].modelSchema}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModel(e,o){let s=xe({deploymentName:e},o),i=Oe;return i.name=s.deploymentName,new I(i,s)}embeddingModelSchema(e){if(!(e in this.embeddingModelFactories))throw new ae({info:`Azure embedding model: ${e} not found`,cause:new Error(`Azure embedding model: ${e} not found, available embedding models:
|
|
17
15
|
${this.embeddingModelLiterals().join(", ")}`)});return this.embeddingModelFactories[e].modelSchema}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}};B.azureUrl=(e,o)=>`https://${e}.${o}.azure.com`;
|
|
18
16
|
|
|
19
17
|
exports.Azure = B;
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
18
|
+
exports.AzureChatModelOptions = b;
|
|
19
|
+
exports.AzureEmbeddingModelOptions = F;
|
|
20
|
+
exports.BaseChatModelOpenAI = f;
|
|
21
|
+
exports.BaseEmbeddingModelOpenAI = I;
|
|
22
|
+
exports.GPT_3_5_Turbo = fe;
|
|
24
23
|
exports.GPT_3_5_TurboLiteral = ha;
|
|
25
24
|
exports.GPT_3_5_TurboOptions = _a;
|
|
26
|
-
exports.GPT_3_5_TurboSchema =
|
|
27
|
-
exports.GPT_3_5_Turbo_0125 =
|
|
25
|
+
exports.GPT_3_5_TurboSchema = nt;
|
|
26
|
+
exports.GPT_3_5_Turbo_0125 = Te;
|
|
28
27
|
exports.GPT_3_5_Turbo_0125Literal = ba;
|
|
29
28
|
exports.GPT_3_5_Turbo_0125Options = Ta;
|
|
30
|
-
exports.GPT_3_5_Turbo_0125Schema =
|
|
31
|
-
exports.GPT_3_5_Turbo_1106 =
|
|
29
|
+
exports.GPT_3_5_Turbo_0125Schema = it;
|
|
30
|
+
exports.GPT_3_5_Turbo_1106 = be;
|
|
32
31
|
exports.GPT_3_5_Turbo_1106Literal = ga;
|
|
33
32
|
exports.GPT_3_5_Turbo_1106Options = fa;
|
|
34
|
-
exports.GPT_3_5_Turbo_1106Schema =
|
|
35
|
-
exports.GPT_4 =
|
|
33
|
+
exports.GPT_3_5_Turbo_1106Schema = st;
|
|
34
|
+
exports.GPT_4 = ue;
|
|
36
35
|
exports.GPT_4Literal = ia;
|
|
37
36
|
exports.GPT_4Options = ra;
|
|
38
|
-
exports.GPT_4Schema =
|
|
39
|
-
exports.GPT_4_0613 =
|
|
37
|
+
exports.GPT_4Schema = et;
|
|
38
|
+
exports.GPT_4_0613 = ge;
|
|
40
39
|
exports.GPT_4_0613Literal = ca;
|
|
41
40
|
exports.GPT_4_0613Options = ua;
|
|
42
|
-
exports.GPT_4_0613Schema =
|
|
43
|
-
exports.GPT_4_1106_Preview =
|
|
41
|
+
exports.GPT_4_0613Schema = at;
|
|
42
|
+
exports.GPT_4_1106_Preview = _e;
|
|
44
43
|
exports.GPT_4_1106_PreviewLiteral = da;
|
|
45
44
|
exports.GPT_4_1106_PreviewOptions = pa;
|
|
46
|
-
exports.GPT_4_1106_PreviewSchema =
|
|
47
|
-
exports.GPT_4_Turbo_2024_04_09 =
|
|
45
|
+
exports.GPT_4_1106_PreviewSchema = ot;
|
|
46
|
+
exports.GPT_4_Turbo_2024_04_09 = he;
|
|
48
47
|
exports.GPT_4_Turbo_2024_04_09Literal = la;
|
|
49
48
|
exports.GPT_4_Turbo_2024_04_09Options = ma;
|
|
50
|
-
exports.GPT_4_Turbo_2024_04_09Schema =
|
|
49
|
+
exports.GPT_4_Turbo_2024_04_09Schema = tt;
|
|
51
50
|
exports.GPT_4o = re;
|
|
52
51
|
exports.GPT_4oLiteral = Yo;
|
|
53
52
|
exports.GPT_4oOptions = Zo;
|
|
54
|
-
exports.GPT_4oSchema =
|
|
55
|
-
exports.GPT_4o_2024_05_13 =
|
|
53
|
+
exports.GPT_4oSchema = le;
|
|
54
|
+
exports.GPT_4o_2024_05_13 = ce;
|
|
56
55
|
exports.GPT_4o_2024_05_13Literal = na;
|
|
57
56
|
exports.GPT_4o_2024_05_13Options = sa;
|
|
58
|
-
exports.GPT_4o_2024_05_13Schema =
|
|
59
|
-
exports.GPT_4o_2024_08_06 =
|
|
57
|
+
exports.GPT_4o_2024_05_13Schema = Qe;
|
|
58
|
+
exports.GPT_4o_2024_08_06 = pe;
|
|
60
59
|
exports.GPT_4o_2024_08_06Literal = oa;
|
|
61
60
|
exports.GPT_4o_2024_08_06Options = aa;
|
|
62
|
-
exports.GPT_4o_2024_08_06Schema =
|
|
63
|
-
exports.GPT_4o_Mini =
|
|
61
|
+
exports.GPT_4o_2024_08_06Schema = Xe;
|
|
62
|
+
exports.GPT_4o_Mini = me;
|
|
64
63
|
exports.GPT_4o_MiniLiteral = Xo;
|
|
65
64
|
exports.GPT_4o_MiniOptions = Qo;
|
|
66
|
-
exports.GPT_4o_MiniSchema =
|
|
67
|
-
exports.GPT_4o_Mini_2024_07_18 =
|
|
65
|
+
exports.GPT_4o_MiniSchema = Ye;
|
|
66
|
+
exports.GPT_4o_Mini_2024_07_18 = de;
|
|
68
67
|
exports.GPT_4o_Mini_2024_07_18Literal = ea;
|
|
69
68
|
exports.GPT_4o_Mini_2024_07_18Options = ta;
|
|
70
|
-
exports.GPT_4o_Mini_2024_07_18Schema =
|
|
71
|
-
exports.Text_Embedding_3_Large =
|
|
69
|
+
exports.GPT_4o_Mini_2024_07_18Schema = Ze;
|
|
70
|
+
exports.Text_Embedding_3_Large = ye;
|
|
72
71
|
exports.Text_Embedding_3_LargeLiteral = ya;
|
|
73
72
|
exports.Text_Embedding_3_LargeOptions = Oa;
|
|
74
|
-
exports.Text_Embedding_3_LargeSchema =
|
|
75
|
-
exports.Text_Embedding_3_Small =
|
|
73
|
+
exports.Text_Embedding_3_LargeSchema = Oe;
|
|
74
|
+
exports.Text_Embedding_3_Small = Se;
|
|
76
75
|
exports.Text_Embedding_3_SmallLiteral = va;
|
|
77
76
|
exports.Text_Embedding_3_SmallOptions = xa;
|
|
78
77
|
exports.Text_Embedding_3_SmallSchema = lt;
|
|
79
|
-
exports.Text_Embedding_Ada_002 =
|
|
78
|
+
exports.Text_Embedding_Ada_002 = Pe;
|
|
80
79
|
exports.Text_Embedding_Ada_002Literal = Pa;
|
|
81
80
|
exports.Text_Embedding_Ada_002Options = Sa;
|
|
82
81
|
exports.Text_Embedding_Ada_002Schema = rt;
|