@adaline/custom 0.2.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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -43,7 +43,7 @@ declare const BaseChatModelSchema: {
|
|
|
43
43
|
param: string;
|
|
44
44
|
title: string;
|
|
45
45
|
description: string;
|
|
46
|
-
default: string
|
|
46
|
+
default: string;
|
|
47
47
|
choices: string[];
|
|
48
48
|
}>;
|
|
49
49
|
schema: zod.ZodObject<zod.ZodRawShape, zod.UnknownKeysParam, zod.ZodTypeAny, unknown, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare const BaseChatModelSchema: {
|
|
|
43
43
|
param: string;
|
|
44
44
|
title: string;
|
|
45
45
|
description: string;
|
|
46
|
-
default: string
|
|
46
|
+
default: string;
|
|
47
47
|
choices: string[];
|
|
48
48
|
}>;
|
|
49
49
|
schema: zod.ZodObject<zod.ZodRawShape, zod.UnknownKeysParam, zod.ZodTypeAny, unknown, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
5
|
var de=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),oa=e=>{throw TypeError(e)};var aa=function(e,t){this[0]=e,this[1]=t;};var ce=e=>{var t=e[de("asyncIterator")],o=!1,s,r={};return t==null?(t=e[de("iterator")](),s=m=>r[m]=i=>t[m](i)):(t=t.call(e),s=m=>r[m]=i=>{if(o){if(o=!1,m==="throw")throw i;return i}return o=!0,{done:!1,value:new aa(new Promise(d=>{var c=t[m](i);c instanceof Object||oa("Object expected"),d(c);}),1)}}),r[de("iterator")]=()=>r,s("next"),"throw"in t?s("throw"):r.throw=m=>{throw m},"return"in t&&s("return"),r};var na=e=>{let t=new WeakSet;return JSON.stringify(e,(o,s)=>{if(typeof s=="object"&&s!==null){if(t.has(s))return;t.add(s);}return s})},sa=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:na(e),pe="GatewayBaseError",A=class We extends Error{constructor({info:t,cause:o},s){super(`[${s!=null?s:pe}]: ${t}
|
|
6
|
-
Message: ${sa(o)}`),this.name=pe,this.info=t,this.cause=o,this.name=s!=null?s:pe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof We}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Y="system",U="user",E="assistant",V="tool",ra=[Y,U,E,V],ue=zod.z.enum(ra),ia=[E],la=zod.z.enum(ia),N="image",he="base64",ma=["png","jpeg","webp","gif"],da=zod.z.object({type:zod.z.literal(he),base64:zod.z.string(),media_type:zod.z.enum(ma)}),ge="url",ca=zod.z.object({type:zod.z.literal(ge),url:zod.z.string()}),pa=zod.z.discriminatedUnion("type",[da,ca]),ua=["low","medium","high","auto"],ha=zod.z.enum(ua),ga=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),detail:ha,value:pa,metadata:e}),v="text",Ye=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(v),value:zod.z.string(),metadata:e}),fe="partial-text",Ve=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(fe),value:zod.z.string(),metadata:e}),w="tool-call",Ze=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(w),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:e}),be="partial-tool-call",Qe=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(be),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),R="tool-response",fa=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(R),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:e}),ba=[v,N,w,R],Xe=zod.z.enum(ba),ya=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ye(e),ga(t),Ze(o),fa(s)]),_a=[fe,be];zod.z.enum(_a);var Ta=(e=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ve(e),Qe(t)]);var ye=(e=ue,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(ya(t,o,s,r)),metadata:m}),_e=(e=la,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:e,partialContent:Ta(t,o),metadata:s}),Te=e=>Ye().parse({modality:v,value:e}),et=(e,t,o,s)=>Ze().parse({modality:w,index:e,id:t,name:o,arguments:s});var ve=(e,t)=>_e().parse({role:e,partialContent:Ve().parse({modality:fe,value:t})}),tt=(e,t,o,s,r)=>_e().parse({role:e,partialContent:Qe().parse({modality:be,index:t,id:o,name:s,arguments:r})});var Oe=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,va=["object","array","number","string","boolean","enum"],He=zod.z.enum(va),Oa=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([He,zod.z.array(zod.z.union([He,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()}),Sa=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(Oa),additionalProperties:zod.z.literal(!1)}),ot=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:Sa}).optional(),xa="function";var Ca=zod.z.enum(["object","array","number","string","boolean","null"]),Ma=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ca.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(Ma).optional(),required:zod.z.array(zod.z.string()).optional()});var Pa=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 Ea=zod.z.enum(["function"]),wa=zod.z.object({type:Ea,definition:zod.z.object({schema:Pa})}),Ia=[xa];zod.z.enum(Ia);var at=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[wa.extend({metadata:e})]),q="text",D="token",ka=[q,D],nt=zod.z.enum(ka),ja=zod.z.array(zod.z.string().min(1)),Ra=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),st=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(q),metadata:e,requests:ja}),zod.z.object({modality:zod.z.literal(D),metadata:e,requests:Ra})]),Se="float",La=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),xe="base64",Aa=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Ke=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Se),embeddings:zod.z.array(La),usage:Ke.optional()}),zod.z.object({encodingFormat:zod.z.literal(xe),embeddings:zod.z.array(Aa),usage:Ke.optional()})]);var rt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Je=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ga=Je.extend({topLogProbs:zod.z.array(Je)}),it=zod.z.array(Ga);zod.z.object({messages:zod.z.array(ye()),usage:rt.optional(),logProbs:it.optional()});zod.z.object({partialMessages:zod.z.array(_e()),usage:rt.optional(),logProbs:it.optional()});var Na=Object.defineProperty,lt=Object.getOwnPropertySymbols,qa=Object.prototype.hasOwnProperty,$a=Object.prototype.propertyIsEnumerable,mt=(e,t,o)=>t in e?Na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,Z=(e,t)=>{for(var o in t||(t={}))qa.call(t,o)&&mt(e,o,t[o]);if(lt)for(var o of lt(t))$a.call(t,o)&&mt(e,o,t[o]);return e},dt="ProviderError",Q=class yt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},dt),this.name=dt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof yt}},ct="ModelError",B=class _t extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ct),this.name=ct,this.info=t,this.cause=o;}static isModelError(t){return t instanceof _t}},pt="ModelResponseError",z=class Tt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},pt),this.name=pt,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Tt}},ut="InvalidModelRequestError",H=class vt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ut),this.name=ut,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof vt}},ht="InvalidConfigError",G=class Ot extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ht),this.name=ht,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Ot}},gt="InvalidMessagesError",I=class St extends A{constructor({info:t,cause:o}){super({info:t,cause:o},gt),this.name=gt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof St}},ft="InvalidToolsError",Ce=class xt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ft),this.name=ft,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof xt}},bt="InvalidEmbeddingRequestsError",Ct=class Mt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},bt),this.name=bt,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Mt}},Me="multi-string",Pt=zod.z.object({type:zod.z.literal(Me),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()}),Fa=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Et=e=>({def:Pt.parse(Z({type:Me},e)),schema:Fa(e.max)}),Pe="object-schema",wt=zod.z.object({type:zod.z.literal(Pe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Ua=e=>e.optional(),It=e=>({def:wt.parse(Z({type:Pe},e)),schema:Ua(e.objectSchema)}),Ee="range",kt=zod.z.object({type:zod.z.literal(Ee),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()}),Ba=(e,t,o,s)=>zod.z.number().min(e).max(t).step(o).default(s).optional(),L=e=>({def:kt.parse(Z({type:Ee},e)),schema:Ba(e.min,e.max,e.step,e.default)}),we="select-boolean",jt=zod.z.object({type:zod.z.literal(we),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()}),Da=e=>zod.z.boolean().nullable().default(e).optional(),Rt=e=>({def:jt.parse(Z({type:we},e)),schema:Da(e.default)}),Ie="select-string",Lt=zod.z.object({type:zod.z.literal(Ie),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))}),za=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),X=e=>({def:Lt.parse(Z({type:Ie},e)),schema:za(e.default,e.choices)}),Ha=[Ee,Me,Ie,Pe,we];zod.z.enum(Ha);var At=zod.z.discriminatedUnion("type",[kt,Pt,Lt,jt,wt]),_=(e=ue,t=Xe)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),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),At),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,r;let m=Object.keys(o.def),i=Object.keys((r=(s=o.schema)==null?void 0:s.shape)!=null?r:{});return m.every(d=>i.includes(d))&&i.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),oe=(e=nt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),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),At),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,s;let r=Object.keys(t.def),m=Object.keys((s=(o=t.schema)==null?void 0:o.shape)!=null?s:{});return r.every(i=>m.includes(i))&&m.every(i=>r.includes(i))},{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 Ka={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."},Ja={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."},Wa=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Ya={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."},Va={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."},Za={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."},Qa={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."},Xa={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."},en={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."},tn={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."},on={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."},an={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."},nn={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."},sn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},rn={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."},ln={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."},mn={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:Ka,MAX_TOKENS:Ja,STOP:Wa,TOP_A:Ya,TOP_P:Va,TOP_K:Za,MIN_P:Qa,FREQUENCY_PENALTY:Xa,PRESENCE_PENALTY:en,REPETITION_PENALTY:on,SEED:tn,LOG_PROBS:an,TOP_LOG_PROBS:nn,ECHO:sn,RESPONSE_FORMAT:rn,RESPONSE_FORMAT_WITH_SCHEMA:ln,RESPONSE_SCHEMA:mn};var ke=e=>Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null));var Gt=e=>e.split(";")[0].split("/")[1],K=e=>e==null?void 0:e.replace(/\/$/,"");var dn=Object.defineProperty,cn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertySymbols,un=Object.prototype.hasOwnProperty,hn=Object.prototype.propertyIsEnumerable,ne=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),gn=e=>{throw TypeError(e)},qt=(e,t,o)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))un.call(t,o)&&qt(e,o,t[o]);if(Nt)for(var o of Nt(t))hn.call(t,o)&&qt(e,o,t[o]);return e},ee=(e,t)=>cn(e,pn(t)),M=(e,t,o)=>new Promise((s,r)=>{var m=c=>{try{d(o.next(c));}catch(p){r(p);}},i=c=>{try{d(o.throw(c));}catch(p){r(p);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,i);d((o=o.apply(e,t)).next());}),$t=function(e,t){this[0]=e,this[1]=t;},se=(e,t,o)=>{var s=(i,d,c,p)=>{try{var b=o[i](d),h=(d=b.value)instanceof $t,y=b.done;Promise.resolve(h?d[0]:d).then(g=>h?s(i==="return"?i:"next",d[1]?{done:g.done,value:g.value}:g,c,p):c({value:g,done:y})).catch(g=>s("throw",g,c,p));}catch(g){p(g);}},r=i=>m[i]=d=>new Promise((c,p)=>s(i,d,c,p)),m={};return o=o.apply(e,t),m[ne("asyncIterator")]=()=>m,r("next"),r("throw"),r("return"),m},Ft=e=>{var t=e[ne("asyncIterator")],o=!1,s,r={};return t==null?(t=e[ne("iterator")](),s=m=>r[m]=i=>t[m](i)):(t=t.call(e),s=m=>r[m]=i=>{if(o){if(o=!1,m==="throw")throw i;return i}return o=!0,{done:!1,value:new $t(new Promise(d=>{var c=t[m](i);c instanceof Object||gn("Object expected"),d(c);}),1)}}),r[ne("iterator")]=()=>r,s("next"),"throw"in t?s("throw"):r.throw=m=>{throw m},"return"in t&&s("return"),r},Ut=L({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),Bt=e=>L({param:"max_completion_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),Dt=e=>Et({param:"stop",title:f.STOP(e).title,description:f.STOP(e).description,max:e}),zt=L({param:"top_p",title:f.TOP_P.title,description:f.TOP_P.description,min:0,max:1,step:.01,default:1}),Ht=L({param:"frequency_penalty",title:f.FREQUENCY_PENALTY.title,description:f.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Kt=L({param:"presence_penalty",title:f.PRESENCE_PENALTY.title,description:f.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Jt=L({param:"seed",title:f.SEED.title,description:f.SEED.description,min:0,max:1e6,step:1,default:0}),Wt=Rt({param:"logprobs",title:f.LOG_PROBS.title,description:f.LOG_PROBS.description,default:!1}),Yt=L({param:"top_logprobs",title:f.TOP_LOG_PROBS.title,description:f.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),Vt=X({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"]}),je=(e,t)=>zod.z.object({temperature:Ut.schema,maxTokens:Bt(e).schema,stop:Dt(t).schema,topP:zt.schema,frequencyPenalty:Ht.schema,presencePenalty:Kt.schema,seed:Jt.schema.transform(o=>o===0?void 0:o),logProbs:Wt.schema,topLogProbs:Yt.schema,toolChoice:Vt.schema}),Re=(e,t)=>({temperature:Ut.def,maxTokens:Bt(e).def,stop:Dt(t).def,topP:zt.def,frequencyPenalty:Ht.def,presencePenalty:Kt.def,seed:Jt.def,logProbs:Wt.def,topLogProbs:Yt.def,toolChoice:Vt.def}),Zt=It({param:"response_schema",title:f.RESPONSE_SCHEMA.title,description:f.RESPONSE_SCHEMA.description,objectSchema:ot}),Qt=X({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"]}),Xt=(e,t)=>ee(O({},Re(e,t)),{responseFormat:Qt.def,responseSchema:Zt.def}),eo=(e,t)=>je(e,t).extend({responseFormat:Qt.schema,responseSchema:Zt.schema}),to=L({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),fn=(e,t)=>ee(O({},Xt(e,t)),{temperature:to.def}),bn=(e,t)=>eo(e,t).extend({temperature:to.schema}),oo=X({param:"response_format",title:f.RESPONSE_FORMAT.title,description:f.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),yn=(e,t)=>ee(O({},Re(e,t)),{responseFormat:oo.def}),_n=(e,t)=>je(e,t).extend({responseFormat:oo.schema}),ao=X({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),no=e=>L({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:e,step:1,default:e}),so=()=>zod.z.object({encodingFormat:ao.schema}),ro=()=>({encodingFormat:ao.def}),Tn=e=>so().extend({dimensions:no(e).schema}),vn=e=>ee(O({},ro()),{dimensions:no(e).def}),u={base:(e,t)=>({def:Re(e,t),schema:je(e,t)}),responseFormat:(e,t)=>({def:yn(e,t),schema:_n(e,t)}),responseSchema:(e,t)=>({def:Xt(e,t),schema:eo(e,t)}),oSeries:(e,t)=>({def:fn(e,t),schema:bn(e,t)})},J={base:()=>({def:ro(),schema:so()}),dimensions:e=>({def:vn(e),schema:Tn(e)})},On="openai",Le=class{constructor(){this.version="v1",this.name=On,this.chatModelFactories={[ho]:{model:Jn,modelOptions:Kn,modelSchema:go},[mo]:{model:Un,modelOptions:Fn,modelSchema:co},[po]:{model:zn,modelOptions:Dn,modelSchema:uo},[fo]:{model:Vn,modelOptions:Yn,modelSchema:bo},[yo]:{model:Xn,modelOptions:Qn,modelSchema:_o},[To]:{model:os,modelOptions:ts,modelSchema:vo},[Oo]:{model:ss,modelOptions:ns,modelSchema:So},[xo]:{model:ls,modelOptions:is,modelSchema:Co},[Mo]:{model:cs,modelOptions:ds,modelSchema:Po},[Eo]:{model:hs,modelOptions:us,modelSchema:wo},[jo]:{model:Ts,modelOptions:_s,modelSchema:Ro},[Go]:{model:Ms,modelOptions:Cs,modelSchema:No},[qo]:{model:ws,modelOptions:Es,modelSchema:$o},[Lo]:{model:Ss,modelOptions:Os,modelSchema:Ao},[Io]:{model:bs,modelOptions:fs,modelSchema:ko},[zo]:{model:qs,modelOptions:Ns,modelSchema:Ho},[Ko]:{model:Us,modelOptions:Fs,modelSchema:Jo},[Wo]:{model:zs,modelOptions:Ds,modelSchema:Yo},[Fo]:{model:js,modelOptions:ks,modelSchema:Uo},[Bo]:{model:As,modelOptions:Ls,modelSchema:Do}},this.embeddingModelFactories={[Vo]:{model:Vs,modelOptions:Ys,modelSchema:Zo},[Qo]:{model:Xs,modelOptions:Qs,modelSchema:Xo},[ea]:{model:or,modelOptions:tr,modelSchema:ta}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new Q({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
|
|
6
|
+
Message: ${sa(o)}`),this.name=pe,this.info=t,this.cause=o,this.name=s!=null?s:pe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof We}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},Y="system",U="user",E="assistant",V="tool",ra=[Y,U,E,V],ue=zod.z.enum(ra),ia=[E],la=zod.z.enum(ia),N="image",he="base64",ma=["png","jpeg","webp","gif"],da=zod.z.object({type:zod.z.literal(he),base64:zod.z.string(),media_type:zod.z.enum(ma)}),ge="url",ca=zod.z.object({type:zod.z.literal(ge),url:zod.z.string()}),pa=zod.z.discriminatedUnion("type",[da,ca]),ua=["low","medium","high","auto"],ha=zod.z.enum(ua),ga=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(N),detail:ha,value:pa,metadata:e}),v="text",Ye=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(v),value:zod.z.string(),metadata:e}),fe="partial-text",Ve=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(fe),value:zod.z.string(),metadata:e}),w="tool-call",Ze=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(w),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:e}),be="partial-tool-call",Qe=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(be),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:e}),R="tool-response",fa=(e=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(R),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),data:zod.z.string(),metadata:e}),ba=[v,N,w,R],Xe=zod.z.enum(ba),ya=(e=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ye(e),ga(t),Ze(o),fa(s)]),_a=[fe,be];zod.z.enum(_a);var Ta=(e=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ve(e),Qe(t)]);var ye=(e=ue,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined(),m=zod.z.undefined())=>zod.z.object({role:e,content:zod.z.array(ya(t,o,s,r)),metadata:m}),_e=(e=la,t=zod.z.undefined(),o=zod.z.undefined(),s=zod.z.undefined())=>zod.z.object({role:e,partialContent:Ta(t,o),metadata:s}),Te=e=>Ye().parse({modality:v,value:e}),et=(e,t,o,s)=>Ze().parse({modality:w,index:e,id:t,name:o,arguments:s});var ve=(e,t)=>_e().parse({role:e,partialContent:Ve().parse({modality:fe,value:t})}),tt=(e,t,o,s,r)=>_e().parse({role:e,partialContent:Qe().parse({modality:be,index:t,id:o,name:s,arguments:r})});var Oe=(e=zod.z.record(zod.z.string(),zod.z.any()).optional())=>e,va=["object","array","number","string","boolean","enum"],He=zod.z.enum(va),Oa=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([He,zod.z.array(zod.z.union([He,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()}),Sa=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(Oa),additionalProperties:zod.z.literal(!1)}),ot=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:Sa}).optional(),xa="function";var Ca=zod.z.enum(["object","array","number","string","boolean","null"]),Ma=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:Ca.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(Ma).optional(),required:zod.z.array(zod.z.string()).optional()});var Pa=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 Ea=zod.z.enum(["function"]),wa=zod.z.object({type:Ea,definition:zod.z.object({schema:Pa})}),Ia=[xa];zod.z.enum(Ia);var at=(e=zod.z.undefined())=>zod.z.discriminatedUnion("type",[wa.extend({metadata:e})]),q="text",D="token",ka=[q,D],nt=zod.z.enum(ka),ja=zod.z.array(zod.z.string().min(1)),Ra=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),st=(e=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(q),metadata:e,requests:ja}),zod.z.object({modality:zod.z.literal(D),metadata:e,requests:Ra})]),Se="float",La=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),xe="base64",Aa=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),Ke=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(Se),embeddings:zod.z.array(La),usage:Ke.optional()}),zod.z.object({encodingFormat:zod.z.literal(xe),embeddings:zod.z.array(Aa),usage:Ke.optional()})]);var rt=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),Je=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Ga=Je.extend({topLogProbs:zod.z.array(Je)}),it=zod.z.array(Ga);zod.z.object({messages:zod.z.array(ye()),usage:rt.optional(),logProbs:it.optional()});zod.z.object({partialMessages:zod.z.array(_e()),usage:rt.optional(),logProbs:it.optional()});var Na=Object.defineProperty,lt=Object.getOwnPropertySymbols,qa=Object.prototype.hasOwnProperty,$a=Object.prototype.propertyIsEnumerable,mt=(e,t,o)=>t in e?Na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,Z=(e,t)=>{for(var o in t||(t={}))qa.call(t,o)&&mt(e,o,t[o]);if(lt)for(var o of lt(t))$a.call(t,o)&&mt(e,o,t[o]);return e},dt="ProviderError",Q=class yt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},dt),this.name=dt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof yt}},ct="ModelError",B=class _t extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ct),this.name=ct,this.info=t,this.cause=o;}static isModelError(t){return t instanceof _t}},pt="ModelResponseError",z=class Tt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},pt),this.name=pt,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof Tt}},ut="InvalidModelRequestError",H=class vt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ut),this.name=ut,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof vt}},ht="InvalidConfigError",G=class Ot extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ht),this.name=ht,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof Ot}},gt="InvalidMessagesError",I=class St extends A{constructor({info:t,cause:o}){super({info:t,cause:o},gt),this.name=gt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof St}},ft="InvalidToolsError",Ce=class xt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ft),this.name=ft,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof xt}},bt="InvalidEmbeddingRequestsError",Ct=class Mt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},bt),this.name=bt,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof Mt}},Me="multi-string",Pt=zod.z.object({type:zod.z.literal(Me),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()}),Fa=e=>zod.z.array(zod.z.string()).max(e).default([]).optional(),Et=e=>({def:Pt.parse(Z({type:Me},e)),schema:Fa(e.max)}),Pe="object-schema",wt=zod.z.object({type:zod.z.literal(Pe),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),Ua=e=>e.optional(),It=e=>({def:wt.parse(Z({type:Pe},e)),schema:Ua(e.objectSchema)}),Ee="range",kt=zod.z.object({type:zod.z.literal(Ee),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()}),Ba=(e,t,o,s)=>zod.z.number().min(e).max(t).step(o).default(s).optional(),L=e=>({def:kt.parse(Z({type:Ee},e)),schema:Ba(e.min,e.max,e.step,e.default)}),we="select-boolean",jt=zod.z.object({type:zod.z.literal(we),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()}),Da=e=>zod.z.boolean().nullable().default(e).optional(),Rt=e=>({def:jt.parse(Z({type:we},e)),schema:Da(e.default)}),Ie="select-string",Lt=zod.z.object({type:zod.z.literal(Ie),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),default:zod.z.string(),choices:zod.z.array(zod.z.string())}),za=(e,t)=>zod.z.enum(t).nullable().default(e).optional(),X=e=>({def:Lt.parse(Z({type:Ie},e)),schema:za(e.default,e.choices)}),Ha=[Ee,Me,Ie,Pe,we];zod.z.enum(Ha);var At=zod.z.discriminatedUnion("type",[kt,Pt,Lt,jt,wt]),_=(e=ue,t=Xe)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(e,zod.z.string().min(1).optional()),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),At),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var s,r;let m=Object.keys(o.def),i=Object.keys((r=(s=o.schema)==null?void 0:s.shape)!=null?r:{});return m.every(d=>i.includes(d))&&i.every(d=>m.includes(d))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),oe=(e=nt)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),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),At),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,s;let r=Object.keys(t.def),m=Object.keys((s=(o=t.schema)==null?void 0:o.shape)!=null?s:{});return r.every(i=>m.includes(i))&&m.every(i=>r.includes(i))},{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 Ka={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."},Ja={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."},Wa=e=>({type:"multi",title:"Stop sequence",description:`Enter up to ${e} sequences that will halt additional text output. The generated text will exclude these sequences.`}),Ya={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."},Va={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."},Za={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."},Qa={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."},Xa={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."},en={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."},tn={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."},on={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."},an={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."},nn={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."},sn={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},rn={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."},ln={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."},mn={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:Ka,MAX_TOKENS:Ja,STOP:Wa,TOP_A:Ya,TOP_P:Va,TOP_K:Za,MIN_P:Qa,FREQUENCY_PENALTY:Xa,PRESENCE_PENALTY:en,REPETITION_PENALTY:on,SEED:tn,LOG_PROBS:an,TOP_LOG_PROBS:nn,ECHO:sn,RESPONSE_FORMAT:rn,RESPONSE_FORMAT_WITH_SCHEMA:ln,RESPONSE_SCHEMA:mn};var ke=e=>Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null));var Gt=e=>e.split(";")[0].split("/")[1],K=e=>e==null?void 0:e.replace(/\/$/,"");var dn=Object.defineProperty,cn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertySymbols,un=Object.prototype.hasOwnProperty,hn=Object.prototype.propertyIsEnumerable,ne=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),gn=e=>{throw TypeError(e)},qt=(e,t,o)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))un.call(t,o)&&qt(e,o,t[o]);if(Nt)for(var o of Nt(t))hn.call(t,o)&&qt(e,o,t[o]);return e},ee=(e,t)=>cn(e,pn(t)),M=(e,t,o)=>new Promise((s,r)=>{var m=c=>{try{d(o.next(c));}catch(p){r(p);}},i=c=>{try{d(o.throw(c));}catch(p){r(p);}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(m,i);d((o=o.apply(e,t)).next());}),$t=function(e,t){this[0]=e,this[1]=t;},se=(e,t,o)=>{var s=(i,d,c,p)=>{try{var b=o[i](d),h=(d=b.value)instanceof $t,y=b.done;Promise.resolve(h?d[0]:d).then(g=>h?s(i==="return"?i:"next",d[1]?{done:g.done,value:g.value}:g,c,p):c({value:g,done:y})).catch(g=>s("throw",g,c,p));}catch(g){p(g);}},r=i=>m[i]=d=>new Promise((c,p)=>s(i,d,c,p)),m={};return o=o.apply(e,t),m[ne("asyncIterator")]=()=>m,r("next"),r("throw"),r("return"),m},Ft=e=>{var t=e[ne("asyncIterator")],o=!1,s,r={};return t==null?(t=e[ne("iterator")](),s=m=>r[m]=i=>t[m](i)):(t=t.call(e),s=m=>r[m]=i=>{if(o){if(o=!1,m==="throw")throw i;return i}return o=!0,{done:!1,value:new $t(new Promise(d=>{var c=t[m](i);c instanceof Object||gn("Object expected"),d(c);}),1)}}),r[ne("iterator")]=()=>r,s("next"),"throw"in t?s("throw"):r.throw=m=>{throw m},"return"in t&&s("return"),r},Ut=L({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),Bt=e=>L({param:"max_completion_tokens",title:f.MAX_TOKENS.title,description:f.MAX_TOKENS.description,min:0,max:e,step:1,default:0}),Dt=e=>Et({param:"stop",title:f.STOP(e).title,description:f.STOP(e).description,max:e}),zt=L({param:"top_p",title:f.TOP_P.title,description:f.TOP_P.description,min:0,max:1,step:.01,default:1}),Ht=L({param:"frequency_penalty",title:f.FREQUENCY_PENALTY.title,description:f.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),Kt=L({param:"presence_penalty",title:f.PRESENCE_PENALTY.title,description:f.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),Jt=L({param:"seed",title:f.SEED.title,description:f.SEED.description,min:0,max:1e6,step:1,default:0}),Wt=Rt({param:"logprobs",title:f.LOG_PROBS.title,description:f.LOG_PROBS.description,default:!1}),Yt=L({param:"top_logprobs",title:f.TOP_LOG_PROBS.title,description:f.TOP_LOG_PROBS.description,min:0,max:20,step:1,default:0}),Vt=X({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"]}),je=(e,t)=>zod.z.object({temperature:Ut.schema,maxTokens:Bt(e).schema,stop:Dt(t).schema,topP:zt.schema,frequencyPenalty:Ht.schema,presencePenalty:Kt.schema,seed:Jt.schema.transform(o=>o===0?void 0:o),logProbs:Wt.schema,topLogProbs:Yt.schema,toolChoice:Vt.schema}),Re=(e,t)=>({temperature:Ut.def,maxTokens:Bt(e).def,stop:Dt(t).def,topP:zt.def,frequencyPenalty:Ht.def,presencePenalty:Kt.def,seed:Jt.def,logProbs:Wt.def,topLogProbs:Yt.def,toolChoice:Vt.def}),Zt=It({param:"response_schema",title:f.RESPONSE_SCHEMA.title,description:f.RESPONSE_SCHEMA.description,objectSchema:ot}),Qt=X({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"]}),Xt=(e,t)=>ee(O({},Re(e,t)),{responseFormat:Qt.def,responseSchema:Zt.def}),eo=(e,t)=>je(e,t).extend({responseFormat:Qt.schema,responseSchema:Zt.schema}),to=L({param:"temperature",title:f.TEMPERATURE.title,description:f.TEMPERATURE.description,min:1,max:1,step:.01,default:1}),fn=(e,t)=>ee(O({},Xt(e,t)),{temperature:to.def}),bn=(e,t)=>eo(e,t).extend({temperature:to.schema}),oo=X({param:"response_format",title:f.RESPONSE_FORMAT.title,description:f.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),yn=(e,t)=>ee(O({},Re(e,t)),{responseFormat:oo.def}),_n=(e,t)=>je(e,t).extend({responseFormat:oo.schema}),ao=X({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),no=e=>L({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:e,step:1,default:e}),so=()=>zod.z.object({encodingFormat:ao.schema}),ro=()=>({encodingFormat:ao.def}),Tn=e=>so().extend({dimensions:no(e).schema}),vn=e=>ee(O({},ro()),{dimensions:no(e).def}),u={base:(e,t)=>({def:Re(e,t),schema:je(e,t)}),responseFormat:(e,t)=>({def:yn(e,t),schema:_n(e,t)}),responseSchema:(e,t)=>({def:Xt(e,t),schema:eo(e,t)}),oSeries:(e,t)=>({def:fn(e,t),schema:bn(e,t)})},J={base:()=>({def:ro(),schema:so()}),dimensions:e=>({def:vn(e),schema:Tn(e)})},On="openai",Le=class{constructor(){this.version="v1",this.name=On,this.chatModelFactories={[ho]:{model:Jn,modelOptions:Kn,modelSchema:go},[mo]:{model:Un,modelOptions:Fn,modelSchema:co},[po]:{model:zn,modelOptions:Dn,modelSchema:uo},[fo]:{model:Vn,modelOptions:Yn,modelSchema:bo},[yo]:{model:Xn,modelOptions:Qn,modelSchema:_o},[To]:{model:os,modelOptions:ts,modelSchema:vo},[Oo]:{model:ss,modelOptions:ns,modelSchema:So},[xo]:{model:ls,modelOptions:is,modelSchema:Co},[Mo]:{model:cs,modelOptions:ds,modelSchema:Po},[Eo]:{model:hs,modelOptions:us,modelSchema:wo},[jo]:{model:Ts,modelOptions:_s,modelSchema:Ro},[Go]:{model:Ms,modelOptions:Cs,modelSchema:No},[qo]:{model:ws,modelOptions:Es,modelSchema:$o},[Lo]:{model:Ss,modelOptions:Os,modelSchema:Ao},[Io]:{model:bs,modelOptions:fs,modelSchema:ko},[zo]:{model:qs,modelOptions:Ns,modelSchema:Ho},[Ko]:{model:Us,modelOptions:Fs,modelSchema:Jo},[Wo]:{model:zs,modelOptions:Ds,modelSchema:Yo},[Fo]:{model:js,modelOptions:ks,modelSchema:Uo},[Bo]:{model:As,modelOptions:Ls,modelSchema:Do}},this.embeddingModelFactories={[Vo]:{model:Vs,modelOptions:Ys,modelSchema:Zo},[Qo]:{model:Xs,modelOptions:Qs,modelSchema:Xo},[ea]:{model:or,modelOptions:tr,modelSchema:ta}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,t)=>(e[t]=this.chatModelFactories[t].modelSchema,e),{})}chatModel(e){let t=e.modelName;if(!(t in this.chatModelFactories))throw new Q({info:`OpenAI chat model: ${t} not found`,cause:new Error(`OpenAI chat model: ${t} not found, available chat models:
|
|
7
7
|
[${this.chatModelLiterals().join(", ")}]`)});let o=this.chatModelFactories[t].model,s=this.chatModelFactories[t].modelOptions.parse(e);return new o(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,t)=>(e[t]=this.embeddingModelFactories[t].modelSchema,e),{})}embeddingModel(e){let t=e.modelName;if(!(t in this.embeddingModelFactories))throw new Q({info:`OpenAI embedding model: ${t} not found`,cause:new Error(`OpenAI embedding model: ${t} not found, available embedding models:
|
|
8
8
|
[${this.embeddingModelLiterals().join(", ")}]`)});let o=this.embeddingModelFactories[t].model,s=this.embeddingModelFactories[t].modelOptions.parse(e);return new o(s)}};Le.baseUrl="https://api.openai.com/v1";var S=zod.z.enum([Y,U,E,V]),x={system:Y,user:U,assistant:E,tool:V},Ae=zod.z.enum([U,E]),Ge={user:U,assistant:E},k=[v,N,w,R],j=zod.z.enum([v,N,w,R]),Ne=[v],qe=zod.z.enum([v]),$=[v,w,R],F=zod.z.enum([v,w,R]),ae=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(ae.extend({top_logprobs:zod.z.array(ae)})).nullable().optional(),refusal:zod.z.array(ae.extend({top_logprobs:zod.z.array(ae)})).nullable().optional()}).nullable(),Sn=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()})})),xn=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:Sn.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()})}),Cn=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()})),Mn=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().optional(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Cn.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()}),Pn=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()})}),En=zod.z.enum(["none","auto","required"]),wn=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),In=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()})})),$e=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),kn=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()})}),jn=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)})}),Rn=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array($e).min(1))}),Ln=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([$e,kn])).min(1))}),An=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array($e).min(1)).optional(),tool_calls:zod.z.array(jn).min(1).optional()}),Gn=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Nn=zod.z.union([Rn,Ln,An,Gn]),lo=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Nn).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_completion_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:In.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(Pn).optional(),tool_choice:En.or(wn).optional()}),qn=lo,T=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),C=class{constructor(e,t){this.version="v1";let o=T.parse(t);this.modelSchema=e,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=K(o.baseUrl||Le.baseUrl),this.streamChatUrl=K(o.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=K(o.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=o.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return O({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){let t=i=>{let d=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},p,b=0;for(;(p=d.exec(i))!==null;){let h=parseInt(p[1]),y=p[2];b+=h*c[y];}return b},o=0,s=0,r=!0;e["x-ratelimit-reset-requests"]&&(o=t(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(s=t(e["x-ratelimit-reset-tokens"]));let m=Math.max(o,s);return {shouldRetry:r,delayMs:m}}getTokenCount(e){return e.reduce((t,o)=>t+o.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(e){let t=lo.safeParse(e);if(!t.success)throw new H({info:"Invalid model request",cause:t.error});let o=t.data,s=o.model;if(o.tool_choice&&(!o.tools||o.tools.length===0))throw new H({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};o.response_format&&(r.responseFormat=o.response_format.type,o.response_format.type==="json_schema"&&(r.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"?r.toolChoice=o.tool_choice:r.toolChoice=o.tool_choice.function.name),r.seed=o.seed,r.maxTokens=o.max_completion_tokens,r.temperature=o.temperature,r.topP=o.top_p,r.presencePenalty=o.presence_penalty,r.frequencyPenalty=o.frequency_penalty,r.stop=o.stop,r.logProbs=o.logprobs,r.topLogProbs=o.top_logprobs;let m=Oe().parse(ke(r)),i=[],d={};o.messages.forEach(p=>{let b=p.role;switch(b){case"system":{let h=p.content;if(typeof h=="string")i.push({role:b,content:[{modality:v,value:h}]});else {let y=h.map(g=>({modality:v,value:g.text}));i.push({role:b,content:y});}}break;case"user":{let h=p.content;if(typeof h=="string")i.push({role:b,content:[{modality:v,value:h}]});else {let y=h.map(g=>g.type==="text"?{modality:v,value:g.text}:g.image_url.url.startsWith("data:")?{modality:N,detail:g.image_url.detail||"auto",value:{type:he,base64:g.image_url.url,media_type:Gt(g.image_url.url)}}:{modality:N,detail:g.image_url.detail||"auto",value:{type:ge,url:g.image_url.url}});i.push({role:b,content:y});}}break;case"assistant":{let h=[];if(!p.content&&!p.tool_calls)throw new H({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});if(p.content){let y=p.content;typeof y=="string"?h.push({modality:v,value:y}):y.forEach(g=>{h.push({modality:v,value:g.text});});}p.tool_calls&&p.tool_calls.forEach((y,g)=>{let P={modality:w,id:y.id,index:g,name:y.function.name,arguments:y.function.arguments};h.push(P),d[P.id]=P;}),i.push({role:b,content:h});}break;case"tool":{let h=p;i.push({role:b,content:[{modality:R,id:h.tool_call_id,index:d[h.tool_call_id].index,name:d[h.tool_call_id].name,data:h.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:i,tools:c.length>0?c:void 0}}transformConfig(e,t,o){let s=e.toolChoice;delete e.toolChoice;let r=this.modelSchema.config.schema.safeParse(e);if(!r.success)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:r.error});let m=r.data;s!==void 0&&(m.toolChoice=s),Object.keys(m).forEach(d=>{if(!(d in this.modelSchema.config.def))throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
|
|
9
9
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let i=Object.keys(m).reduce((d,c)=>{let p=this.modelSchema.config.def[c],b=p.param,h=m[c];return b==="max_completion_tokens"&&p.type==="range"&&h===0?d[b]=p.max:d[b]=h,d},{});if(i.top_logprobs&&!i.logprobs)throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in i&&i.tool_choice!==void 0){let d=i.tool_choice;if(!o||o&&o.length===0)throw new G({info:`Invalid config for model : '${this.modelName}'`,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))i.tool_choice={type:"function",function:{name:d}};else throw new G({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${d}' is not part of provided 'tools' names or
|