UNPKG

@adaline/groq

Version:
60 lines (57 loc) 17.8 kB
'use strict'; var provider = require('@adaline/provider'); var zod = require('zod'); var openai = require('@adaline/openai'); var t={"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}}}]},"llama-3.3-70b-versatile":{modelName:"llama-3.3-70b-versatile",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.59,outputPricePerMillion:.79}}}]},"meta-llama/llama-guard-4-12b":{modelName:"meta-llama/llama-guard-4-12b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.2,outputPricePerMillion:.2}}}]},"deepseek-r1-distill-llama-70b":{modelName:"deepseek-r1-distill-llama-70b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.75,outputPricePerMillion:.99}}}]},"moonshotai/kimi-k2-instruct":{modelName:"moonshotai/kimi-k2-instruct",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:1,outputPricePerMillion:3}}}]},"qwen/qwen3-32b":{modelName:"qwen/qwen3-32b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.29,outputPricePerMillion:.59}}}]},"meta-llama/llama-4-maverick-17b-128e-instruct":{modelName:"meta-llama/llama-4-maverick-17b-128e-instruct",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.2,outputPricePerMillion:.6}}}]},"meta-llama/llama-4-scout-17b-16e-instruct":{modelName:"meta-llama/llama-4-scout-17b-16e-instruct",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.11,outputPricePerMillion:.34}}}]},"openai/gpt-oss-20b":{modelName:"openai/gpt-oss-20b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.5}}}]},"openai/gpt-oss-120b":{modelName:"openai/gpt-oss-120b",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.75}}}]}};var s=zod.z.object({modelName:zod.z.string().min(1),apiKey:zod.z.string().min(1)}),a=class extends openai.BaseChatModel{constructor(n,d){let m=s.parse(d),p=u.baseUrl;super(n,{modelName:m.modelName,apiKey:m.apiKey,baseUrl:p,completeChatUrl:`${p}/chat/completions`,streamChatUrl:`${p}/chat/completions`});this.version="v1";this.modelSchema=n,this.modelName=m.modelName,this.groqApiKey=m.apiKey;}transformMessages(n){let d=n.some(r=>r.role==="system"),m=n.some(r=>r.content.some(_=>_.modality==="image"));if(d&&m)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(n);return p.messages.forEach(r=>{r.role==="system"?typeof r.content!="string"&&(r.content=r.content.map(_=>_.text).join(` `)):r.role==="assistant"&&r.content&&typeof r.content!="string"&&(r.content=r.content.map(_=>_.text).join(` `));}),p}getModelPricing(){if(!(this.modelName in t))throw new provider.ModelResponseError({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return t[this.modelName]}};var N=provider.RangeConfigItem({param:"temperature",title:provider.CHAT_CONFIG.TEMPERATURE.title,description:provider.CHAT_CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),B=i=>provider.RangeConfigItem({param:"max_tokens",title:provider.CHAT_CONFIG.MAX_TOKENS.title,description:provider.CHAT_CONFIG.MAX_TOKENS.description,min:0,max:i,step:1,default:0}),K=provider.MultiStringConfigItem({param:"stop",title:provider.CHAT_CONFIG.STOP(4).title,description:provider.CHAT_CONFIG.STOP(4).description,max:4}),z=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}),U=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}),F=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}),V=provider.RangeConfigItem({param:"seed",title:provider.CHAT_CONFIG.SEED.title,description:provider.CHAT_CONFIG.SEED.description,min:0,max:1e6,step:1,default:0}),Q=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"]}),j=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 ie=i=>zod.z.object({temperature:N.schema,maxTokens:B(i).schema,stop:K.schema,topP:z.schema,frequencyPenalty:U.schema,presencePenalty:F.schema,seed:V.schema.transform(e=>e===0?void 0:e),responseFormat:Q.schema,toolChoice:j.schema}),ne=i=>({temperature:N.def,maxTokens:B(i).def,stop:K.def,topP:z.def,frequencyPenalty:U.def,presencePenalty:F.def,seed:V.def,responseFormat:Q.def,toolChoice:j.def});var o={base:i=>({def:ne(i),schema:ie(i)})};var h="gemma2-9b-it",Re="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.",$=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:h,description:Re,maxInputTokens:8192,maxOutputTokens:4096,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(4096).def,schema:o.base(4096).schema},price:t[h]}),le=s,M=class extends a{constructor(e){super($,e);}};var f="openai/gpt-oss-20b",we="GPT-OSS 20B is OpenAI's flagship open source model, built on a Mixture-of-Experts (MoE) architecture with 20 billion parameters and 32 experts.",Y=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:f,description:we,maxInputTokens:131072,maxOutputTokens:32768,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(32768).def,schema:o.base(32768).schema},price:t[f]}),re=s,b=class extends a{constructor(e){super(Y,e);}};var g="openai/gpt-oss-120b",Ue="GPT-OSS 120B is OpenAI's flagship open source model, built on a Mixture-of-Experts (MoE) architecture with 120 billion parameters and 128 experts.",W=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:g,description:Ue,maxInputTokens:131072,maxOutputTokens:32766,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(32766).def,schema:o.base(32766).schema},price:t[g]}),me=s,O=class extends a{constructor(e){super(W,e);}};var T="llama-3.1-8b-instant",Ye="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.",X=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:T,description:Ye,maxInputTokens:128e3,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:t[T]}),pe=s,y=class extends a{constructor(e){super(X,e);}};var C="llama-3.3-70b-versatile",eo="Llama-3.3-70B-Versatile is Meta's advanced multilingual large language model, optimized for a wide range of natural language processing tasks. With 70 billion parameters, it offers high performance across various benchmarks while maintaining efficiency suitable for diverse applications.",Z=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:C,description:eo,maxInputTokens:128e3,maxOutputTokens:32768,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(32768).def,schema:o.base(32768).schema},price:t[C]}),ce=s,k=class extends a{constructor(e){super(Z,e);}};var x="meta-llama/llama-guard-4-12b",no="Llama-Guard-4-12B is Meta's advanced multilingual large language model, optimized for a wide range of natural language processing tasks. With 70 billion parameters, it offers high performance across various benchmarks while maintaining efficiency suitable for diverse applications.",H=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:x,description:no,maxInputTokens:128e3,maxOutputTokens:1024,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextModalities,config:{def:o.base(1024).def,schema:o.base(1024).schema},price:t[x]}),de=s,S=class extends a{constructor(e){super(H,e);}};var I="qwen/qwen3-32b",_o="Qwen 3 32B is the latest generation of large language models in the Qwen series, offering groundbreaking advancements in reasoning, instruction-following, agent capabilities, and multilingual support. It uniquely supports seamless switching between thinking mode (for complex logical reasoning, math, and coding) and non-thinking mode (for efficient, general-purpose dialogue) within a single model. ",J=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:I,description:_o,maxInputTokens:128e3,maxOutputTokens:40960,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(40960).def,schema:o.base(40960).schema},price:t[I]}),_e=s,P=class extends a{constructor(e){super(J,e);}};var L="deepseek-r1-distill-llama-70b",go="DeepSeek-R1-Distill-Llama-70B is a distilled version of DeepSeek's R1 model, fine-tuned from the Llama-3.3-70B-Instruct base model. This model leverages knowledge distillation to retain robust reasoning capabilities and deliver exceptional performance on mathematical and logical reasoning tasks with Groq's industry-leading speed.",ee=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:L,description:go,maxInputTokens:128e3,maxOutputTokens:128e3,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(128e3).def,schema:o.base(128e3).schema},price:t[L]}),ue=s,R=class extends a{constructor(e){super(ee,e);}};var G="moonshotai/kimi-k2-instruct",xo="Kimi K2 is Moonshot AI's state-of-the-art Mixture-of-Experts (MoE) language model with 1 trillion total parameters and 32 billion activated parameters. Designed for agentic intelligence, it excels at tool use, coding, and autonomous problem-solving across diverse domains.",oe=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelTextToolModalitiesEnum).parse({name:G,description:xo,maxInputTokens:128e3,maxOutputTokens:16384,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelTextToolModalities,config:{def:o.base(16384).def,schema:o.base(16384).schema},price:t[G]}),he=s,D=class extends a{constructor(e){super(oe,e);}};var E="meta-llama/llama-4-maverick-17b-128e-instruct",Go="Llama 4 Maverick is Meta's natively multimodal model that enables text and image understanding. Model offers industry-leading performance for multimodal tasks like natural assistant-like chat, image recognition, and coding tasks.",te=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelModalitiesEnum).parse({name:E,description:Go,maxInputTokens:131072,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:t[E]}),Me=s,A=class extends a{constructor(e){super(te,e);}};var v="meta-llama/llama-4-scout-17b-16e-instruct",qo="Llama 4 Scout is Meta's natively multimodal model that enables text and image understanding. Model offers industry-leading performance for multimodal tasks like natural assistant-like chat, image recognition, and coding tasks.",ae=provider.ChatModelSchema(openai.OpenAIChatModelRoles,openai.OpenAIChatModelModalitiesEnum).parse({name:v,description:qo,maxInputTokens:131072,maxOutputTokens:8192,roles:openai.OpenAIChatModelRolesMap,modalities:openai.OpenAIChatModelModalities,config:{def:o.base(8192).def,schema:o.base(8192).schema},price:t[v]}),fe=s,w=class extends a{constructor(e){super(ae,e);}};var No="groq",u=class{constructor(){this.version="v1";this.name=No;this.chatModelFactories={[h]:{model:M,modelOptions:le,modelSchema:$},[T]:{model:y,modelOptions:pe,modelSchema:X},[C]:{model:k,modelOptions:ce,modelSchema:Z},[x]:{model:S,modelOptions:de,modelSchema:H},[I]:{model:P,modelOptions:_e,modelSchema:J},[L]:{model:R,modelOptions:ue,modelSchema:ee},[G]:{model:D,modelOptions:he,modelSchema:oe},[E]:{model:A,modelOptions:Me,modelSchema:te},[v]:{model:w,modelOptions:fe,modelSchema:ae},[f]:{model:b,modelOptions:re,modelSchema:Y},[g]:{model:O,modelOptions:me,modelSchema:W}};this.embeddingModelFactories={};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,n)=>(e[n]=this.chatModelFactories[n].modelSchema,e),{})}chatModel(e){let n=e.modelName;if(!(n in this.chatModelFactories))throw new provider.ProviderError({info:`Groq chat model: ${n} not found`,cause:new Error(`Groq chat model: ${n} not found, available chat models: ${this.chatModelLiterals().join(", ")}`)});let d=this.chatModelFactories[n].model,m=this.chatModelFactories[n].modelOptions.parse(e);return new d(m)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,n)=>(e[n]=this.embeddingModelFactories[n].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")})}};u.baseUrl="https://api.groq.com/openai/v1"; exports.BaseChatModelGroq = a; exports.BaseChatModelOptions = s; exports.Deepseek_R1_Distill_Llama_70b = R; exports.Deepseek_R1_Distill_Llama_70bLiteral = L; exports.Deepseek_R1_Distill_Llama_70bSchema = ee; exports.Deepseek_R1_Distill_Llama_70b_Options = ue; exports.Gemma2_9b_IT = M; exports.Gemma2_9b_ITLiteral = h; exports.Gemma2_9b_ITOptions = le; exports.Gemma2_9b_ITSchema = $; exports.Gpt_Oss_120b = O; exports.Gpt_Oss_120bLiteral = g; exports.Gpt_Oss_120bSchema = W; exports.Gpt_Oss_120b_Options = me; exports.Gpt_Oss_20b = b; exports.Gpt_Oss_20bLiteral = f; exports.Gpt_Oss_20bSchema = Y; exports.Gpt_Oss_20b_Options = re; exports.Groq = u; exports.Kimi_K2_Instruct = D; exports.Kimi_K2_InstructLiteral = G; exports.Kimi_K2_InstructSchema = oe; exports.Kimi_K2_Instruct_Options = he; exports.Llama_3_1_8b = y; exports.Llama_3_1_8bLiteral = T; exports.Llama_3_1_8bSchema = X; exports.Llama_3_1_8b_Options = pe; exports.Llama_3_3_70b_Versatile = k; exports.Llama_3_3_70b_VersatileLiteral = C; exports.Llama_3_3_70b_VersatileSchema = Z; exports.Llama_3_3_70b_Versatile_Options = ce; exports.Llama_4_Maverick_17b_128e_Instruct = A; exports.Llama_4_Maverick_17b_128e_InstructLiteral = E; exports.Llama_4_Maverick_17b_128e_InstructSchema = te; exports.Llama_4_Maverick_17b_128e_Instruct_Options = Me; exports.Llama_4_Scout_17b_16e_Instruct = w; exports.Llama_4_Scout_17b_16e_InstructLiteral = v; exports.Llama_4_Scout_17b_16e_InstructSchema = ae; exports.Llama_4_Scout_17b_16e_Instruct_Options = fe; exports.Llama_Guard_4_12b = S; exports.Llama_Guard_4_12bLiteral = x; exports.Llama_Guard_4_12bSchema = H; exports.Llama_Guard_4_12b_Options = de; exports.Qwen3_32b = P; exports.Qwen3_32bLiteral = I; exports.Qwen3_32bSchema = J; exports.Qwen3_32b_Options = _e; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map