@adaline/together-ai 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/README.md +0 -2
- package/dist/index.d.mts +59 -61
- package/dist/index.d.ts +59 -61
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -7
package/dist/index.js
CHANGED
|
@@ -2,46 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
Message: ${Ht(o)}`),this.name=Y,this.info=t,this.cause=o,this.name=n!=null?n:Y,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof ke}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},k="system",O="user",R="assistant",N="tool",Gt=[k,O,R,N],J=zod.z.enum(Gt),Vt=[R],Yt=zod.z.enum(Vt),Oe="image",Jt="base64",Wt=["png","jpeg","webp","gif"],Zt=zod.z.object({type:zod.z.literal(Jt),base64:zod.z.string(),media_type:zod.z.enum(Wt)}),Qt="url",Xt=zod.z.object({type:zod.z.literal(Qt),url:zod.z.string()}),eo=zod.z.discriminatedUnion("type",[Zt,Xt]),to=["low","medium","high","auto"],oo=zod.z.enum(to),no=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Oe),detail:oo,value:eo,metadata:a}),b="text",Ne=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(b),value:zod.z.string(),metadata:a}),W="partial-text",Le=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(W),value:zod.z.string(),metadata:a}),I="tool-call",Ue=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(I),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),Z="partial-tool-call",$e=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Z),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),w="tool-response",ao=(a=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),data:zod.z.string(),metadata:a}),so=[b,Oe,I,w],Be=zod.z.enum(so),ro=(a=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ne(a),no(t),Ue(o),ao(n)]),io=[W,Z];zod.z.enum(io);var lo=(a=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Le(a),$e(t)]);var U=(a=J,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(ro(t,o,n,s)),metadata:r}),Q=(a=Yt,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:lo(t,o),metadata:n});var Fe=(a,t)=>U().parse({role:a,content:[Ne().parse({modality:b,value:t})]});var ze=(a,t,o,n,s)=>U().parse({role:a,content:[Ue().parse({modality:I,index:t,id:o,name:n,arguments:s})]});var De=(a,t)=>Q().parse({role:a,partialContent:Le().parse({modality:W,value:t})}),Ke=(a,t,o,n,s)=>Q().parse({role:a,partialContent:$e().parse({modality:Z,index:t,id:o,name:n,arguments:s})});var z=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,mo=["object","array","number","string","boolean","enum"],je=zod.z.enum(mo),po=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([je,zod.z.array(zod.z.union([je,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()}),co=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(po),additionalProperties:zod.z.literal(!1)}),He=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:co}).optional(),uo="function";var ho=zod.z.enum(["object","array","number","string","boolean","null"]),go=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:ho.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(go).optional(),required:zod.z.array(zod.z.string()).optional()});var fo=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 yo=zod.z.enum(["function"]),To=zod.z.object({type:yo,definition:zod.z.object({schema:fo})}),bo=[uo];zod.z.enum(bo);var Ge=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[To.extend({metadata:a})]),x="text",Ve="token",Co=[x,Ve],Ye=zod.z.enum(Co),Eo=zod.z.array(zod.z.string().min(1)),Mo=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),Je=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(x),metadata:a,requests:Eo}),zod.z.object({modality:zod.z.literal(Ve),metadata:a,requests:Mo})]),X="float",Ro=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),Io="base64",vo=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),_e=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(X),embeddings:zod.z.array(Ro),usage:_e.optional()}),zod.z.object({encodingFormat:zod.z.literal(Io),embeddings:zod.z.array(vo),usage:_e.optional()})]);var We=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),qe=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),Po=qe.extend({topLogProbs:zod.z.array(qe)}),Ze=zod.z.array(Po);zod.z.object({messages:zod.z.array(U()),usage:We.optional(),logProbs:Ze.optional()});zod.z.object({partialMessages:zod.z.array(Q()),usage:We.optional(),logProbs:Ze.optional()});var So=Object.defineProperty,Qe=Object.getOwnPropertySymbols,wo=Object.prototype.hasOwnProperty,xo=Object.prototype.propertyIsEnumerable,Xe=(a,t,o)=>t in a?So(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,$=(a,t)=>{for(var o in t||(t={}))wo.call(t,o)&&Xe(a,o,t[o]);if(Qe)for(var o of Qe(t))xo.call(t,o)&&Xe(a,o,t[o]);return a},et="ProviderError",B=class it extends A{constructor({info:t,cause:o}){super({info:t,cause:o},et),this.name=et,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof it}};var tt="ModelResponseError",j=class lt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},tt),this.name=tt,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof lt}},ot="InvalidModelRequestError",L=class mt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ot),this.name=ot,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof mt}},nt="InvalidConfigError",v=class dt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},nt),this.name=nt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof dt}},at="InvalidMessagesError",E=class pt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},at),this.name=at,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof pt}},st="InvalidToolsError",ee=class ct extends A{constructor({info:t,cause:o}){super({info:t,cause:o},st),this.name=st,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof ct}},rt="InvalidEmbeddingRequestsError",te=class ut extends A{constructor({info:t,cause:o}){super({info:t,cause:o},rt),this.name=rt,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof ut}},oe="multi-string",ht=zod.z.object({type:zod.z.literal(oe),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()}),Ao=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),gt=a=>({def:ht.parse($({type:oe},a)),schema:Ao(a.max)}),ne="range",ft=zod.z.object({type:zod.z.literal(ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),min:zod.z.number().int(),max:zod.z.number().int(),step:zod.z.number().positive(),default:zod.z.number()}),jo=(a,t,o,n)=>zod.z.number().min(a).max(t).step(o).default(n).optional(),P=a=>({def:ft.parse($({type:ne},a)),schema:jo(a.min,a.max,a.step,a.default)}),ae="select-string",yt=zod.z.object({type:zod.z.literal(ae),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))}),_o=(a,t)=>zod.z.enum(t).nullable().default(a).optional(),se=a=>({def:yt.parse($({type:ae},a)),schema:_o(a.default,a.choices)}),re="object-schema",Tt=zod.z.object({type:zod.z.literal(re),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),qo=a=>a.optional(),bt=a=>({def:Tt.parse($({type:re},a)),schema:qo(a.objectSchema)}),ie="select-boolean",Ct=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.boolean().nullable()}),ko=a=>zod.z.boolean().nullable().default(a).optional(),Et=a=>({def:Ct.parse($({type:ie},a)),schema:ko(a.default)}),Oo=[ne,oe,ae,re,ie];zod.z.enum(Oo);var Mt=zod.z.discriminatedUnion("type",[ft,ht,yt,Ct,Tt]),Rt=(a=J,t=Be)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,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),Mt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,s;let r=Object.keys(o.def),d=Object.keys((s=(n=o.schema)==null?void 0:n.shape)!=null?s:{});return r.every(l=>d.includes(l))&&d.every(l=>r.includes(l))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),It=(a=Ye)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(a).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),Mt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,n;let s=Object.keys(t.def),r=Object.keys((n=(o=t.schema)==null?void 0:o.shape)!=null?n:{});return s.every(d=>r.includes(d))&&r.every(d=>s.includes(d))},{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 No={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."},Lo={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."},Uo=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),$o={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."},Bo={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."},Fo={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."},zo={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."},Do={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."},Ko={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."},Ho={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."},Go={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."},Vo={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."},Yo={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."},Jo={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Wo={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."},Zo={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."},Qo={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},g={TEMPERATURE:No,MAX_TOKENS:Lo,STOP:Uo,TOP_A:$o,TOP_P:Bo,TOP_K:Fo,MIN_P:zo,FREQUENCY_PENALTY:Do,PRESENCE_PENALTY:Ko,REPETITION_PENALTY:Go,SEED:Ho,LOG_PROBS:Vo,TOP_LOG_PROBS:Yo,ECHO:Jo,RESPONSE_FORMAT:Wo,RESPONSE_FORMAT_WITH_SCHEMA:Zo,RESPONSE_SCHEMA:Qo};var D=a=>Object.fromEntries(Object.entries(a).filter(([t,o])=>o!=null));var _=a=>a==null?void 0:a.replace(/\/$/,"");var le=P({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),me=a=>P({param:"max_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),de=a=>gt({param:"stop",title:g.STOP(a).title,description:g.STOP(a).description,max:a}),pe=P({param:"top_k",title:g.TOP_K.title,description:g.TOP_K.description,min:0,max:1e4,step:1,default:0}),ce=P({param:"top_p",title:g.TOP_P.title,description:g.TOP_P.description,min:0,max:1,step:.01,default:1}),ue=P({param:"min_p",title:g.MIN_P.title,description:g.MIN_P.description,min:0,max:1,step:.01,default:0}),he=P({param:"frequency_penalty",title:g.FREQUENCY_PENALTY.title,description:g.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),ge=P({param:"presence_penalty",title:g.PRESENCE_PENALTY.title,description:g.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),fe=P({param:"repetition_penalty",title:g.REPETITION_PENALTY.title,description:g.REPETITION_PENALTY.description,min:0,max:1e4,step:.01,default:0}),ye=P({param:"seed",title:g.SEED.title,description:g.SEED.description,min:0,max:1e6,step:1,default:0}),Te=Et({param:"logprobs",title:g.LOG_PROBS.title,description:g.LOG_PROBS.description,default:!1}),be=se({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"]}),Ce=se({param:"response_format",title:g.RESPONSE_FORMAT.title,description:g.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Ee=bt({param:"response_schema",title:g.RESPONSE_SCHEMA.title,description:g.RESPONSE_SCHEMA.description,objectSchema:He});var vt=(a,t)=>zod.z.object({temperature:le.schema,maxTokens:me(a).schema,stop:de(t).schema,topP:ce.schema,topK:pe.schema,minP:ue.schema,frequencyPenalty:he.schema,presencePenalty:ge.schema,repetitionPenalty:fe.schema,seed:ye.schema.transform(o=>o===0?void 0:o),logProbs:Te.schema,toolChoice:be.schema,responseSchema:Ee.schema,responseFormat:Ce.schema}),Pt=(a,t)=>({temperature:le.def,maxTokens:me(a).def,stop:de(t).def,topP:ce.def,topK:pe.def,minP:ue.def,frequencyPenalty:he.def,presencePenalty:ge.def,repetitionPenalty:fe.def,seed:ye.def,logProbs:Te.def,toolChoice:be.def,responseSchema:Ee.def,responseFormat:Ce.def});var Me={base:(a,t)=>({def:Pt(a,t),schema:vt(a,t)})};var St=zod.z.enum([k,O,R,N]),wt={system:k,user:O,assistant:R,tool:N};var xt=[b,I,w],At=zod.z.enum([b,I,w]);var on=zod.z.object({token_ids:zod.z.array(zod.z.number()),tokens:zod.z.array(zod.z.string()),token_logprobs:zod.z.array(zod.z.number())}),nn=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()})})),jt=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),prompt:zod.z.any(),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:nn.optional()}),logprobs:on.nullable().optional(),seed:zod.z.number().nullable().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()}).nullable().optional()}),an=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()})),_t=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({token_id:zod.z.number().nullable().optional(),role:zod.z.string().nullable().optional(),content:zod.z.string().nullable().optional(),tool_calls:an.optional()}).or(zod.z.object({})),logprobs:zod.z.any().nullable().optional(),seed:zod.z.number().nullable().optional(),finish_reason:zod.z.string().nullable(),text:zod.z.string().nullable().optional()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var sn=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()})}),rn=zod.z.enum(["none","auto","required"]),ln=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),mn=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()})})),Re=zod.z.string(),dn=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)})}),pn=zod.z.object({role:zod.z.literal("system"),content:Re}),cn=zod.z.object({role:zod.z.literal("user"),content:Re}),un=zod.z.object({role:zod.z.literal("assistant"),content:Re.optional(),tool_calls:zod.z.array(dn).min(1).optional()}),hn=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),gn=zod.z.union([pn,cn,un,hn]),qt=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(gn).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.number().min(0).max(1).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),repetition_penalty:zod.z.number().min(0).max(2).nullable().optional(),response_format:mn.optional(),seed:zod.z.number().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(1).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),top_k:zod.z.number().min(0).max(1e4).nullable().optional(),min_p:zod.z.number().min(0).max(1).nullable().optional(),echo:zod.z.boolean().nullable().optional(),tools:zod.z.array(sn).optional(),tool_choice:rn.or(ln).optional()});var Ie=Rt(St,At).parse({name:"together-ai-base-chat-model",description:"Base chat model for Together AI",maxInputTokens:128e3,maxOutputTokens:128e3,roles:wt,modalities:xt,config:{def:Me.base(128e3,4).def,schema:Me.base(128e3,4).schema}});var fn="together-ai",q=class{constructor(){this.version="v1";this.name=fn;}chatModelLiterals(){throw new B({info:"Not implemented",cause:new Error("Not implemented")})}chatModel(t,o){let n=T({modelName:t},o);return new K(Ie,n)}chatModelSchema(t){return Ie}chatModelSchemas(){throw new B({info:"Not implemented",cause:new Error("Not implemented")})}embeddingModelLiterals(){throw new B({info:"Not implemented",cause:new Error("Not implemented")})}embeddingModel(t,o){let n=T({modelName:t},o);return new H(ve,n)}embeddingModelSchema(t){return ve}embeddingModelSchemas(){throw new B({info:"Not implemented",cause:new Error("Not implemented")})}};q.baseUrl="https://api.together.xyz/v1";var yn=zod.z.object({apiKey:zod.z.string(),modelName:zod.z.string()}),K=class{constructor(t,o){this.version="v1";let n=yn.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=_(q.baseUrl),this.streamChatUrl=_(`${this.baseUrl}/chat/completions`),this.completeChatUrl=_(`${this.baseUrl}/chat/completions`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}getTokenCount(t){return t.reduce((o,n)=>o+n.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let o=qt.safeParse(t);if(!o.success)throw new L({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new L({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};n.response_format&&(r.responseFormat=n.response_format.type,n.response_format.type==="json_schema"&&(r.responseSchema={name:n.response_format.json_schema.name,description:n.response_format.json_schema.description||"",strict:n.response_format.json_schema.strict,schema:n.response_format.json_schema.schema})),n.tool_choice&&(typeof n.tool_choice=="string"?r.toolChoice=n.tool_choice:r.toolChoice=n.tool_choice.function.name),r.seed=n.seed,r.maxTokens=n.max_tokens,r.temperature=n.temperature,r.topP=n.top_p,r.minP=n.min_p,r.topK=n.top_k,r.repetitionPenalty=n.repetition_penalty,r.presencePenalty=n.presence_penalty,r.frequencyPenalty=n.frequency_penalty,r.repetitionPenalty=n.repetition_penalty,r.stop=n.stop,r.logProbs=n.logprobs!==0,r.echo=n.echo;let d=z().parse(D(r)),l=[],c={};n.messages.forEach(u=>{let f=u.role;switch(f){case"system":l.push({role:f,content:[{modality:b,value:u.content}]});break;case"user":l.push({role:f,content:[{modality:b,value:u.content}]});break;case"assistant":{let y=[];if(!u.content&&!u.tool_calls)throw new L({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});u.content&&y.push({modality:b,value:u.content}),u.tool_calls&&u.tool_calls.forEach((G,Ut)=>{let V={modality:I,id:G.id,index:Ut,name:G.function.name,arguments:G.function.arguments};y.push(V),c[V.id]=V;}),l.push({role:f,content:y});}break;case"tool":{let y=u;l.push({role:f,content:[{modality:w,id:y.tool_call_id,index:c[y.tool_call_id].index,name:c[y.tool_call_id].name,data:y.content}]});}break}});let h=[];return n.tools&&n.tools.forEach(u=>{h.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.function.parameters}}});}),{modelName:s,config:d,messages:l,tools:h.length>0?h:void 0}}transformConfig(t,o,n){let s=t.toolChoice;delete t.toolChoice;let r=this.modelSchema.config.schema.safeParse(t);if(!r.success)throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:r.error});let d=r.data;s!==void 0&&(d.toolChoice=s),Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
|
|
5
|
+
var Bt=Object.defineProperty,Ft=Object.defineProperties;var zt=Object.getOwnPropertyDescriptors;var xe=Object.getOwnPropertySymbols;var Dt=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable;var Ht=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a);var Ae=(a,t,o)=>t in a?Bt(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,T=(a,t)=>{for(var o in t||(t={}))Dt.call(t,o)&&Ae(a,o,t[o]);if(xe)for(var o of xe(t))Kt.call(t,o)&&Ae(a,o,t[o]);return a},V=(a,t)=>Ft(a,zt(t));var R=(a,t,o)=>new Promise((n,s)=>{var r=c=>{try{l(o.next(c));}catch(h){s(h);}},d=c=>{try{l(o.throw(c));}catch(h){s(h);}},l=c=>c.done?n(c.value):Promise.resolve(c.value).then(r,d);l((o=o.apply(a,t)).next());}),Gt=function(a,t){this[0]=a,this[1]=t;},je=(a,t,o)=>{var n=(d,l,c,h)=>{try{var u=o[d](l),f=(l=u.value)instanceof Gt,y=u.done;Promise.resolve(f?l[0]:l).then(S=>f?n(d==="return"?d:"next",l[1]?{done:S.done,value:S.value}:S,c,h):c({value:S,done:y})).catch(S=>n("throw",S,c,h));}catch(S){h(S);}},s=d=>r[d]=l=>new Promise((c,h)=>n(d,l,c,h)),r={};return o=o.apply(a,t),r[Ht("asyncIterator")]=()=>r,s("next"),s("throw"),s("return"),r};var Vt=a=>{let t=new WeakSet;return JSON.stringify(a,(o,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return;t.add(n);}return n})},Yt=a=>a==null?"unknown error":typeof a=="string"?a:a instanceof Error?a.message:Vt(a),Y="GatewayBaseError",A=class Oe extends Error{constructor({info:t,cause:o},n){super(`[${n!=null?n:Y}]: ${t}
|
|
6
|
+
Message: ${Yt(o)}`),this.name=Y,this.info=t,this.cause=o,this.name=n!=null?n:Y,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof Oe}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}},k="system",O="user",M="assistant",N="tool",Jt=[k,O,M,N],J=zod.z.enum(Jt),Wt=[M],Zt=zod.z.enum(Wt),Ne="image",Qt="base64",Xt=["png","jpeg","webp","gif"],eo=zod.z.object({type:zod.z.literal(Qt),base64:zod.z.string(),media_type:zod.z.enum(Xt)}),to="url",oo=zod.z.object({type:zod.z.literal(to),url:zod.z.string()}),no=zod.z.discriminatedUnion("type",[eo,oo]),ao=["low","medium","high","auto"],so=zod.z.enum(ao),ro=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Ne),detail:so,value:no,metadata:a}),b="text",Le=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(b),value:zod.z.string(),metadata:a}),W="partial-text",Ue=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(W),value:zod.z.string(),metadata:a}),I="tool-call",$e=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(I),index:zod.z.number().int().nonnegative(),id:zod.z.string().min(1),name:zod.z.string().min(1),arguments:zod.z.string(),metadata:a}),Z="partial-tool-call",Be=(a=zod.z.undefined())=>zod.z.object({modality:zod.z.literal(Z),index:zod.z.number().int().nonnegative(),id:zod.z.string().optional(),name:zod.z.string().optional(),arguments:zod.z.string().optional(),metadata:a}),w="tool-response",io=(a=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),data:zod.z.string(),metadata:a}),lo=[b,Ne,I,w],Fe=zod.z.enum(lo),mo=(a=zod.z.undefined(),t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Le(a),ro(t),$e(o),io(n)]),po=[W,Z];zod.z.enum(po);var co=(a=zod.z.undefined(),t=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[Ue(a),Be(t)]);var U=(a=J,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined(),s=zod.z.undefined(),r=zod.z.undefined())=>zod.z.object({role:a,content:zod.z.array(mo(t,o,n,s)),metadata:r}),Q=(a=Zt,t=zod.z.undefined(),o=zod.z.undefined(),n=zod.z.undefined())=>zod.z.object({role:a,partialContent:co(t,o),metadata:n});var ze=(a,t)=>U().parse({role:a,content:[Le().parse({modality:b,value:t})]});var De=(a,t,o,n,s)=>U().parse({role:a,content:[$e().parse({modality:I,index:t,id:o,name:n,arguments:s})]});var Ke=(a,t)=>Q().parse({role:a,partialContent:Ue().parse({modality:W,value:t})}),He=(a,t,o,n,s)=>Q().parse({role:a,partialContent:Be().parse({modality:Z,index:t,id:o,name:n,arguments:s})});var F=(a=zod.z.record(zod.z.string(),zod.z.any()).optional())=>a,uo=["object","array","number","string","boolean","enum"],_e=zod.z.enum(uo),ho=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([_e,zod.z.array(zod.z.union([_e,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()}),go=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(ho),additionalProperties:zod.z.literal(!1)}),Ge=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:go}).optional(),fo="function";var yo=zod.z.enum(["object","array","number","string","boolean","null"]),To=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:yo.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(To).optional(),required:zod.z.array(zod.z.string()).optional()});var bo=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 Co=zod.z.enum(["function"]),Eo=zod.z.object({type:Co,definition:zod.z.object({schema:bo})}),Ro=[fo];zod.z.enum(Ro);var Ve=(a=zod.z.undefined())=>zod.z.discriminatedUnion("type",[Eo.extend({metadata:a})]),x="text",Ye="token",Mo=[x,Ye],Je=zod.z.enum(Mo),Io=zod.z.array(zod.z.string().min(1)),vo=zod.z.array(zod.z.array(zod.z.number().int().nonnegative())),We=(a=zod.z.undefined())=>zod.z.discriminatedUnion("modality",[zod.z.object({modality:zod.z.literal(x),metadata:a,requests:Io}),zod.z.object({modality:zod.z.literal(Ye),metadata:a,requests:vo})]),X="float",Po=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.array(zod.z.number())}),So="base64",wo=zod.z.object({index:zod.z.number().int().nonnegative(),embedding:zod.z.string().base64()}),qe=zod.z.object({totalTokens:zod.z.number().int().nonnegative()});zod.z.discriminatedUnion("encodingFormat",[zod.z.object({encodingFormat:zod.z.literal(X),embeddings:zod.z.array(Po),usage:qe.optional()}),zod.z.object({encodingFormat:zod.z.literal(So),embeddings:zod.z.array(wo),usage:qe.optional()})]);var Ze=zod.z.object({promptTokens:zod.z.number().nonnegative(),completionTokens:zod.z.number().nonnegative(),totalTokens:zod.z.number().nonnegative()}),ke=zod.z.object({token:zod.z.string(),logProb:zod.z.number(),bytes:zod.z.array(zod.z.number().int()).nullable()}),xo=ke.extend({topLogProbs:zod.z.array(ke)}),Qe=zod.z.array(xo);zod.z.object({messages:zod.z.array(U()),usage:Ze.optional(),logProbs:Qe.optional()});zod.z.object({partialMessages:zod.z.array(Q()),usage:Ze.optional(),logProbs:Qe.optional()});var Ao=Object.defineProperty,Xe=Object.getOwnPropertySymbols,jo=Object.prototype.hasOwnProperty,_o=Object.prototype.propertyIsEnumerable,et=(a,t,o)=>t in a?Ao(a,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[t]=o,$=(a,t)=>{for(var o in t||(t={}))jo.call(t,o)&&et(a,o,t[o]);if(Xe)for(var o of Xe(t))_o.call(t,o)&&et(a,o,t[o]);return a},tt="ProviderError",ee=class lt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},tt),this.name=tt,this.info=t,this.cause=o;}static isProviderError(t){return t instanceof lt}};var ot="ModelResponseError",j=class mt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},ot),this.name=ot,this.cause=o,this.info=t;}static isModelResponseError(t){return t instanceof mt}},nt="InvalidModelRequestError",L=class dt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},nt),this.name=nt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidModelRequestError(t){return t instanceof dt}},at="InvalidConfigError",v=class pt extends A{constructor({info:t,cause:o}){super({info:t,cause:o},at),this.name=at,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidConfigError(t){return t instanceof pt}},st="InvalidMessagesError",E=class ct extends A{constructor({info:t,cause:o}){super({info:t,cause:o},st),this.name=st,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidMessagesError(t){return t instanceof ct}},rt="InvalidToolsError",te=class ut extends A{constructor({info:t,cause:o}){super({info:t,cause:o},rt),this.name=rt,this.cause=o,this.info=t,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidToolsError(t){return t instanceof ut}},it="InvalidEmbeddingRequestsError",oe=class ht extends A{constructor({info:t,cause:o}){super({info:t,cause:o},it),this.name=it,this.info=t,this.cause=o,Object.setPrototypeOf(this,new.target.prototype);}static isInvalidEmbeddingRequestsError(t){return t instanceof ht}},ne="multi-string",gt=zod.z.object({type:zod.z.literal(ne),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),max:zod.z.number().int().positive()}),qo=a=>zod.z.array(zod.z.string()).max(a).default([]).optional(),ft=a=>({def:gt.parse($({type:ne},a)),schema:qo(a.max)}),ae="object-schema",yt=zod.z.object({type:zod.z.literal(ae),param:zod.z.string().min(1),title:zod.z.string().min(1),description:zod.z.string().min(1).max(500),objectSchema:zod.z.any()}),ko=a=>a.optional(),Tt=a=>({def:yt.parse($({type:ae},a)),schema:ko(a.objectSchema)}),se="range",bt=zod.z.object({type:zod.z.literal(se),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()}),Oo=(a,t,o,n)=>zod.z.number().min(a).max(t).step(o).default(n).optional(),P=a=>({def:bt.parse($({type:se},a)),schema:Oo(a.min,a.max,a.step,a.default)}),re="select-boolean",Ct=zod.z.object({type:zod.z.literal(re),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()}),No=a=>zod.z.boolean().nullable().default(a).optional(),Et=a=>({def:Ct.parse($({type:re},a)),schema:No(a.default)}),ie="select-string",Rt=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))}),Lo=(a,t)=>zod.z.enum(t).nullable().default(a).optional(),le=a=>({def:Rt.parse($({type:ie},a)),schema:Lo(a.default,a.choices)}),Uo=[se,ne,ie,ae,re];zod.z.enum(Uo);var Mt=zod.z.discriminatedUnion("type",[bt,gt,Rt,Ct,yt]),It=(a=J,t=Fe)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),roles:zod.z.record(a,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),Mt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(o=>{var n,s;let r=Object.keys(o.def),d=Object.keys((s=(n=o.schema)==null?void 0:n.shape)!=null?s:{});return r.every(l=>d.includes(l))&&d.every(l=>r.includes(l))},{message:"Keys in 'config.def' must exactly match keys in 'config.schema'"})}),vt=(a=Je)=>zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1),modalities:zod.z.array(a).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),Mt),schema:zod.z.instanceof(zod.z.ZodObject)}).refine(t=>{var o,n;let s=Object.keys(t.def),r=Object.keys((n=(o=t.schema)==null?void 0:o.shape)!=null?n:{});return s.every(d=>r.includes(d))&&r.every(d=>s.includes(d))},{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 $o={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."},Bo={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."},Fo=a=>({type:"multi",title:"Stop sequence",description:`Enter up to ${a} sequences that will halt additional text output. The generated text will exclude these sequences.`}),zo={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."},Do={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."},Ko={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."},Ho={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."},Go={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."},Vo={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."},Yo={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."},Jo={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."},Wo={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."},Zo={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."},Qo={type:"boolean",title:"Echo",description:"If true, the response will contain the prompt."},Xo={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."},en={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."},tn={type:"object",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema."},g={TEMPERATURE:$o,MAX_TOKENS:Bo,STOP:Fo,TOP_A:zo,TOP_P:Do,TOP_K:Ko,MIN_P:Ho,FREQUENCY_PENALTY:Go,PRESENCE_PENALTY:Vo,REPETITION_PENALTY:Jo,SEED:Yo,LOG_PROBS:Wo,TOP_LOG_PROBS:Zo,ECHO:Qo,RESPONSE_FORMAT:Xo,RESPONSE_FORMAT_WITH_SCHEMA:en,RESPONSE_SCHEMA:tn};var z=a=>Object.fromEntries(Object.entries(a).filter(([t,o])=>o!=null));var _=a=>a==null?void 0:a.replace(/\/$/,"");var me=P({param:"temperature",title:g.TEMPERATURE.title,description:g.TEMPERATURE.description,min:0,max:1,step:.01,default:1}),de=a=>P({param:"max_tokens",title:g.MAX_TOKENS.title,description:g.MAX_TOKENS.description,min:0,max:a,step:1,default:0}),pe=a=>ft({param:"stop",title:g.STOP(a).title,description:g.STOP(a).description,max:a}),ce=P({param:"top_k",title:g.TOP_K.title,description:g.TOP_K.description,min:0,max:1e4,step:1,default:0}),ue=P({param:"top_p",title:g.TOP_P.title,description:g.TOP_P.description,min:0,max:1,step:.01,default:1}),he=P({param:"min_p",title:g.MIN_P.title,description:g.MIN_P.description,min:0,max:1,step:.01,default:0}),ge=P({param:"frequency_penalty",title:g.FREQUENCY_PENALTY.title,description:g.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),fe=P({param:"presence_penalty",title:g.PRESENCE_PENALTY.title,description:g.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),ye=P({param:"repetition_penalty",title:g.REPETITION_PENALTY.title,description:g.REPETITION_PENALTY.description,min:0,max:1e4,step:.01,default:0}),Te=P({param:"seed",title:g.SEED.title,description:g.SEED.description,min:0,max:1e6,step:1,default:0}),be=Et({param:"logprobs",title:g.LOG_PROBS.title,description:g.LOG_PROBS.description,default:!1}),Ce=le({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"]}),Ee=le({param:"response_format",title:g.RESPONSE_FORMAT.title,description:g.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),Re=Tt({param:"response_schema",title:g.RESPONSE_SCHEMA.title,description:g.RESPONSE_SCHEMA.description,objectSchema:Ge});var Pt=(a,t)=>zod.z.object({temperature:me.schema,maxTokens:de(a).schema,stop:pe(t).schema,topP:ue.schema,topK:ce.schema,minP:he.schema,frequencyPenalty:ge.schema,presencePenalty:fe.schema,repetitionPenalty:ye.schema,seed:Te.schema.transform(o=>o===0?void 0:o),logProbs:be.schema,toolChoice:Ce.schema,responseSchema:Re.schema,responseFormat:Ee.schema}),St=(a,t)=>({temperature:me.def,maxTokens:de(a).def,stop:pe(t).def,topP:ue.def,topK:ce.def,minP:he.def,frequencyPenalty:ge.def,presencePenalty:fe.def,repetitionPenalty:ye.def,seed:Te.def,logProbs:be.def,toolChoice:Ce.def,responseSchema:Re.def,responseFormat:Ee.def});var Me={base:(a,t)=>({def:St(a,t),schema:Pt(a,t)})};var wt=zod.z.enum([k,O,M,N]),xt={system:k,user:O,assistant:M,tool:N};var At=[b,I,w],jt=zod.z.enum([b,I,w]);var sn=zod.z.object({token_ids:zod.z.array(zod.z.number()),tokens:zod.z.array(zod.z.string()),token_logprobs:zod.z.array(zod.z.number())}),rn=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()})})),_t=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),prompt:zod.z.any(),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:rn.optional()}),logprobs:sn.nullable().optional(),seed:zod.z.number().nullable().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()}).nullable().optional()}),ln=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()})),qt=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({token_id:zod.z.number().nullable().optional(),role:zod.z.string().nullable().optional(),content:zod.z.string().nullable().optional(),tool_calls:ln.optional()}).or(zod.z.object({})),logprobs:zod.z.any().nullable().optional(),seed:zod.z.number().nullable().optional(),finish_reason:zod.z.string().nullable(),text:zod.z.string().nullable().optional()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var mn=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()})}),dn=zod.z.enum(["none","auto","required"]),pn=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),cn=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()})})),Ie=zod.z.string(),un=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)})}),hn=zod.z.object({role:zod.z.literal("system"),content:Ie}),gn=zod.z.object({role:zod.z.literal("user"),content:Ie}),fn=zod.z.object({role:zod.z.literal("assistant"),content:Ie.optional(),tool_calls:zod.z.array(un).min(1).optional()}),yn=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),Tn=zod.z.union([hn,gn,fn,yn]),kt=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(Tn).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.number().min(0).max(1).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),repetition_penalty:zod.z.number().min(0).max(2).nullable().optional(),response_format:cn.optional(),seed:zod.z.number().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(1).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),top_k:zod.z.number().min(0).max(1e4).nullable().optional(),min_p:zod.z.number().min(0).max(1).nullable().optional(),echo:zod.z.boolean().nullable().optional(),tools:zod.z.array(mn).optional(),tool_choice:dn.or(pn).optional()});var ve=It(wt,jt).parse({name:"together-ai-base-chat-model",description:"Base chat model for Together AI",maxInputTokens:128e3,maxOutputTokens:128e3,roles:xt,modalities:At,config:{def:Me.base(128e3,4).def,schema:Me.base(128e3,4).schema}});var bn="together-ai",q=class{constructor(){this.version="v1";this.name=bn;}chatModelLiterals(){return ["base"]}chatModelSchemas(){return {base:ve}}chatModel(t){let o=t.modelName;if(!o)throw new ee({info:"options.modelName is required",cause:new Error("options.modelName is required")});let n=V(T({},t),{modelName:o});return new D(ve,n)}embeddingModelLiterals(){return ["base"]}embeddingModelSchemas(){return {base:Pe}}embeddingModel(t){let o=t.modelName;if(!o)throw new ee({info:"options.modelName is required",cause:new Error("options.modelName is required")});let n=V(T({},t),{modelName:o});return new K(Pe,n)}};q.baseUrl="https://api.together.xyz/v1";var Cn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string()}),D=class{constructor(t,o){this.version="v1";let n=Cn.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=_(q.baseUrl),this.streamChatUrl=_(`${this.baseUrl}/chat/completions`),this.completeChatUrl=_(`${this.baseUrl}/chat/completions`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json",source:"adaline.ai"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}getTokenCount(t){return t.reduce((o,n)=>o+n.content.map(s=>s.modality==="text"?s.value:"").join(" ").length,0)}transformModelRequest(t){let o=kt.safeParse(t);if(!o.success)throw new L({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model;if(n.tool_choice&&(!n.tools||n.tools.length===0))throw new L({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'tool_choice' is specified")});let r={};n.response_format&&(r.responseFormat=n.response_format.type,n.response_format.type==="json_schema"&&(r.responseSchema={name:n.response_format.json_schema.name,description:n.response_format.json_schema.description||"",strict:n.response_format.json_schema.strict,schema:n.response_format.json_schema.schema})),n.tool_choice&&(typeof n.tool_choice=="string"?r.toolChoice=n.tool_choice:r.toolChoice=n.tool_choice.function.name),r.seed=n.seed,r.maxTokens=n.max_tokens,r.temperature=n.temperature,r.topP=n.top_p,r.minP=n.min_p,r.topK=n.top_k,r.repetitionPenalty=n.repetition_penalty,r.presencePenalty=n.presence_penalty,r.frequencyPenalty=n.frequency_penalty,r.repetitionPenalty=n.repetition_penalty,r.stop=n.stop,r.logProbs=n.logprobs!==0,r.echo=n.echo;let d=F().parse(z(r)),l=[],c={};n.messages.forEach(u=>{let f=u.role;switch(f){case"system":l.push({role:f,content:[{modality:b,value:u.content}]});break;case"user":l.push({role:f,content:[{modality:b,value:u.content}]});break;case"assistant":{let y=[];if(!u.content&&!u.tool_calls)throw new L({info:`Invalid model request for model : '${this.modelName}'`,cause:new Error("one of'content' or 'tool_calls' must be provided")});u.content&&y.push({modality:b,value:u.content}),u.tool_calls&&u.tool_calls.forEach((H,$t)=>{let G={modality:I,id:H.id,index:$t,name:H.function.name,arguments:H.function.arguments};y.push(G),c[G.id]=G;}),l.push({role:f,content:y});}break;case"tool":{let y=u;l.push({role:f,content:[{modality:w,id:y.tool_call_id,index:c[y.tool_call_id].index,name:c[y.tool_call_id].name,data:y.content}]});}break}});let h=[];return n.tools&&n.tools.forEach(u=>{h.push({type:"function",definition:{schema:{name:u.function.name,description:u.function.description||"",strict:u.function.strict,parameters:u.function.parameters}}});}),{modelName:s,config:d,messages:l,tools:h.length>0?h:void 0}}transformConfig(t,o,n){let s=t.toolChoice;delete t.toolChoice;let r=this.modelSchema.config.schema.safeParse(t);if(!r.success)throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:r.error});let d=r.data;s!==void 0&&(d.toolChoice=s),Object.keys(d).forEach(c=>{if(!(c in this.modelSchema.config.def))throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${c}',
|
|
7
7
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let l=Object.keys(d).reduce((c,h)=>{let u=this.modelSchema.config.def[h],f=u.param,y=d[h];return f==="max_tokens"&&u.type==="range"&&y===0?c[f]=u.max:f==="logprobs"&&u.type==="select-boolean"?y===!0?c[f]=1:c[f]=0:c[f]=y,c},{});if(l.top_logprobs&&!l.logprobs)throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'logprobs' must be 'true' when 'top_logprobs' is specified")});if("tool_choice"in l&&l.tool_choice!==void 0){let c=l.tool_choice;if(!n||n&&n.length===0)throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(n&&n.length>0){let h=this.modelSchema.config.def.toolChoice;if(!h.choices.includes(c))if(n.map(u=>u.definition.schema.name).includes(c))l.tool_choice={type:"function",function:{name:c}};else throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`toolChoice : '${c}' is not part of provided 'tools' names or
|
|
8
8
|
one of [${h.choices.join(", ")}]`)})}}if("response_format"in l&&l.response_format!==void 0){let c=l.response_format;if(c==="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 v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else l.response_format={type:c};}return l}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let o=t.map(s=>{let r=U().safeParse(s);if(!r.success)throw new E({info:"Invalid messages",cause:r.error});return r.data});return o.forEach(s=>{s.content.forEach(r=>{if(!this.modelSchema.modalities.includes(r.modality))throw new E({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${r.modality}',
|
|
9
9
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(s=>{if(!Object.keys(this.modelSchema.roles).includes(s.role))throw new E({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${s.role}',
|
|
10
10
|
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),{messages:o.map(s=>{switch(s.role){case k:{let r="";return s.content.forEach(d=>{if(d.modality===b)r+=d.value+`
|
|
11
|
-
`;else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:r}}case
|
|
11
|
+
`;else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:r}}case M:{let r="",d=[];return s.content.forEach(l=>{if(l.modality===b)r+=l.value+`
|
|
12
12
|
`;else if(l.modality===I)d.push({id:l.id,type:"function",function:{name:l.name,arguments:l.arguments}});else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${l.modality}'`)})}),T({role:this.modelSchema.roles[s.role],content:r},d.length>0?{tool_calls:d}:{})}case O:{let r="";return s.content.forEach(d=>{if(d.modality===b)r+=d.value+`
|
|
13
13
|
`;else throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' cannot have content with modality : '${d.modality}'`)})}),{role:this.modelSchema.roles[s.role],content:r}}case N:{if(s.content.length!==1)throw new E({info:`Invalid message for role : '${s.role}'`,cause:new Error(`role : '${s.role}' must have exactly one content item`)});if(s.content[0].modality!==w)throw new E({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' must have content with modality : '${w}'`)});let r=s.content[0];return {role:this.modelSchema.roles[s.role],tool_call_id:r.id,content:r.data}}default:throw new E({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${s.role}' is not supported,
|
|
14
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(I))throw new
|
|
15
|
-
`).filter(d=>d.trim()!=="");for(let d of n){if(d==="data: [DONE]")return;if(d.startsWith("data: {")&&d.endsWith("}")){let l;try{l=JSON.parse(d.substring(6));}catch(h){throw new j({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${l}`)})}let c=
|
|
16
|
-
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((d,l)=>{let h=this.modelSchema.config.def[l].param,u=s[l];return d[h]=u,d},{})}transformEmbeddingRequests(t){let o=
|
|
14
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(t){if(!this.modelSchema.modalities.includes(I))throw new te({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${I}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(s=>{let r=Ve().safeParse(s);if(!r.success)throw new te({info:"Invalid tools",cause:r.error});return r.data}).map(s=>({type:"function",function:s.definition.schema}))}}getCompleteChatUrl(t,o,n){return R(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(t,o,n){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(t,o,n){return R(this,null,function*(){let s=this.transformConfig(t,o,n),r=this.transformMessages(o);if(r.messages&&r.messages.length===0)throw new E({info:"Messages are required",cause:new Error("Messages are required")});let d=n?this.transformTools(n):{};return new Promise(l=>{l(T(T(T(T({},this.getDefaultParams()),s),r),d));})})}transformCompleteChatResponse(t){let o=_t.safeParse(t);if(o.success){if(o.data.choices.length===0)throw new j({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let n=o.data,s=[],r=n.choices[0].message;r.content&&s.push(ze(M,r.content)),r.tool_calls&&r.tool_calls.forEach((h,u)=>{s.push(De(M,u,h.id,h.function.name,h.function.arguments));});let d;n.usage&&(d={promptTokens:n.usage.prompt_tokens,completionTokens:n.usage.completion_tokens,totalTokens:n.usage.total_tokens});let l=[],c=n.choices[0].logprobs;return c&&c.tokens.forEach((h,u)=>{l.push({token:h,logProb:c.token_logprobs[u],bytes:null,topLogProbs:[]});}),{messages:s,usage:d,logProbs:l}}throw new j({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(t,o,n){return R(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(t,o,n){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(t,o,n){return R(this,null,function*(){let s=this.transformConfig(t,o,n),r=this.transformMessages(o);if(r.messages&&r.messages.length===0)throw new E({info:"Messages are required",cause:new Error("Messages are required")});let d=n?this.transformTools(n):{};return new Promise(l=>{l(T(T(T(T({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),s),r),d));})})}transformStreamChatResponseChunk(t,o){return je(this,null,function*(){var s,r;let n=(o+t).split(`
|
|
15
|
+
`).filter(d=>d.trim()!=="");for(let d of n){if(d==="data: [DONE]")return;if(d.startsWith("data: {")&&d.endsWith("}")){let l;try{l=JSON.parse(d.substring(6));}catch(h){throw new j({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${l}`)})}let c=qt.safeParse(l);if(c.success){let h={partialMessages:[]},u=c.data;if(u.choices.length>0){let f=u.choices[0].delta;if(f!==void 0&&Object.keys(f).length!==0){if("content"in f&&f.content!==null)h.partialMessages.push(Ke(M,f.content));else if("tool_calls"in f&&f.tool_calls){let y=f.tool_calls.at(0);h.partialMessages.push(He(M,y.index,y.id,(s=y.function)==null?void 0:s.name,(r=y.function)==null?void 0:r.arguments));}}}u.usage&&(h.usage={promptTokens:u.usage.prompt_tokens,completionTokens:u.usage.completion_tokens,totalTokens:u.usage.total_tokens}),yield {partialResponse:h,buffer:o};}else throw new j({info:"Invalid response from model",cause:c.error})}}})}};var Ot=[x],Nt=zod.z.enum([x]);var Lt=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()}).optional()});var Rn=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)),Ut=zod.z.object({model:zod.z.string().min(1).optional(),input:Rn});var Mn=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string()}),K=class{constructor(t,o){this.version="v1";let n=Mn.parse(o);this.modelSchema=t,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=_(q.baseUrl),this.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.modelName}}getRetryDelay(t){return {shouldRetry:!0,delayMs:0}}getTokenCount(t){return t.requests.reduce((o,n)=>o+n.length,0)}transformModelRequest(t){let o=Ut.safeParse(t);if(!o.success)throw new L({info:"Invalid model request",cause:o.error});let n=o.data,s=n.model,r={},d=F().parse(z(r)),l={modality:x,requests:[...n.input]};return {modelName:s,config:d,embeddingRequests:l}}transformConfig(t,o){let n=this.modelSchema.config.schema.safeParse(t);if(!n.success)throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let s=n.data;return Object.keys(s).forEach(d=>{if(!this.modelSchema.config.def[d])throw new v({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',
|
|
16
|
+
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((d,l)=>{let h=this.modelSchema.config.def[l].param,u=s[l];return d[h]=u,d},{})}transformEmbeddingRequests(t){let o=We().safeParse(t);if(!o.success)throw new oe({info:"Invalid embedding requests",cause:o.error});if(t.modality!==x)throw new oe({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${x}' modality is supported for model : '${this.modelName}'`)});return {input:o.data.requests}}getGetEmbeddingsUrl(t,o){return R(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,o){return R(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,o){return R(this,null,function*(){return new Promise(n=>{n(T(T(T({},this.getDefaultParams()),this.transformConfig(t,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(t){var n;let o=Lt.safeParse(t);if(o.success){let s=o.data,r=s.data.map(d=>({index:d.index,embedding:d.embedding}));return {encodingFormat:X,embeddings:r,usage:{totalTokens:(n=s.usage)==null?void 0:n.total_tokens}}}throw new j({info:"Invalid response from model",cause:o.error})}};var Pe=vt(Nt).parse({name:"together-ai-base-embedding-model",description:"Base embedding model for Together AI",maxInputTokens:128e3,maxOutputTokens:128e3,modalities:Ot,config:{def:{},schema:zod.z.object({})}});
|
|
17
17
|
|
|
18
|
-
exports.BaseChatModel =
|
|
19
|
-
exports.BaseChatModelSchema =
|
|
20
|
-
exports.BaseEmbeddingModel =
|
|
21
|
-
exports.BaseEmbeddingModelOptions =
|
|
22
|
-
exports.BaseEmbeddingModelSchema =
|
|
23
|
-
exports.ChatModelBaseConfigDef =
|
|
24
|
-
exports.ChatModelBaseConfigSchema =
|
|
18
|
+
exports.BaseChatModel = D;
|
|
19
|
+
exports.BaseChatModelSchema = ve;
|
|
20
|
+
exports.BaseEmbeddingModel = K;
|
|
21
|
+
exports.BaseEmbeddingModelOptions = Mn;
|
|
22
|
+
exports.BaseEmbeddingModelSchema = Pe;
|
|
23
|
+
exports.ChatModelBaseConfigDef = St;
|
|
24
|
+
exports.ChatModelBaseConfigSchema = Pt;
|
|
25
25
|
exports.TogetherAI = q;
|
|
26
26
|
exports.TogetherAIChatModelConfigs = Me;
|
|
27
|
-
exports.TogetherAIEmbeddingModelModalities =
|
|
28
|
-
exports.TogetherAIEmbeddingModelModalitiesEnum =
|
|
29
|
-
exports.TogetherAIEmbeddingRequest =
|
|
30
|
-
exports.TogetherAIEmbeddingRequestInput =
|
|
31
|
-
exports.TogetherAIGetEmbeddingsResponse =
|
|
32
|
-
exports.frequencyPenalty =
|
|
33
|
-
exports.logProbs =
|
|
34
|
-
exports.maxTokens =
|
|
35
|
-
exports.minP =
|
|
36
|
-
exports.presencePenalty =
|
|
37
|
-
exports.repetitionPenalty =
|
|
38
|
-
exports.responseFormat =
|
|
39
|
-
exports.responseSchema =
|
|
40
|
-
exports.seed =
|
|
41
|
-
exports.stop =
|
|
42
|
-
exports.temperature =
|
|
43
|
-
exports.toolChoice =
|
|
44
|
-
exports.topK =
|
|
45
|
-
exports.topP =
|
|
27
|
+
exports.TogetherAIEmbeddingModelModalities = Ot;
|
|
28
|
+
exports.TogetherAIEmbeddingModelModalitiesEnum = Nt;
|
|
29
|
+
exports.TogetherAIEmbeddingRequest = Ut;
|
|
30
|
+
exports.TogetherAIEmbeddingRequestInput = Rn;
|
|
31
|
+
exports.TogetherAIGetEmbeddingsResponse = Lt;
|
|
32
|
+
exports.frequencyPenalty = ge;
|
|
33
|
+
exports.logProbs = be;
|
|
34
|
+
exports.maxTokens = de;
|
|
35
|
+
exports.minP = he;
|
|
36
|
+
exports.presencePenalty = fe;
|
|
37
|
+
exports.repetitionPenalty = ye;
|
|
38
|
+
exports.responseFormat = Ee;
|
|
39
|
+
exports.responseSchema = Re;
|
|
40
|
+
exports.seed = Te;
|
|
41
|
+
exports.stop = pe;
|
|
42
|
+
exports.temperature = me;
|
|
43
|
+
exports.toolChoice = Ce;
|
|
44
|
+
exports.topK = ce;
|
|
45
|
+
exports.topP = ue;
|
|
46
46
|
//# sourceMappingURL=index.js.map
|
|
47
47
|
//# sourceMappingURL=index.js.map
|