@adaline/google 0.7.0 → 0.8.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.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 +1 -1
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var lt=Object.defineProperty;var Co=Object.getOwnPropertySymbols;var mt=Object.p
|
|
|
11
11
|
one of [${C.choices.join(", ")}]`)})}}return G(G({generation_config:m},p?{tool_config:p}:{}),r?{safety_settings:r}:{})}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(n=>{let m=types.Message().safeParse(n);if(!m.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:m.error});return m.data});o.forEach(n=>{n.content.forEach(m=>{if(!this.modelSchema.modalities.includes(m.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${m.modality}',
|
|
12
12
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),o.forEach(n=>{if(!Object.keys(this.modelSchema.roles).includes(n.role))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${n.role}',
|
|
13
13
|
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let t={parts:[]},s=[];if(o.forEach(n=>{switch(n.role){case types.SystemRoleLiteral:n.content.forEach(m=>{if(m.modality===types.TextModalityLiteral)t.parts.push({text:m.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${m.modality}'`)})});break;case types.AssistantRoleLiteral:{let m=[];n.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)m.push({text:r.value});else if(r.modality===types.ToolCallModalityLiteral)m.push({function_call:{name:r.name,args:JSON.parse(r.arguments)}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})}),s.push({role:this.modelSchema.roles[n.role],parts:m});}break;case types.UserRoleLiteral:{let m=[];n.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)m.push({text:r.value});else if(r.modality===types.ImageModalityLiteral){if(r.value.type==="base64")m.push({inline_data:{mime_type:r.value.media_type,data:r.value.base64}});else if(r.value.type==="url")throw new provider.InvalidMessagesError({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${r.value.type}'`)})}else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})}),s.push({role:this.modelSchema.roles[n.role],parts:m});}break;case types.ToolRoleLiteral:{let m=[];n.content.forEach(r=>{if(r.modality===types.ToolResponseModalityLiteral)m.push({function_response:{name:r.name,response:JSON.parse(r.data)}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})}),s.push({role:this.modelSchema.roles[n.role],parts:m});}break;default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${n.role}' is not supported,
|
|
14
|
-
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[types.UserRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let l=n=>n===this.modelSchema.roles[types.UserRoleLiteral]||n===this.modelSchema.roles[types.ToolRoleLiteral]?[this.modelSchema.roles[types.AssistantRoleLiteral]]:[this.modelSchema.roles[types.UserRoleLiteral],this.modelSchema.roles[types.ToolRoleLiteral]];for(let n=1;n<s.length;n++)if(!l(s[n-1].role).includes(s[n].role))throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${s[n].role}' after message with role : '${s[n-1].role}'`)});if(s[s.length-1].role!==this.modelSchema.roles[types.UserRoleLiteral]&&s[s.length-1].role!==this.modelSchema.roles[types.ToolRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return G({contents:s},t.parts.length>0?{system_instruction:t}:{})}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(s=>{let l=types.Tool().safeParse(s);if(!l.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:l.error});return l.data}).map(s=>({function_declarations:[{name:s.definition.schema.name,description:s.definition.schema.description,parameters:s.definition.schema.parameters}]}))}}getCompleteChatUrl(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,o,t){return R(this,null,function*(){let s=this.transformConfig(e,o,t),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=t?this.transformTools(t):{};return new Promise(m=>{m(G(G(G(G({},this.getDefaultParams()),s),l),n));})})}transformCompleteChatResponse(e){let o=Ro.safeParse(e);if(o.success){if(o.data.candidates.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let t=o.data,s=[],l,n=t.candidates[0].content;if(n){let p=n.parts.map((f,C)=>{if("text"in f&&f.text!==void 0)return types.createTextContent(f.text);if("functionCall"in f&&f.functionCall!==void 0)return types.createToolCallContent(C,`${f.functionCall.name}_${C}`,f.functionCall.name,JSON.stringify(f.functionCall.args))});return s.push({role:types.AssistantRoleLiteral,content:p}),t.usageMetadata&&(l={promptTokens:t.usageMetadata.promptTokenCount,totalTokens:t.usageMetadata.totalTokenCount,completionTokens:t.usageMetadata.candidatesTokenCount||0}),{messages:s,usage:l,logProbs:void 0}}let m=t.candidates[0].safetyRatings;if(m&&m.length>0&&m.forEach(p=>{if(p.blocked)throw new provider.ModelResponseError({info:`Blocked content for category: ${p.category} with probability: ${p.probability}`,cause:new Error(`Blocked content for category: ${p.category} with probability: ${p.probability}`)})}),t.candidates[0].finishReason==="SAFETY")throw new provider.ModelResponseError({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,o,t){return R(this,null,function*(){let s=this.transformConfig(e,o,t),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=t?this.transformTools(t):{};return new Promise(m=>{m(G(G(G(G({},this.getDefaultParams()),s),l),n));})})}transformStreamChatResponseChunk(e,o){return Mo(this,null,function*(){let t=(o+e).split(",\r").filter(s=>s.trim()!=="");for(let s of t){let l=s;if(l=l.replace(/\n/g,""),l.startsWith("["))l=l.slice(1);else if(l.endsWith("]")){if(l==="]")return;l=l.slice(0,-1);}let n;try{n=JSON.parse(l);}catch(r){if(r instanceof SyntaxError){o=l;continue}else throw r}o="";let m=xo.safeParse(n);if(m.success){let r={partialMessages:[]},p=m.data;if(p.candidates.length>0){let f=p.candidates[0].content;f&&"parts"in f&&f.parts.length>0&&f.parts.forEach((C,M)=>{if("text"in C&&C.text!==void 0&&r.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,C.text)),"functionCall"in C&&C.functionCall!==void 0){let g=C.functionCall;r.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,M,`${g.name}_${M}`,g.name,JSON.stringify(g.args)));}});}p.usageMetadata&&(r.usage={promptTokens:p.usageMetadata.promptTokenCount,completionTokens:p.usageMetadata.candidatesTokenCount,totalTokens:p.usageMetadata.totalTokenCount}),yield {partialResponse:r,buffer:o};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:m.error})}yield {partialResponse:{partialMessages:[]},buffer:o};})}};var P=class extends T{transformMessages(e){let o=super.transformMessages(e);if(o.systemInstruction){let t={role:this.modelSchema.roles[types.UserRoleLiteral],parts:o.systemInstruction.parts};o.contents.unshift(t),delete o.systemInstruction;}return o}};var Ne="gemini-pro",Kt="A model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Fe=provider.ChatModelSchema(u,L).parse({name:Ne,description:Kt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),qo=h,me=class extends P{constructor(e){super(Fe,e);}};var qe="gemini-pro-vision",Jt="An image understanding model to handle a broad range of applications",$e=provider.ChatModelSchema(u,le).parse({name:qe,description:Jt,maxInputTokens:12288,maxOutputTokens:4096,roles:y,modalities:re,config:{def:c.c1(1,.4,4096,4,1,32).def,schema:c.c1(1,.4,4096,4,1,32).schema}}),$o=h,de=class extends P{constructor(e){super($e,e);}};var ze="gemini-1.0-pro",Xt="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",je=provider.ChatModelSchema(u,L).parse({name:ze,description:Xt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),zo=h,pe=class extends P{constructor(e){super(je,e);}};var Be="gemini-1.0-pro-001",Zt="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",De=provider.ChatModelSchema(u,L).parse({name:Be,description:Zt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),jo=h,ce=class extends P{constructor(e){super(De,e);}};var Ue="gemini-1.0-pro-latest",os="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ae=provider.ChatModelSchema(u,L).parse({name:Ue,description:os,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),Bo=h,fe=class extends P{constructor(e){super(Ae,e);}};var Ve="gemini-1.0-pro-vision",ss="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",He=provider.ChatModelSchema(u,le).parse({name:Ve,description:ss,maxInputTokens:12288,maxOutputTokens:4096,roles:y,modalities:re,config:{def:c.c1(1,.4,4096,4,1,32).def,schema:c.c1(1,.4,4096,4,1,32).schema}}),Do=h,he=class extends P{constructor(e){super(He,e);}};var Ke="gemini-1.5-flash",is="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ye=provider.ChatModelSchema(u,E).parse({name:Ke,description:is,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Uo=h,ge=class extends T{constructor(e){super(Ye,e);}};var Je="gemini-1.5-flash-001",rs="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",We=provider.ChatModelSchema(u,E).parse({name:Je,description:rs,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ao=h,ue=class extends T{constructor(e){super(We,e);}};var Xe="gemini-1.5-flash-002",ms="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Qe=provider.ChatModelSchema(u,E).parse({name:Xe,description:ms,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,40).def,schema:c.c1(2,1,8192,4,.95,40).schema}}),Vo=h,ye=class extends T{constructor(e){super(Qe,e);}};var Ze="gemini-1.5-flash-latest",ps="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",eo=provider.ChatModelSchema(u,E).parse({name:Ze,description:ps,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ho=h,Ce=class extends T{constructor(e){super(eo,e);}};var oo="gemini-1.5-pro",fs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",to=provider.ChatModelSchema(u,E).parse({name:oo,description:fs,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ko=h,Te=class extends T{constructor(e){super(to,e);}};var so="gemini-1.5-pro-001",gs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",no=provider.ChatModelSchema(u,E).parse({name:so,description:gs,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Yo=h,Me=class extends T{constructor(e){super(no,e);}};var io="gemini-1.5-pro-002",ys="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",ao=provider.ChatModelSchema(u,E).parse({name:io,description:ys,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,40).def,schema:c.c1(2,1,8192,4,.95,40).schema}}),Jo=h,Ge=class extends T{constructor(e){super(ao,e);}};var ro="gemini-1.5-pro-latest",Ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",lo=provider.ChatModelSchema(u,E).parse({name:ro,description:Ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Wo=h,be=class extends T{constructor(e){super(lo,e);}};var Se=[types.EmbeddingTextModalityLiteral],Re=zod.z.enum([types.EmbeddingTextModalityLiteral]);var nt=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))});var Gs=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),it=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Gs).min(1),outputDimensionality:zod.z.number().int().min(1).optional()});var oe=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),A=class{constructor(e,o){this.version="v1";let t=oe.parse(o);this.modelSchema=e,this.modelName=t.modelName,this.apiKey=t.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(t.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(t.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,t)=>o+t.length,0)}transformModelRequest(e){let o=it.safeParse(e);if(!o.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:o.error});let t=o.data,s=t.model,l={outputDimensionality:t.outputDimensionality},n=types.Config().parse(provider.removeUndefinedEntries(l)),m={modality:types.EmbeddingTextModalityLiteral,requests:t.requests.reduce((r,p)=>(r.push(...p.content.parts.map(f=>f.text)),r),[])};return {modelName:s,config:n,embeddingRequests:m}}transformConfig(e,o){let t=this.modelSchema.config.schema.safeParse(e);if(!t.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:t.error});let s=t.data;return Object.keys(s).forEach(n=>{if(!this.modelSchema.config.def[n])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${n}',
|
|
14
|
+
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[types.UserRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let l=n=>n===this.modelSchema.roles[types.UserRoleLiteral]||n===this.modelSchema.roles[types.ToolRoleLiteral]?[this.modelSchema.roles[types.AssistantRoleLiteral]]:[this.modelSchema.roles[types.UserRoleLiteral],this.modelSchema.roles[types.ToolRoleLiteral]];for(let n=1;n<s.length;n++)if(!l(s[n-1].role).includes(s[n].role))throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${s[n].role}' after message with role : '${s[n-1].role}'`)});if(s[s.length-1].role!==this.modelSchema.roles[types.UserRoleLiteral]&&s[s.length-1].role!==this.modelSchema.roles[types.ToolRoleLiteral])throw new provider.InvalidMessagesError({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return G({contents:s},t.parts.length>0?{system_instruction:t}:{})}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:[{function_declarations:e.map(s=>{let l=types.Tool().safeParse(s);if(!l.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:l.error});return l.data}).map(s=>({name:s.definition.schema.name,description:s.definition.schema.description,parameters:s.definition.schema.parameters}))}]}}getCompleteChatUrl(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getCompleteChatData(e,o,t){return R(this,null,function*(){let s=this.transformConfig(e,o,t),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=t?this.transformTools(t):{};return new Promise(m=>{m(G(G(G(G({},this.getDefaultParams()),s),l),n));})})}transformCompleteChatResponse(e){let o=Ro.safeParse(e);if(o.success){if(o.data.candidates.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let t=o.data,s=[],l,n=t.candidates[0].content;if(n){let p=n.parts.map((f,C)=>{if("text"in f&&f.text!==void 0)return types.createTextContent(f.text);if("functionCall"in f&&f.functionCall!==void 0)return types.createToolCallContent(C,`${f.functionCall.name}_${C}`,f.functionCall.name,JSON.stringify(f.functionCall.args))});return s.push({role:types.AssistantRoleLiteral,content:p}),t.usageMetadata&&(l={promptTokens:t.usageMetadata.promptTokenCount,totalTokens:t.usageMetadata.totalTokenCount,completionTokens:t.usageMetadata.candidatesTokenCount||0}),{messages:s,usage:l,logProbs:void 0}}let m=t.candidates[0].safetyRatings;if(m&&m.length>0&&m.forEach(p=>{if(p.blocked)throw new provider.ModelResponseError({info:`Blocked content for category: ${p.category} with probability: ${p.probability}`,cause:new Error(`Blocked content for category: ${p.category} with probability: ${p.probability}`)})}),t.candidates[0].finishReason==="SAFETY")throw new provider.ModelResponseError({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.streamChatUrl);})})}getStreamChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(s=>{s(this.getDefaultHeaders());})})}getStreamChatData(e,o,t){return R(this,null,function*(){let s=this.transformConfig(e,o,t),l=this.transformMessages(o);if(l.messages&&l.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let n=t?this.transformTools(t):{};return new Promise(m=>{m(G(G(G(G({},this.getDefaultParams()),s),l),n));})})}transformStreamChatResponseChunk(e,o){return Mo(this,null,function*(){let t=(o+e).split(",\r").filter(s=>s.trim()!=="");for(let s of t){let l=s;if(l=l.replace(/\n/g,""),l.startsWith("["))l=l.slice(1);else if(l.endsWith("]")){if(l==="]")return;l=l.slice(0,-1);}let n;try{n=JSON.parse(l);}catch(r){if(r instanceof SyntaxError){o=l;continue}else throw r}o="";let m=xo.safeParse(n);if(m.success){let r={partialMessages:[]},p=m.data;if(p.candidates.length>0){let f=p.candidates[0].content;f&&"parts"in f&&f.parts.length>0&&f.parts.forEach((C,M)=>{if("text"in C&&C.text!==void 0&&r.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,C.text)),"functionCall"in C&&C.functionCall!==void 0){let g=C.functionCall;r.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,M,`${g.name}_${M}`,g.name,JSON.stringify(g.args)));}});}p.usageMetadata&&(r.usage={promptTokens:p.usageMetadata.promptTokenCount,completionTokens:p.usageMetadata.candidatesTokenCount,totalTokens:p.usageMetadata.totalTokenCount}),yield {partialResponse:r,buffer:o};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:m.error})}yield {partialResponse:{partialMessages:[]},buffer:o};})}};var P=class extends T{transformMessages(e){let o=super.transformMessages(e);if(o.systemInstruction){let t={role:this.modelSchema.roles[types.UserRoleLiteral],parts:o.systemInstruction.parts};o.contents.unshift(t),delete o.systemInstruction;}return o}};var Ne="gemini-pro",Kt="A model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Fe=provider.ChatModelSchema(u,L).parse({name:Ne,description:Kt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),qo=h,me=class extends P{constructor(e){super(Fe,e);}};var qe="gemini-pro-vision",Jt="An image understanding model to handle a broad range of applications",$e=provider.ChatModelSchema(u,le).parse({name:qe,description:Jt,maxInputTokens:12288,maxOutputTokens:4096,roles:y,modalities:re,config:{def:c.c1(1,.4,4096,4,1,32).def,schema:c.c1(1,.4,4096,4,1,32).schema}}),$o=h,de=class extends P{constructor(e){super($e,e);}};var ze="gemini-1.0-pro",Xt="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",je=provider.ChatModelSchema(u,L).parse({name:ze,description:Xt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),zo=h,pe=class extends P{constructor(e){super(je,e);}};var Be="gemini-1.0-pro-001",Zt="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",De=provider.ChatModelSchema(u,L).parse({name:Be,description:Zt,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),jo=h,ce=class extends P{constructor(e){super(De,e);}};var Ue="gemini-1.0-pro-latest",os="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ae=provider.ChatModelSchema(u,L).parse({name:Ue,description:os,maxInputTokens:30720,maxOutputTokens:2048,roles:y,modalities:I,config:{def:c.base(1,.9,2048,4,1).def,schema:c.base(1,.9,2048,4,1).schema}}),Bo=h,fe=class extends P{constructor(e){super(Ae,e);}};var Ve="gemini-1.0-pro-vision",ss="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",He=provider.ChatModelSchema(u,le).parse({name:Ve,description:ss,maxInputTokens:12288,maxOutputTokens:4096,roles:y,modalities:re,config:{def:c.c1(1,.4,4096,4,1,32).def,schema:c.c1(1,.4,4096,4,1,32).schema}}),Do=h,he=class extends P{constructor(e){super(He,e);}};var Ke="gemini-1.5-flash",is="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ye=provider.ChatModelSchema(u,E).parse({name:Ke,description:is,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Uo=h,ge=class extends T{constructor(e){super(Ye,e);}};var Je="gemini-1.5-flash-001",rs="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",We=provider.ChatModelSchema(u,E).parse({name:Je,description:rs,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ao=h,ue=class extends T{constructor(e){super(We,e);}};var Xe="gemini-1.5-flash-002",ms="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Qe=provider.ChatModelSchema(u,E).parse({name:Xe,description:ms,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,40).def,schema:c.c1(2,1,8192,4,.95,40).schema}}),Vo=h,ye=class extends T{constructor(e){super(Qe,e);}};var Ze="gemini-1.5-flash-latest",ps="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",eo=provider.ChatModelSchema(u,E).parse({name:Ze,description:ps,maxInputTokens:1e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ho=h,Ce=class extends T{constructor(e){super(eo,e);}};var oo="gemini-1.5-pro",fs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",to=provider.ChatModelSchema(u,E).parse({name:oo,description:fs,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Ko=h,Te=class extends T{constructor(e){super(to,e);}};var so="gemini-1.5-pro-001",gs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",no=provider.ChatModelSchema(u,E).parse({name:so,description:gs,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Yo=h,Me=class extends T{constructor(e){super(no,e);}};var io="gemini-1.5-pro-002",ys="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",ao=provider.ChatModelSchema(u,E).parse({name:io,description:ys,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,40).def,schema:c.c1(2,1,8192,4,.95,40).schema}}),Jo=h,Ge=class extends T{constructor(e){super(ao,e);}};var ro="gemini-1.5-pro-latest",Ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",lo=provider.ChatModelSchema(u,E).parse({name:ro,description:Ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:y,modalities:_,config:{def:c.c1(2,1,8192,4,.95,64).def,schema:c.c1(2,1,8192,4,.95,64).schema}}),Wo=h,be=class extends T{constructor(e){super(lo,e);}};var Se=[types.EmbeddingTextModalityLiteral],Re=zod.z.enum([types.EmbeddingTextModalityLiteral]);var nt=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))});var Gs=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),it=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(Gs).min(1),outputDimensionality:zod.z.number().int().min(1).optional()});var oe=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),A=class{constructor(e,o){this.version="v1";let t=oe.parse(o);this.modelSchema=e,this.modelName=t.modelName,this.apiKey=t.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(t.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(t.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,t)=>o+t.length,0)}transformModelRequest(e){let o=it.safeParse(e);if(!o.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:o.error});let t=o.data,s=t.model,l={outputDimensionality:t.outputDimensionality},n=types.Config().parse(provider.removeUndefinedEntries(l)),m={modality:types.EmbeddingTextModalityLiteral,requests:t.requests.reduce((r,p)=>(r.push(...p.content.parts.map(f=>f.text)),r),[])};return {modelName:s,config:n,embeddingRequests:m}}transformConfig(e,o){let t=this.modelSchema.config.schema.safeParse(e);if(!t.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:t.error});let s=t.data;return Object.keys(s).forEach(n=>{if(!this.modelSchema.config.def[n])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${n}',
|
|
15
15
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(s).reduce((n,m)=>{let p=this.modelSchema.config.def[m].param,f=s[m];return n[p]=f,n},{})}transformEmbeddingRequests(e){let o=types.EmbeddingRequests().safeParse(e);if(!o.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:o.error});if(e.modality!==types.EmbeddingTextModalityLiteral)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${types.EmbeddingTextModalityLiteral}' modality is supported for model : '${this.modelName}'`)});return {requests:o.data.requests.map(s=>({model:`models/${this.modelName}`,content:{parts:[{text:s}]}}))}}getGetEmbeddingsUrl(e,o){return R(this,null,function*(){return new Promise(t=>{t(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return R(this,null,function*(){return new Promise(t=>{t(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return R(this,null,function*(){return new Promise(t=>{let s=this.transformConfig(e),l=this.transformEmbeddingRequests(o);if(o.requests.length===0)throw new provider.InvalidEmbeddingRequestsError({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});s.outputDimensionality&&(l.requests.forEach(n=>{n.outputDimensionality=s.outputDimensionality;}),delete s.outputDimensionality),t(G(G(G({},this.getDefaultParams()),s),l));})})}transformGetEmbeddingsResponse(e){let o=nt.safeParse(e);if(o.success){let s=o.data.embeddings.map((l,n)=>({index:n,embedding:l.values}));return {encodingFormat:types.FloatEmbeddingLiteral,embeddings:s}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}};var mo="text-embedding-001",xs="text-embedding-001",po=provider.EmbeddingModelSchema(Re).parse({name:mo,description:xs,modalities:Se,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),Xo=oe,_e=class extends A{constructor(e){super(po,e);}};var co="text-embedding-004",Is="text-embedding-004",fo=provider.EmbeddingModelSchema(Re).parse({name:co,description:Is,modalities:Se,maxInputTokens:2048,maxOutputTokens:768,config:{def:j.base(768).def,schema:j.base(768).schema}}),Qo=oe,Ee=class extends A{constructor(e){super(fo,e);}};
|
|
16
16
|
|
|
17
17
|
exports.BaseChatModel = T;
|