UNPKG

@adaline/groq

Version:
52 lines (49 loc) 13.7 kB
'use strict'; var provider = require('@adaline/provider'); var zod = require('zod'); var openai = require('@adaline/openai'); var a={"gemma2-9b-it":{modelName:"gemma2-9b-it",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.2,outputPricePerMillion:.2}}}]},"llama-3.1-8b-instant":{modelName:"llama-3.1-8b-instant",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.05,outputPricePerMillion:.08}}}]},"llama-3.2-11b-vision-preview":{modelName:"llama-3.2-11b-vision-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.18,outputPricePerMillion:.18}}}]},"llama-3.2-1b-preview":{modelName:"llama-3.2-1b-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.04,outputPricePerMillion:.04}}}]},"llama-3.2-3b-preview":{modelName:"llama-3.2-3b-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.06,outputPricePerMillion:.06}}}]},"llama-3.2-90b-vision-preview":{modelName:"llama-3.2-90b-vision-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.7,outputPricePerMillion:.8}}}]},"llama3-70b-8192":{modelName:"llama3-70b-8192",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.59,outputPricePerMillion:.79}}}]},"llama3-8b-8192":{modelName:"llama3-8b-8192",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.05,outputPricePerMillion:.08}}}]},"llama-guard-3-8b":{modelName:"llama-guard-3-8b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.2,outputPricePerMillion:.2}}}]}};var n=zod.z.object({modelName:zod.z.string().min(1),apiKey:zod.z.string().min(1)}),t=class extends openai.BaseChatModel{constructor(i,c){let r=n.parse(c),p=h.baseUrl;super(i,{modelName:r.modelName,apiKey:r.apiKey,baseUrl:p,completeChatUrl:`${p}/chat/completions`,streamChatUrl:`${p}/chat/completions`});this.version="v1";this.modelSchema=i,this.modelName=r.modelName,this.groqApiKey=r.apiKey;}transformMessages(i){let c=i.some(l=>l.role==="system"),r=i.some(l=>l.content.some(_=>_.modality==="image"));if(c&&r)throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error("Prompting with images is incompatible with system messages`)")});let p=super.transformMessages(i);return p.messages.forEach(l=>{l.role==="system"?typeof l.content!="string"&&(l.content=l.content.map(_=>_.text).join(` `)):l.role==="assistant"&&l.content&&typeof l.content!="string"&&(l.content=l.content.map(_=>_.text).join(` `));}),p}getModelPricing(){if(!(this.modelName in a))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return a[this.modelName]}};var v=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),N=s=>provider.RangeConfigItem({param:"max_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:s,step:1,default:0}),q=provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(4).title,description:provider.CHAT_CONFIG.STOP(4).description,max:4}),w=provider.RangeConfigItem({param:"top_p",title:provider.CHAT_CONFIG.TOP_P.title,description:provider.CHAT_CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),z=provider.RangeConfigItem({param:"frequency_penalty",title:provider.CHAT_CONFIG.FREQUENCY_PENALTY.title,description:provider.CHAT_CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),B=provider.RangeConfigItem({param:"presence_penalty",title:provider.CHAT_CONFIG.PRESENCE_PENALTY.title,description:provider.CHAT_CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),D=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),V=provider.SelectStringConfigItem({param:"response_format",title:provider.CHAT_CONFIG.RESPONSE_FORMAT.title,description:provider.CHAT_CONFIG.RESPONSE_FORMAT.description,default:"text",choices:["text","json_object"]}),F=provider.SelectStringConfigItem({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"]});var W=s=>zod.z.object({temperature:v.schema,maxTokens:N(s).schema,stop:q.schema,topP:w.schema,frequencyPenalty:z.schema,presencePenalty:B.schema,seed:D.schema.transform(e=>e===0?void 0:e),responseFormat:V.schema,toolChoice:F.schema}),ee=s=>({temperature:v.def,maxTokens:N(s).def,stop:q.def,topP:w.def,frequencyPenalty:z.def,presencePenalty:B.def,seed:D.def,responseFormat:V.def,toolChoice:F.def});var o={base:s=>({def:ee(s),schema:W(s)})};var u="gemma2-9b-it",ge="Gemma is a family of lightweight, state-of-the-art open models from Google, built from the same research and technology used to create the Gemini models.",U=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:u,description:ge,maxInputTokens:8192,maxOutputTokens:4096,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(4096).def,schema:o.base(4096).schema},price:a[u]}),oe=n,M=class extends t{constructor(e){super(U,e);}};var f="llama-3.1-8b-instant",Ie="The Llama 3.1 instruction tuned text only models (8B, 70B, 405B) are optimized for multilingual dialogue use cases and outperform many of the available open source and closed chat models on common industry benchmarks.",j=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:f,description:Ie,maxInputTokens:128e3,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:a[f]}),ae=n,b=class extends t{constructor(e){super(j,e);}};var y="llama-3.2-11b-vision-preview",ve="The Llama 3.2-Vision instruction-tuned models are optimized for visual recognition, image reasoning, captioning, and answering general questions about an image. The models outperform many of the available open source and closed multimodal models on common industry benchmarks.",K=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelModalitiesEnum).parse({name:y,description:ve,maxInputTokens:128e3,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:a[y]}),te=n,T=class extends t{constructor(e){super(K,e);}};var O="llama-3.2-1b-preview",De="The Llama 3.2 instruction-tuned text only models are optimized for multilingual dialogue use cases, including agentic retrieval and summarization tasks. They outperform many of the available open source and closed chat models on common industry benchmarks.",$=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:O,description:De,maxInputTokens:128e3,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:a[O]}),se=n,g=class extends t{constructor(e){super($,e);}};var C="llama-3.2-3b-preview",$e="The Llama 3.2 instruction-tuned text only models are optimized for multilingual dialogue use cases, including agentic retrieval and summarization tasks. They outperform many of the available open source and closed chat models on common industry benchmarks.",Y=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:C,description:$e,maxInputTokens:128e3,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:a[C]}),ie=n,L=class extends t{constructor(e){super(Y,e);}};var x="llama-3.2-90b-vision-preview",Je="The Llama 3.2-90B Vision instruction-tuned models are optimized for advanced visual recognition, complex image reasoning, detailed captioning, and answering intricate questions about images. These models achieve state-of-the-art results on multiple industry benchmarks for multimodal tasks.",Q=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelModalitiesEnum).parse({name:x,description:Je,maxInputTokens:131072,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:a[x]}),ne=n,S=class extends t{constructor(e){super(Q,e);}};var P="llama3-70b-8192",so="The Llama 3 instruction tuned models are optimized for dialogue use cases and outperform many of the available open source chat models on common industry benchmarks.",X=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:P,description:so,maxInputTokens:8192,maxOutputTokens:4096,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(4096).def,schema:o.base(4096).schema},price:a[P]}),me=n,I=class extends t{constructor(e){super(X,e);}};var k="llama3-8b-8192",po="The Llama 3 instruction tuned models are optimized for dialogue use cases and outperform many of the available open source chat models on common industry benchmarks.",Z=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:k,description:po,maxInputTokens:8192,maxOutputTokens:4096,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(4096).def,schema:o.base(4096).schema},price:a[k]}),le=n,E=class extends t{constructor(e){super(Z,e);}};var R="llama-guard-3-8b",fo="Llama Guard 3 is a Llama-3.1-8B pretrained model, fine-tuned for content safety classification.",H=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:R,description:fo,maxInputTokens:8192,maxOutputTokens:4096,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(4096).def,schema:o.base(4096).schema},price:a[R]}),re=n,A=class extends t{constructor(e){super(H,e);}};var bo="groq",h=class{constructor(){this.version="v1";this.name=bo;this.chatModelFactories={[u]:{model:M,modelOptions:oe,modelSchema:U},[R]:{model:A,modelOptions:re,modelSchema:H},[k]:{model:E,modelOptions:le,modelSchema:Z},[P]:{model:I,modelOptions:me,modelSchema:X},[f]:{model:b,modelOptions:ae,modelSchema:j},[y]:{model:T,modelOptions:te,modelSchema:K},[x]:{model:S,modelOptions:ne,modelSchema:Q},[C]:{model:L,modelOptions:ie,modelSchema:Y},[O]:{model:g,modelOptions:se,modelSchema:$}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,i)=>(e[i]=this.chatModelFactories[i].modelSchema,e),{})}chatModel(e){let i=e.modelName;if(!(i in this.chatModelFactories))throw new provider.ProviderError({info:`Groq chat model: ${i} not found`,cause:new Error(`Groq chat model: ${i} not found, available chat models: ${this.chatModelLiterals().join(", ")}`)});let c=this.chatModelFactories[i].model,r=this.chatModelFactories[i].modelOptions.parse(e);return new c(r)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,i)=>(e[i]=this.embeddingModelFactories[i].modelSchema,e),{})}embeddingModel(e){throw new provider.ProviderError({info:"Groq does not support embedding models yet",cause:new Error("Groq does not support embedding models yet")})}};h.baseUrl="https://api.groq.com/openai/v1"; exports.BaseChatModelGroq = t; exports.BaseChatModelOptions = n; exports.Gemma2_9b_IT = M; exports.Gemma2_9b_ITLiteral = u; exports.Gemma2_9b_ITOptions = oe; exports.Gemma2_9b_ITSchema = U; exports.Groq = h; exports.LlamaGuard_3_8b = A; exports.LlamaGuard_3_8bLiteral = R; exports.LlamaGuard_3_8bOptions = re; exports.LlamaGuard_3_8bSchema = H; exports.Llama_3_1_8b = b; exports.Llama_3_1_8bLiteral = f; exports.Llama_3_1_8bSchema = j; exports.Llama_3_1_8b_Options = ae; exports.Llama_3_2_11b_Vision = T; exports.Llama_3_2_11b_VisionLiteral = y; exports.Llama_3_2_11b_VisionOptions = te; exports.Llama_3_2_11b_VisionSchema = K; exports.Llama_3_2_1b = g; exports.Llama_3_2_1bLiteral = O; exports.Llama_3_2_1bSchema = $; exports.Llama_3_2_1b_Options = se; exports.Llama_3_2_3b = L; exports.Llama_3_2_3bLiteral = C; exports.Llama_3_2_3bSchema = Y; exports.Llama_3_2_3b_Options = ie; exports.Llama_3_2_90b_Vision = S; exports.Llama_3_2_90b_VisionLiteral = x; exports.Llama_3_2_90b_VisionOptions = ne; exports.Llama_3_2_90b_VisionSchema = Q; exports.Llama_3_70b = I; exports.Llama_3_70bLiteral = P; exports.Llama_3_70bOptions = me; exports.Llama_3_70bSchema = X; exports.Llama_3_8b = E; exports.Llama_3_8bLiteral = k; exports.Llama_3_8bOptions = le; exports.Llama_3_8bSchema = Z; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map