@adaline/azure 0.1.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/LICENSE +19 -0
- package/README.md +9 -0
- package/dist/index.d.mts +196 -0
- package/dist/index.d.ts +196 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z as z$1 } from 'zod';
|
|
2
|
+
|
|
3
|
+
var po=Object.defineProperty;var $e=Object.getOwnPropertySymbols;var uo=Object.prototype.hasOwnProperty,ho=Object.prototype.propertyIsEnumerable;var Fe=(o,e,t)=>e in o?po(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,me=(o,e)=>{for(var t in e||(e={}))uo.call(e,t)&&Fe(o,t,e[t]);if($e)for(var t of $e(e))ho.call(e,t)&&Fe(o,t,e[t]);return o};var go=o=>{let e=new WeakSet;return JSON.stringify(o,(t,s)=>{if(typeof s=="object"&&s!==null){if(e.has(s))return;e.add(s);}return s})},fo=o=>o==null?"unknown error":typeof o=="string"?o:o instanceof Error?o.message:go(o),de="GatewayBaseError",I=class ze extends Error{constructor({info:e,cause:t},s){super(`[${s!=null?s:de}]: ${e}
|
|
4
|
+
Message: ${fo(t)}`),this.name=de,this.info=e,this.cause=t,this.name=s!=null?s:de,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(e){return e instanceof ze}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},B="system",$="user",S="assistant",D="tool",bo=[B,$,S,D],ce=z$1.enum(bo),yo=[S],_o=z$1.enum(yo),k="image",pe="base64",To=["png","jpeg","webp","gif"],vo=z$1.object({type:z$1.literal(pe),base64:z$1.string(),media_type:z$1.enum(To)}),ue="url",So=z$1.object({type:z$1.literal(ue),url:z$1.string()}),Oo=z$1.discriminatedUnion("type",[vo,So]),xo=["low","medium","high","auto"],Eo=z$1.enum(xo),Mo=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(k),detail:Eo,value:Oo,metadata:o}),y="text",Ne=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(y),value:z$1.string(),metadata:o}),he="partial-text",Be=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(he),value:z$1.string(),metadata:o}),E="tool-call",De=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(E),index:z$1.number().int().nonnegative(),id:z$1.string().min(1),name:z$1.string().min(1),arguments:z$1.string(),metadata:o}),ge="partial-tool-call",Ke=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(ge),index:z$1.number().int().nonnegative(),id:z$1.string().optional(),name:z$1.string().optional(),arguments:z$1.string().optional(),metadata:o}),w="tool-response",Co=(o=z$1.undefined())=>z$1.object({modality:z$1.literal(w),index:z$1.number().int().nonnegative(),id:z$1.string().min(1),name:z$1.string().min(1),data:z$1.string(),metadata:o}),wo=[y,k,E,w],He=z$1.enum(wo),Po=(o=z$1.undefined(),e=z$1.undefined(),t=z$1.undefined(),s=z$1.undefined())=>z$1.discriminatedUnion("modality",[Ne(o),Mo(e),De(t),Co(s)]),jo=[he,ge];z$1.enum(jo);var Io=(o=z$1.undefined(),e=z$1.undefined())=>z$1.discriminatedUnion("modality",[Be(o),Ke(e)]);var K=(o=ce,e=z$1.undefined(),t=z$1.undefined(),s=z$1.undefined(),i=z$1.undefined(),m=z$1.undefined())=>z$1.object({role:o,content:z$1.array(Po(e,t,s,i)),metadata:m}),fe=(o=_o,e=z$1.undefined(),t=z$1.undefined(),s=z$1.undefined())=>z$1.object({role:o,partialContent:Io(e,t),metadata:s});var be=(o,e)=>K().parse({role:o,content:[Ne().parse({modality:y,value:e})]});var Je=(o,e,t,s,i)=>K().parse({role:o,content:[De().parse({modality:E,index:e,id:t,name:s,arguments:i})]});var ye=(o,e)=>fe().parse({role:o,partialContent:Be().parse({modality:he,value:e})}),We=(o,e,t,s,i)=>fe().parse({role:o,partialContent:Ke().parse({modality:ge,index:e,id:t,name:s,arguments:i})});var _e=(o=z$1.record(z$1.string(),z$1.any()).optional())=>o,ko=["object","array","number","string","boolean","enum"],Ge=z$1.enum(ko),Ro=z$1.object({anyOf:z$1.array(z$1.any()).optional(),type:z$1.union([Ge,z$1.array(z$1.union([Ge,z$1.literal("null")]))]).optional(),default:z$1.any().optional(),title:z$1.string().optional(),description:z$1.string().max(4096).optional(),properties:z$1.record(z$1.any()).optional(),required:z$1.array(z$1.string()).optional(),minItems:z$1.number().int().min(0).optional(),maxItems:z$1.number().int().optional(),items:z$1.record(z$1.any()).optional(),enum:z$1.array(z$1.union([z$1.string(),z$1.number(),z$1.boolean(),z$1.null()])).optional(),minimum:z$1.number().optional(),maximum:z$1.number().optional(),minLength:z$1.number().int().min(0).optional(),maxLength:z$1.number().int().optional(),$ref:z$1.string().optional()}),Ao=z$1.object({type:z$1.enum(["object"]),required:z$1.array(z$1.string()),$defs:z$1.record(z$1.any()).optional(),properties:z$1.record(Ro),additionalProperties:z$1.literal(!1)}),Ve=z$1.object({name:z$1.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:z$1.string().max(4096),strict:z$1.boolean().optional(),schema:Ao}).optional(),Lo="function";var $o=z$1.enum(["object","array","number","string","boolean","null"]),Fo=z$1.object({anyOf:z$1.array(z$1.any()).optional(),type:$o.optional(),default:z$1.any().optional(),title:z$1.string().optional(),description:z$1.string().max(4096).optional(),properties:z$1.record(z$1.any()).optional(),required:z$1.array(z$1.string()).optional(),minItems:z$1.number().int().min(0).optional(),maxItems:z$1.number().int().optional(),items:z$1.record(z$1.any()).optional(),enum:z$1.array(z$1.union([z$1.string(),z$1.number(),z$1.boolean(),z$1.null()])).optional(),minimum:z$1.number().optional(),maximum:z$1.number().optional(),minLength:z$1.number().int().min(0).optional(),maxLength:z$1.number().int().optional()});z$1.object({type:z$1.enum(["object"]),title:z$1.string().optional(),$defs:z$1.record(z$1.any()).optional(),properties:z$1.record(Fo).optional(),required:z$1.array(z$1.string()).optional()});var Go=z$1.object({name:z$1.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:z$1.string().max(4096),parameters:z$1.any(),strict:z$1.boolean().optional()});var qo=z$1.enum(["function"]),Uo=z$1.object({type:qo,definition:z$1.object({schema:Go})}),zo=[Lo];z$1.enum(zo);var Ye=(o=z$1.undefined())=>z$1.discriminatedUnion("type",[Uo.extend({metadata:o})]),R="text",G="token",No=[R,G],Ze=z$1.enum(No),Bo=z$1.array(z$1.string().min(1)),Do=z$1.array(z$1.array(z$1.number().int().nonnegative())),Qe=(o=z$1.undefined())=>z$1.discriminatedUnion("modality",[z$1.object({modality:z$1.literal(R),metadata:o,requests:Bo}),z$1.object({modality:z$1.literal(G),metadata:o,requests:Do})]),Te="float",Ko=z$1.object({index:z$1.number().int().nonnegative(),embedding:z$1.array(z$1.number())}),ve="base64",Ho=z$1.object({index:z$1.number().int().nonnegative(),embedding:z$1.string().base64()}),qe=z$1.object({totalTokens:z$1.number().int().nonnegative()});z$1.discriminatedUnion("encodingFormat",[z$1.object({encodingFormat:z$1.literal(Te),embeddings:z$1.array(Ko),usage:qe.optional()}),z$1.object({encodingFormat:z$1.literal(ve),embeddings:z$1.array(Ho),usage:qe.optional()})]);var Xe=z$1.object({promptTokens:z$1.number().nonnegative(),completionTokens:z$1.number().nonnegative(),totalTokens:z$1.number().nonnegative()}),Ue=z$1.object({token:z$1.string(),logProb:z$1.number(),bytes:z$1.array(z$1.number().int()).nullable()}),Jo=Ue.extend({topLogProbs:z$1.array(Ue)}),et=z$1.array(Jo);z$1.object({messages:z$1.array(K()),usage:Xe.optional(),logProbs:et.optional()});z$1.object({partialMessages:z$1.array(fe()),usage:Xe.optional(),logProbs:et.optional()});var Wo=Object.defineProperty,tt=Object.getOwnPropertySymbols,Vo=Object.prototype.hasOwnProperty,Yo=Object.prototype.propertyIsEnumerable,ot=(o,e,t)=>e in o?Wo(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,H=(o,e)=>{for(var t in e||(e={}))Vo.call(e,t)&&ot(o,t,e[t]);if(tt)for(var t of tt(e))Yo.call(e,t)&&ot(o,t,e[t]);return o},at="ProviderError",q=class dt extends I{constructor({info:e,cause:t}){super({info:e,cause:t},at),this.name=at,this.info=e,this.cause=t;}static isProviderError(e){return e instanceof dt}};var nt="ModelResponseError",U=class ct extends I{constructor({info:e,cause:t}){super({info:e,cause:t},nt),this.name=nt,this.cause=t,this.info=e;}static isModelResponseError(e){return e instanceof ct}},st="InvalidModelRequestError",J=class pt extends I{constructor({info:e,cause:t}){super({info:e,cause:t},st),this.name=st,this.cause=t,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(e){return e instanceof pt}},it="InvalidConfigError",P=class ut extends I{constructor({info:e,cause:t}){super({info:e,cause:t},it),this.name=it,this.cause=t,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(e){return e instanceof ut}},rt="InvalidMessagesError",M=class ht extends I{constructor({info:e,cause:t}){super({info:e,cause:t},rt),this.name=rt,this.cause=t,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(e){return e instanceof ht}},lt="InvalidToolsError",Se=class gt extends I{constructor({info:e,cause:t}){super({info:e,cause:t},lt),this.name=lt,this.cause=t,this.info=e,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(e){return e instanceof gt}},mt="InvalidEmbeddingRequestsError",ft=class bt extends I{constructor({info:e,cause:t}){super({info:e,cause:t},mt),this.name=mt,this.info=e,this.cause=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(e){return e instanceof bt}},Oe="multi-string",yt=z$1.object({type:z$1.literal(Oe),param:z$1.string().min(1),title:z$1.string().min(1),description:z$1.string().min(1).max(500),max:z$1.number().int().positive()}),Zo=o=>z$1.array(z$1.string()).max(o).default([]).optional(),_t=o=>({def:yt.parse(H({type:Oe},o)),schema:Zo(o.max)}),xe="range",Tt=z$1.object({type:z$1.literal(xe),param:z$1.string().min(1),title:z$1.string().min(1),description:z$1.string().min(1).max(500),min:z$1.number().int(),max:z$1.number().int(),step:z$1.number().positive(),default:z$1.number()}),Qo=(o,e,t,s)=>z$1.number().min(o).max(e).step(t).default(s).optional(),C=o=>({def:Tt.parse(H({type:xe},o)),schema:Qo(o.min,o.max,o.step,o.default)}),Ee="select-string",vt=z$1.object({type:z$1.literal(Ee),param:z$1.string().min(1),title:z$1.string().min(1),description:z$1.string().min(1).max(500),default:z$1.string().min(1).nullable(),choices:z$1.array(z$1.string().min(1))}),Xo=(o,e)=>z$1.enum(e).nullable().default(o).optional(),W=o=>({def:vt.parse(H({type:Ee},o)),schema:Xo(o.default,o.choices)}),Me="object-schema",St=z$1.object({type:z$1.literal(Me),param:z$1.string().min(1),title:z$1.string().min(1),description:z$1.string().min(1).max(500),objectSchema:z$1.any()}),ea=o=>o.optional(),Ot=o=>({def:St.parse(H({type:Me},o)),schema:ea(o.objectSchema)}),Ce="select-boolean",xt=z$1.object({type:z$1.literal(Ce),param:z$1.string().min(1),title:z$1.string().min(1),description:z$1.string().min(1).max(500),default:z$1.boolean().nullable()}),ta=o=>z$1.boolean().nullable().default(o).optional(),Et=o=>({def:xt.parse(H({type:Ce},o)),schema:ta(o.default)}),oa=[xe,Oe,Ee,Me,Ce];z$1.enum(oa);var Mt=z$1.discriminatedUnion("type",[Tt,yt,vt,xt,St]),v=(o=ce,e=He)=>z$1.object({name:z$1.string().min(1),description:z$1.string().min(1),roles:z$1.record(o,z$1.string().min(1).optional()),modalities:z$1.array(e).nonempty(),maxInputTokens:z$1.number().int().positive().min(1),maxOutputTokens:z$1.number().int().positive().min(1),config:z$1.object({def:z$1.record(z$1.string().min(1),Mt),schema:z$1.instanceof(z$1.ZodObject)}).refine(t=>{var s,i;let m=Object.keys(t.def),l=Object.keys((i=(s=t.schema)==null?void 0:s.shape)!=null?i:{});return m.every(d=>l.includes(d))&&l.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),Z=(o=Ze)=>z$1.object({name:z$1.string().min(1),description:z$1.string().min(1),modalities:z$1.array(o).nonempty(),maxInputTokens:z$1.number().int().positive().min(1),maxOutputTokens:z$1.number().int().positive().min(1),config:z$1.object({def:z$1.record(z$1.string().min(1),Mt),schema:z$1.instanceof(z$1.ZodObject)}).refine(e=>{var t,s;let i=Object.keys(e.def),m=Object.keys((s=(t=e.schema)==null?void 0:t.shape)!=null?s:{});return i.every(l=>m.includes(l))&&m.every(l=>i.includes(l))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})});z$1.record(z$1.string());z$1.record(z$1.union([z$1.boolean(),z$1.string(),z$1.number(),z$1.object({}),z$1.array(z$1.any()),z$1.null(),z$1.undefined()]));z$1.string().url();var aa={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."},na={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."},sa=o=>({type:"multi",title:"Stop sequence",description:`Enter up to ${o} sequences that will halt additional text output. The generated text will exclude these sequences.`}),ia={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."},ra={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."},la={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."},ma={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."},da={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."},ca={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."},pa={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."},ua={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."},ha={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."},ga={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."},fa={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},ba={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."},ya={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."},_a={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."},f={TEMPERATURE:aa,MAX_TOKENS:na,STOP:sa,TOP_A:ia,TOP_P:ra,TOP_K:la,MIN_P:ma,FREQUENCY_PENALTY:da,PRESENCE_PENALTY:ca,REPETITION_PENALTY:ua,SEED:pa,LOG_PROBS:ha,TOP_LOG_PROBS:ga,ECHO:fa,RESPONSE_FORMAT:ba,RESPONSE_FORMAT_WITH_SCHEMA:ya,RESPONSE_SCHEMA:_a};var we=o=>Object.fromEntries(Object.entries(o).filter(([e,t])=>t!=null));var Ct=o=>o.split(";")[0].split("/")[1],z=o=>o==null?void 0:o.replace(/\/$/,"");var Ta=Object.defineProperty,va=Object.defineProperties,Sa=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,Oa=Object.prototype.hasOwnProperty,xa=Object.prototype.propertyIsEnumerable,Ea=(o,e)=>(e=Symbol[o])?e:Symbol.for("Symbol."+o),Pt=(o,e,t)=>e in o?Ta(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,T=(o,e)=>{for(var t in e||(e={}))Oa.call(e,t)&&Pt(o,t,e[t]);if(wt)for(var t of wt(e))xa.call(e,t)&&Pt(o,t,e[t]);return o},X=(o,e)=>va(o,Sa(e)),j=(o,e,t)=>new Promise((s,i)=>{var m=p=>{try{d(t.next(p));}catch(c){i(c);}},l=p=>{try{d(t.throw(p));}catch(c){i(c);}},d=p=>p.done?s(p.value):Promise.resolve(p.value).then(m,l);d((t=t.apply(o,e)).next());}),Ma=function(o,e){this[0]=o,this[1]=e;},Ca=(o,e,t)=>{var s=(l,d,p,c)=>{try{var u=t[l](d),h=(d=u.value)instanceof Ma,_=u.done;Promise.resolve(h?d[0]:d).then(b=>h?s(l==="return"?l:"next",d[1]?{done:b.done,value:b.value}:b,p,c):p({value:b,done:_})).catch(b=>s("throw",b,p,c));}catch(b){c(b);}},i=l=>m[l]=d=>new Promise((p,c)=>s(l,d,p,c)),m={};return t=t.apply(o,e),m[Ea("asyncIterator")]=()=>m,i("next"),i("throw"),i("return"),m},jt=C({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),It=o=>C({param:"max_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),kt=o=>_t({param:"stop",title:f.STOP(o).title,description:f.STOP(o).description,max:o}),Rt=C({param:"top_p",title:f.TOP_P.title,description:f.TOP_P.description,min:0,max:1,step:.01,default:1}),At=C({param:"frequency_penalty",title:f.FREQUENCY_PENALTY.title,description:f.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Lt=C({param:"presence_penalty",title:f.PRESENCE_PENALTY.title,description:f.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),$t=C({param:"seed",title:f.SEED.title,description:f.SEED.description,min:0,max:1e6,step:1,default:0}),Ft=Et({param:"logprobs",title:f.LOG_PROBS.title,description:f.LOG_PROBS.description,default:!1}),Gt=C({param:"top_logprobs",title:f.TOP_LOG_PROBS.title,description:f.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),qt=W({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"]}),Pe=(o,e)=>z$1.object({temperature:jt.schema,maxTokens:It(o).schema,stop:kt(e).schema,topP:Rt.schema,frequencyPenalty:At.schema,presencePenalty:Lt.schema,seed:$t.schema.transform(t=>t===0?void 0:t),logProbs:Ft.schema,topLogProbs:Gt.schema,toolChoice:qt.schema}),je=(o,e)=>({temperature:jt.def,maxTokens:It(o).def,stop:kt(e).def,topP:Rt.def,frequencyPenalty:At.def,presencePenalty:Lt.def,seed:$t.def,logProbs:Ft.def,topLogProbs:Gt.def,toolChoice:qt.def}),Ut=W({param:"response_format",title:f.RESPONSE_FORMAT.title,description:f.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),wa=(o,e)=>X(T({},je(o,e)),{responseFormat:Ut.def}),Pa=(o,e)=>Pe(o,e).extend({responseFormat:Ut.schema}),zt=Ot({param:"response_schema",title:f.RESPONSE_SCHEMA.title,description:f.RESPONSE_SCHEMA.description,objectSchema:Ve}),Nt=W({param:"response_format",title:f.RESPONSE_FORMAT_WITH_SCHEMA.title,description:f.RESPONSE_FORMAT_WITH_SCHEMA.description,default:"text",choices:["text","json_object","json_schema"]}),Bt=(o,e)=>X(T({},je(o,e)),{responseFormat:Nt.def,responseSchema:zt.def}),Dt=(o,e)=>Pe(o,e).extend({responseFormat:Nt.schema,responseSchema:zt.schema}),Kt=C({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),Ht=o=>C({param:"max_completion_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:o,step:1,default:0}),ja=(o,e)=>X(T({},Bt(o,e)),{temperature:Kt.def,maxTokens:Ht(o).def}),Ia=(o,e)=>Dt(o,e).extend({temperature:Kt.schema,maxTokens:Ht(o).schema}),Jt=W({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),Wt=o=>C({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:o,step:1,default:o}),Vt=()=>z$1.object({encodingFormat:Jt.schema}),Yt=()=>({encodingFormat:Jt.def}),ka=o=>Vt().extend({dimensions:Wt(o).schema}),Ra=o=>X(T({},Yt()),{dimensions:Wt(o).def}),g={base:(o,e)=>({def:je(o,e),schema:Pe(o,e)}),responseFormat:(o,e)=>({def:wa(o,e),schema:Pa(o,e)}),responseSchema:(o,e)=>({def:Bt(o,e),schema:Dt(o,e)}),oSeries:(o,e)=>({def:ja(o,e),schema:Ia(o,e)})},N={base:()=>({def:Yt(),schema:Vt()}),dimensions:o=>({def:Ra(o),schema:ka(o)})},O=z$1.enum([B,$,S,D]),x={system:B,user:$,assistant:S,tool:D},Zt=z$1.enum([$,S]),Qt={user:$,assistant:S},V=[y,k,E,w],Y=z$1.enum([y,k,E,w]),Xt=[y],eo=z$1.enum([y]),A=[y,E,w],L=z$1.enum([y,E,w]),Q=z$1.object({token:z$1.string(),logprob:z$1.number(),bytes:z$1.array(z$1.number()).nullable()}),to=z$1.object({content:z$1.array(Q.extend({top_logprobs:z$1.array(Q)})).nullable(),refusal:z$1.array(Q.extend({top_logprobs:z$1.array(Q)})).nullable()}).nullable(),Aa=z$1.array(z$1.object({id:z$1.string().min(1),type:z$1.enum(["function"]),function:z$1.object({name:z$1.string(),arguments:z$1.string()})})),La=z$1.object({id:z$1.string(),object:z$1.literal("chat.completion"),created:z$1.number(),model:z$1.string(),system_fingerprint:z$1.string().nullable(),choices:z$1.array(z$1.object({index:z$1.number(),message:z$1.object({role:z$1.string(),content:z$1.string().nullable().optional(),tool_calls:Aa.optional(),refusal:z$1.string().nullable().optional()}),logprobs:to.optional(),finish_reason:z$1.string()})),usage:z$1.object({prompt_tokens:z$1.number(),completion_tokens:z$1.number(),total_tokens:z$1.number()})}),$a=z$1.array(z$1.object({index:z$1.number().int(),id:z$1.string().min(1).optional(),type:z$1.enum(["function"]).optional(),function:z$1.object({name:z$1.string().min(1).optional(),arguments:z$1.string().optional()}).optional()})),Fa=z$1.object({id:z$1.string(),object:z$1.string(),created:z$1.number(),model:z$1.string(),system_fingerprint:z$1.string().nullable(),choices:z$1.array(z$1.object({index:z$1.number(),delta:z$1.object({content:z$1.string().nullable().optional(),tool_calls:$a.optional(),refusal:z$1.string().nullable().optional()}).or(z$1.object({})),logprobs:to,finish_reason:z$1.string().nullable()})),usage:z$1.object({prompt_tokens:z$1.number(),completion_tokens:z$1.number(),total_tokens:z$1.number()}).nullable().optional()}),Ga=z$1.object({type:z$1.literal("function"),function:z$1.object({name:z$1.string().min(1),description:z$1.string().min(1).optional(),strict:z$1.boolean().optional(),parameters:z$1.any()})}),qa=z$1.enum(["none","auto","required"]),Ua=z$1.object({type:z$1.literal("function"),function:z$1.object({name:z$1.string().min(1)})}),za=z$1.object({type:z$1.enum(["text","json_object"])}).or(z$1.object({type:z$1.literal("json_schema"),json_schema:z$1.object({name:z$1.string().min(1),description:z$1.string().min(1).optional(),strict:z$1.boolean().optional(),schema:z$1.any()})})),Ie=z$1.object({text:z$1.string().min(1),type:z$1.literal("text")}),Na=z$1.object({type:z$1.literal("image_url"),image_url:z$1.object({url:z$1.string().url().min(1),detail:z$1.enum(["low","high","auto"]).optional()})}),Ba=z$1.object({id:z$1.string().min(1),type:z$1.literal("function"),function:z$1.object({name:z$1.string().min(1),arguments:z$1.string().min(1)})}),Da=z$1.object({role:z$1.literal("system"),content:z$1.string().min(1).or(z$1.array(Ie).min(1))}),Ka=z$1.object({role:z$1.literal("user"),content:z$1.string().min(1).or(z$1.array(z$1.union([Ie,Na])).min(1))}),Ha=z$1.object({role:z$1.literal("assistant"),content:z$1.string().min(1).or(z$1.array(Ie).min(1)).optional(),tool_calls:z$1.array(Ba).min(1).optional()}),Ja=z$1.object({role:z$1.literal("tool"),tool_call_id:z$1.string().min(1),content:z$1.string().min(1)}),Wa=z$1.union([Da,Ka,Ha,Ja]),oo=z$1.object({model:z$1.string().min(1).optional(),messages:z$1.array(Wa).min(1),frequency_penalty:z$1.number().min(-2).max(2).nullable().optional(),logprobs:z$1.boolean().nullable().optional(),top_logprobs:z$1.number().min(0).max(20).nullable().optional(),max_tokens:z$1.number().min(0).nullable().optional(),presence_penalty:z$1.number().min(-2).max(2).nullable().optional(),response_format:za.optional(),seed:z$1.number().nullable().optional(),stop:z$1.string().or(z$1.array(z$1.string()).max(4)).nullable().optional(),temperature:z$1.number().min(0).max(2).nullable().optional(),top_p:z$1.number().min(0).max(1).nullable().optional(),tools:z$1.array(Ga).optional(),tool_choice:qa.or(Ua).optional()});oo.omit({max_tokens:!0}).extend({max_completion_tokens:z$1.number().min(0).nullable().optional()});var Va=z$1.object({apiKey:z$1.string(),baseUrl:z$1.string().url(),completeChatUrl:z$1.string().url().optional(),streamChatUrl:z$1.string().url().optional(),organization:z$1.string().optional()}),ao=class{constructor(o,e){this.version="v1";let t=Va.parse(e);this.modelSchema=o,this.apiKey=t.apiKey,this.baseUrl=z(t.baseUrl),this.streamChatUrl=z(t.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=z(t.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=t.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return T({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(o){let e=l=>{let d=/(\d+)(h|m|s|ms)/g,p={h:36e5,m:6e4,s:1e3,ms:1},c,u=0;for(;(c=d.exec(l))!==null;){let h=parseInt(c[1]),_=c[2];u+=h*p[_];}return u},t=0,s=0,i=!0;o["x-ratelimit-reset-requests"]&&(t=e(o["x-ratelimit-reset-requests"])),o["x-ratelimit-reset-tokens"]&&(s=e(o["x-ratelimit-reset-tokens"]));let m=Math.max(t,s);return {shouldRetry:i,delayMs:m}}getTokenCount(o){return o.reduce((e,t)=>e+t.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(o){let e=oo.safeParse(o);if(!e.success)throw new J({info:"Invalid model request",cause:e.error});let t=e.data,s=t.model;if(t.tool_choice&&(!t.tools||t.tools.length===0))throw new J({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let i={};t.response_format&&(i.responseFormat=t.response_format.type,t.response_format.type==="json_schema"&&(i.responseSchema={name:t.response_format.json_schema.name,description:t.response_format.json_schema.description||"",strict:t.response_format.json_schema.strict,schema:t.response_format.json_schema.schema})),t.tool_choice&&(typeof t.tool_choice=="string"?i.toolChoice=t.tool_choice:i.toolChoice=t.tool_choice.function.name),i.seed=t.seed,i.maxTokens=t.max_tokens,i.temperature=t.temperature,i.topP=t.top_p,i.presencePenalty=t.presence_penalty,i.frequencyPenalty=t.frequency_penalty,i.stop=t.stop,i.logProbs=t.logprobs,i.topLogProbs=t.top_logprobs;let m=_e().parse(we(i)),l=[],d={};t.messages.forEach(c=>{let u=c.role;switch(u){case"system":{let h=c.content;if(typeof h=="string")l.push({role:u,content:[{modality:y,value:h}]});else {let _=h.map(b=>({modality:y,value:b.text}));l.push({role:u,content:_});}}break;case"user":{let h=c.content;if(typeof h=="string")l.push({role:u,content:[{modality:y,value:h}]});else {let _=h.map(b=>b.type==="text"?{modality:y,value:b.text}:b.image_url.url.startsWith("data:")?{modality:k,detail:b.image_url.detail||"auto",value:{type:pe,base64:b.image_url.url,media_type:Ct(b.image_url.url)}}:{modality:k,detail:b.image_url.detail||"auto",value:{type:ue,url:b.image_url.url}});l.push({role:u,content:_});}}break;case"assistant":{let h=[];if(!c.content&&!c.tool_calls)throw new J({info:`Invalid model request for model : '${this.modelSchema.name}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(c.content){let _=c.content;typeof _=="string"?h.push({modality:y,value:_}):_.forEach(b=>{h.push({modality:y,value:b.text});});}c.tool_calls&&c.tool_calls.forEach((_,b)=>{let le={modality:E,id:_.id,index:b,name:_.function.name,arguments:_.function.arguments};h.push(le),d[le.id]=le;}),l.push({role:u,content:h});}break;case"tool":{let h=c;l.push({role:u,content:[{modality:w,id:h.tool_call_id,index:d[h.tool_call_id].index,name:d[h.tool_call_id].name,data:h.content}]});}break}});let p=[];return t.tools&&t.tools.forEach(c=>{p.push({type:"function",definition:{schema:{name:c.function.name,description:c.function.description||"",strict:c.function.strict,parameters:c.function.parameters}}});}),{modelName:s,config:m,messages:l,tools:p.length>0?p:void 0}}transformConfig(o,e,t){let s=o.toolChoice;delete o.toolChoice;let i=this.modelSchema.config.schema.safeParse(o);if(!i.success)throw new P({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 P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${d}',
|
|
5
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let l=Object.keys(m).reduce((d,p)=>{let c=this.modelSchema.config.def[p],u=c.param,h=m[p];return u==="max_tokens"&&c.type==="range"&&h===0?d[u]=c.max:d[u]=h,d},{});if(l.top_logprobs&&!l.logprobs)throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in l&&l.tool_choice!==void 0){let d=l.tool_choice;if(!t||t&&t.length===0)throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(t&&t.length>0){let p=this.modelSchema.config.def.toolChoice;if(!p.choices.includes(d))if(t.map(c=>c.definition.schema.name).includes(d))l.tool_choice={type:"function",function:{name:d}};else throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
|
|
6
|
+
one of [${p.choices.join(", ")}]`)})}}if("response_format"in l&&l.response_format!==void 0){let d=l.response_format;if(d==="json_schema")if("response_schema"in l)l.response_format={type:"json_schema",json_schema:l.response_schema},delete l.response_schema;else throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else l.response_format={type:d};}return l}transformMessages(o){if(!o||o&&o.length===0)return {messages:[]};let e=o.map(t=>{let s=K().safeParse(t);if(!s.success)throw new M({info:"Invalid messages",cause:s.error});return s.data});return e.forEach(t=>{t.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new M({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support modality : '${s.modality}',
|
|
7
|
+
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),e.forEach(t=>{if(!Object.keys(this.modelSchema.roles).includes(t.role))throw new M({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support role : '${t.role}',
|
|
8
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:e.map(t=>{switch(t.role){case B:{let s=[];return t.content.forEach(i=>{if(i.modality===y)s.push({type:"text",text:i.value});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${i.modality}'`)})}),{role:this.modelSchema.roles[t.role],content:s}}case S:{let s=[],i=[];return t.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 M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${m.modality}'`)})}),T({role:this.modelSchema.roles[t.role],content:s},i.length>0?{tool_calls:i}:{})}case $:{let s=[],i=[];t.content.forEach(l=>{if(l.modality===y)s.push({type:"text",text:l.value});else if(l.modality===k)i.push({type:"image_url",image_url:{url:l.value.type==="url"?l.value.url:l.value.base64,detail:l.detail}});else throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${t.role}' cannot have content with modality : '${l.modality}'`)})});let m=[...s,...i];return {role:this.modelSchema.roles[t.role],content:m}}case D:{if(t.content.length!==1)throw new M({info:`Invalid message for role : '${t.role}'`,cause:new Error(`role : '${t.role}' must have exactly one content item`)});if(t.content[0].modality!==w)throw new M({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${t.role}' must have content with modality : '${w}'`)});let s=t.content[0];return {role:this.modelSchema.roles[t.role],tool_call_id:s.id,content:s.data}}default:throw new M({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`role : '${t.role}' is not supported,
|
|
9
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(o){if(!this.modelSchema.modalities.includes(E))throw new Se({info:`Invalid tool 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' does not support tool modality : '${E}'`)});return !o||o&&o.length===0?{tools:[]}:{tools:o.map(e=>{let t=Ye().safeParse(e);if(!t.success)throw new Se({info:"Invalid tools",cause:t.error});return t.data}).map(e=>({type:"function",function:e.definition.schema}))}}getCompleteChatUrl(o,e,t){return j(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(o,e,t){return j(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(o,e,t){return j(this,null,function*(){let s=this.transformConfig(o,e,t),i=this.transformMessages(e);if(i.messages&&i.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let m=t?this.transformTools(t):{};return new Promise(l=>{l(T(T(T(T({},this.getDefaultParams()),s),i),m));})})}transformCompleteChatResponse(o){let e=La.safeParse(o);if(e.success){if(e.data.choices.length===0)throw new U({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let t=e.data,s=[],i=t.choices[0].message;i.content&&s.push(be(S,i.content)),i.refusal&&s.push(be(S,i.refusal)),i.tool_calls&&i.tool_calls.forEach((p,c)=>{s.push(Je(S,c,p.id,p.function.name,p.function.arguments));});let m={promptTokens:t.usage.prompt_tokens,completionTokens:t.usage.completion_tokens,totalTokens:t.usage.total_tokens},l=[],d=t.choices[0].logprobs;return d&&(d.content&&l.push(...d.content.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes,topLogProbs:p.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))}))),d.refusal&&l.push(...d.refusal.map(p=>({token:p.token,logProb:p.logprob,bytes:p.bytes,topLogProbs:p.top_logprobs.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes}))})))),{messages:s,usage:m,logProbs:l}}throw new U({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(o,e,t){return j(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(o,e,t){return j(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(o,e,t){return j(this,null,function*(){let s=this.transformConfig(o,e,t),i=this.transformMessages(e);if(i.messages&&i.messages.length===0)throw new M({info:"Messages are required",cause:new Error("Messages are required")});let m=t?this.transformTools(t):{};return new Promise(l=>{l(T(T(T(T({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),i),m));})})}transformStreamChatResponseChunk(o,e){return Ca(this,null,function*(){var t,s;let i=(e+o).split(`
|
|
10
|
+
`).filter(m=>m.trim()!=="");for(let m of i){if(m==="data: [DONE]")return;if(m.startsWith("data: {")&&m.endsWith("}")){let l;try{l=JSON.parse(m.substring(6));}catch(p){throw new U({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${l}`)})}let d=Fa.safeParse(l);if(d.success){let p={partialMessages:[]},c=d.data;if(c.choices.length>0){let u=c.choices[0].delta;if(u!==void 0&&Object.keys(u).length!==0){if("content"in u&&u.content!==null)p.partialMessages.push(ye(S,u.content));else if("refusal"in u&&u.refusal!==null)p.partialMessages.push(ye(S,u.refusal));else if("tool_calls"in u&&u.tool_calls!==void 0){let h=u.tool_calls.at(0);p.partialMessages.push(We(S,h.index,h.id,(t=h.function)==null?void 0:t.name,(s=h.function)==null?void 0:s.arguments));}}}c.usage&&(p.usage={promptTokens:c.usage.prompt_tokens,completionTokens:c.usage.completion_tokens,totalTokens:c.usage.total_tokens}),yield {partialResponse:p,buffer:e};}else throw new U({info:"Invalid response from model",cause:d.error})}}})}};var Ya="gpt-3.5-turbo-0125",Za="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.";v(O,L).parse({name:Ya,description:Za,maxInputTokens:4092,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.responseFormat(4092,4).def,schema:g.responseFormat(4092,4).schema}});var Qa="gpt-3.5-turbo-1106",Xa="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.";v(O,L).parse({name:Qa,description:Xa,maxInputTokens:4092,maxOutputTokens:16385,roles:x,modalities:A,config:{def:g.responseFormat(16385,4).def,schema:g.responseFormat(16385,4).schema}});var en="gpt-3.5-turbo",tn="Currently points to gpt-3.5-turbo-0125. Training data up to Sept 2021.";v(O,L).parse({name:en,description:tn,maxInputTokens:4092,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.responseFormat(4092,4).def,schema:g.responseFormat(4092,4).schema}});var on="gpt-4-0125-preview",an="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.";v(O,L).parse({name:on,description:an,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.base(4092,4).def,schema:g.base(4092,4).schema}});var nn="gpt-4-0613",sn="Snapshot of gpt-4 from June 13th 2023 with improved function calling support. Training data up to Sept 2021.";v(O,L).parse({name:nn,description:sn,maxInputTokens:8192,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.base(4092,4).def,schema:g.base(4092,4).schema}});var rn="gpt-4-1106-preview",ln="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.";v(O,L).parse({name:rn,description:ln,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.base(4092,4).def,schema:g.base(4092,4).schema}});var mn="gpt-4-turbo-2024-04-09",dn="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.";v(O,Y).parse({name:mn,description:dn,maxInputTokens:128e3,maxOutputTokens:4096,roles:x,modalities:V,config:{def:g.responseFormat(4096,4).def,schema:g.responseFormat(4096,4).schema}});var cn="gpt-4-turbo-preview",pn="Currently points to gpt-4-0125-preview. Training data up to Apr 2023.";v(O,L).parse({name:cn,description:pn,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.responseFormat(4092,4).def,schema:g.responseFormat(4092,4).schema}});var un="gpt-4-turbo",hn="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.";v(O,Y).parse({name:un,description:hn,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:V,config:{def:g.responseFormat(4092,4).def,schema:g.responseFormat(4092,4).schema}});var gn="gpt-4",fn="Currently points to gpt-4-0613. Training data up to Sept 2021.";v(O,L).parse({name:gn,description:fn,maxInputTokens:8192,maxOutputTokens:4092,roles:x,modalities:A,config:{def:g.base(4092,4).def,schema:g.base(4092,4).schema}});var bn="gpt-4o-2024-08-06",yn="Latest snapshot of gpt-4o that supports Structured Outputs. Training data up to Oct 2023.";v(O,Y).parse({name:bn,description:yn,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:V,config:{def:g.responseSchema(4092,4).def,schema:g.responseSchema(4092,4).schema}});var _n="gpt-4o-mini",Tn="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.";v(O,Y).parse({name:_n,description:Tn,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:V,config:{def:g.responseSchema(4092,4).def,schema:g.responseSchema(4092,4).schema}});var vn="gpt-4o",Sn="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=v(O,Y).parse({name:vn,description:Sn,maxInputTokens:128e3,maxOutputTokens:4092,roles:x,modalities:V,config:{def:g.responseFormat(4092,4).def,schema:g.responseFormat(4092,4).schema}});var On="o1-mini",xn="Faster and cheaper reasoning model particularly good at coding, math, and science. Training data up to Oct 2023.";v(Zt,eo).parse({name:On,description:xn,maxInputTokens:128e3,maxOutputTokens:4092,roles:Qt,modalities:Xt,config:{def:g.oSeries(4092,4).def,schema:g.oSeries(4092,4).schema}});var En="o1-preview",Mn="Reasoning model designed to solve hard problems across domains. Training data up to Oct 2023.";v(Zt,eo).parse({name:En,description:Mn,maxInputTokens:128e3,maxOutputTokens:4092,roles:Qt,modalities:Xt,config:{def:g.oSeries(4092,4).def,schema:g.oSeries(4092,4).schema}});var ke=[R,G],Re=z$1.enum([R,G]),Cn=z$1.object({object:z$1.literal("list"),model:z$1.string(),data:z$1.array(z$1.object({index:z$1.number(),object:z$1.literal("embedding"),embedding:z$1.array(z$1.number()).or(z$1.string().base64())})),usage:z$1.object({prompt_tokens:z$1.number().nonnegative(),total_tokens:z$1.number().nonnegative()})}),wn=z$1.string().min(1).or(z$1.array(z$1.string().min(1)).min(1)).or(z$1.array(z$1.number().int().nonnegative()).min(1)).or(z$1.array(z$1.array(z$1.number().int().nonnegative()).min(1)).min(1)),Pn=z$1.object({model:z$1.string().min(1).optional(),input:wn,encoding_format:z$1.enum(["float","base64"]).optional(),dimensions:z$1.number().int().min(1).optional()}),jn=z$1.object({apiKey:z$1.string(),baseUrl:z$1.string().url(),getEmbeddingsUrl:z$1.string().url().optional()}),so=class{constructor(o,e){this.version="v1";let t=jn.parse(e);this.modelSchema=o,this.apiKey=t.apiKey,this.baseUrl=z(t.baseUrl),this.getEmbeddingsUrl=z(t.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(o){let e=l=>{let d=/(\d+)(h|m|s|ms)/g,p={h:36e5,m:6e4,s:1e3,ms:1},c,u=0;for(;(c=d.exec(l))!==null;){let h=parseInt(c[1]),_=c[2];u+=h*p[_];}return u},t=0,s=0,i=!0;o["x-ratelimit-reset-requests"]&&(t=e(o["x-ratelimit-reset-requests"])),o["x-ratelimit-reset-tokens"]&&(s=e(o["x-ratelimit-reset-tokens"]));let m=Math.max(t,s);return {shouldRetry:i,delayMs:m}}getTokenCount(o){return o.requests.reduce((e,t)=>e+t.length,0)}transformModelRequest(o){let e=Pn.safeParse(o);if(!e.success)throw new J({info:"Invalid model request",cause:e.error});let t=e.data,s=t.model,i={encodingFormat:t.encoding_format,dimensions:t.dimensions},m=_e().parse(we(i)),l,d;return typeof t.input=="string"?d=R:typeof t.input[0]=="string"?d=R:d=G,d===R?typeof t.input=="string"?l={modality:d,requests:[t.input]}:l={modality:d,requests:t.input}:typeof t.input[0]=="number"?l={modality:d,requests:[t.input]}:l={modality:d,requests:t.input},{modelName:s,config:m,embeddingRequests:l}}transformConfig(o,e){let t=this.modelSchema.config.schema.safeParse(o);if(!t.success)throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:t.error});let s=t.data;return Object.keys(s).forEach(i=>{if(!this.modelSchema.config.def[i])throw new P({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${i}',
|
|
11
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((i,m)=>{let l=this.modelSchema.config.def[m].param,d=s[m];return i[l]=d,i},{})}transformEmbeddingRequests(o){let e=Qe().safeParse(o);if(!e.success)throw new ft({info:"Invalid embedding requests",cause:e.error});return {input:e.data.requests}}getGetEmbeddingsUrl(o,e){return j(this,null,function*(){return new Promise(t=>{t(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(o,e){return j(this,null,function*(){return new Promise(t=>{t(this.getDefaultHeaders());})})}getGetEmbeddingsData(o,e){return j(this,null,function*(){return new Promise(t=>{t(T(T(T({},this.getDefaultParams()),this.transformConfig(o,e)),this.transformEmbeddingRequests(e)));})})}transformGetEmbeddingsResponse(o){let e,t=Cn.safeParse(o);if(t.success){let s=t.data;e=typeof s.data[0].embedding=="string"?ve:Te;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 U({info:"Invalid response from model",cause:t.error})}},In="text-embedding-ada-002",kn="Most capable 2nd generation embedding model, replacing 16 first generation models";Z(Re).parse({name:In,description:kn,modalities:ke,maxInputTokens:8192,maxOutputTokens:1536,config:{def:N.base().def,schema:N.base().schema}});var Rn="text-embedding-3-small",An="Increased performance over 2nd generation ada embedding model";Z(Re).parse({name:Rn,description:An,modalities:ke,maxInputTokens:8192,maxOutputTokens:1536,config:{def:N.dimensions(1536).def,schema:N.dimensions(1536).schema}});var Ln="text-embedding-3-large",$n="Most capable embedding model for both english and non-english tasks",io=Z(Re).parse({name:Ln,description:$n,modalities:ke,maxInputTokens:8192,maxOutputTokens:3072,config:{def:N.dimensions(3072).def,schema:N.dimensions(3072).schema}});var te=z$1.object({resourceName:z$1.string().min(1),deploymentName:z$1.string().min(1),apiKey:z$1.string().min(1)});var oe=class extends ao{constructor(t,s){let i=te.parse(s),m=F.azureUrl(i.resourceName,i.deploymentName,"openai");super(t,{apiKey:i.apiKey,baseUrl:m,completeChatUrl:`${m}/chat/completions?api-version=2023-03-15-preview`,streamChatUrl:`${m}/chat/completions?api-version=2023-03-15-preview`});this.version="v1";this.modelSchema=t,this.azureApiKey=i.apiKey;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}};var ro="gpt-4o",Ae=no,lo=te,ae=class extends oe{constructor(e){super(Ae,e);}};var se=z$1.object({resourceName:z$1.string().min(1),deploymentName:z$1.string().min(1),apiKey:z$1.string().min(1)});var ie=class extends so{constructor(t,s){let i=se.parse(s),m=F.azureUrl(i.resourceName,i.deploymentName,"openai");super(t,{apiKey:i.apiKey,baseUrl:m,getEmbeddingsUrl:`${m}/embeddings?api-version=2023-03-15-preview`});this.version="v1";this.modelSchema=t,this.azureApiKey=i.apiKey;}getDefaultHeaders(){return {"Content-Type":"application/json","api-key":this.azureApiKey,source:"adaline"}}};var mo="text-embedding-3-large",Le=io,co=se,re=class extends ie{constructor(e){super(Le,e);}};var Fn="azure",F=class{constructor(){this.version="v1";this.name=Fn;this.chatModelFactories={[ro]:{model:ae,modelOptions:lo,modelSchema:Ae}};this.embeddingModelFactories={[mo]:{model:re,modelOptions:co,modelSchema:Le}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModel(e,t){if(!(e in this.chatModelFactories))throw new q({info:`Azure chat model: ${e} not found`,cause:new Error(`Azure chat model: ${e} not found, available chat models:
|
|
12
|
+
${this.chatModelLiterals().join(", ")}`)});let s=this.chatModelFactories[e].model,i=me({},t),m=this.chatModelFactories[e].modelOptions.parse(i);return new s(m)}chatModelSchema(e){if(!(e in this.chatModelFactories))throw new q({info:`Azure chat model: ${e} not found`,cause:new Error(`Azure chat model: ${e} not found, available chat models:
|
|
13
|
+
${this.chatModelLiterals().join(", ")}`)});return this.chatModelFactories[e].modelSchema}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModel(e,t){if(!(e in this.embeddingModelFactories))throw new q({info:`Azure embedding model: ${e} not found`,cause:new Error(`Azure embedding model: ${e} not found, available embedding models:
|
|
14
|
+
${this.embeddingModelLiterals().join(", ")}`)});let s=this.embeddingModelFactories[e].model,i=me({},t),m=this.embeddingModelFactories[e].modelOptions.parse(i);return new s(m)}embeddingModelSchema(e){if(!(e in this.embeddingModelFactories))throw new q({info:`Azure embedding model: ${e} not found`,cause:new Error(`Azure embedding model: ${e} not found, available embedding models:
|
|
15
|
+
${this.embeddingModelLiterals().join(", ")}`)});return this.embeddingModelFactories[e].modelSchema}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}};F.azureUrl=(e,t,s)=>`https://${e}.${s}.azure.com/${s}/deployments/${t}`;
|
|
16
|
+
|
|
17
|
+
export { F as Azure, se as AzureEmbeddingModelOptions, oe as BaseChatModelOpenAI, ie as BaseEmbeddingModelOpenAI, ae as GPT_4o, ro as GPT_4oLiteral, lo as GPT_4oOptions, Ae as GPT_4oSchema, re as Text_Embedding_3_Large, mo as Text_Embedding_3_LargeLiteral, co as Text_Embedding_3_LargeOptions, Le as Text_Embedding_3_LargeSchema };
|
|
18
|
+
//# sourceMappingURL=index.mjs.map
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|