Skip to content

Commit

Permalink
Added support to fetch models for groq
Browse files Browse the repository at this point in the history
  • Loading branch information
Penagwin committed Mar 1, 2024
1 parent 41f7a63 commit 79ff339
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/modules/llms/server/openai/groq.wiretypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod';


// [Groq] Models List API - Response

export const wireGroqModelsListOutputSchema = z.object({
id: z.string(),
object: z.literal('model'),
created: z.number(),
owned_by: z.string(),
active: z.boolean(),
});

32 changes: 22 additions & 10 deletions src/modules/llms/server/openai/models.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ModelDescriptionSchema } from '../llm.server.types';
import { wireMistralModelsListOutputSchema } from './mistral.wiretypes';
import { wireOpenrouterModelsListOutputSchema } from './openrouter.wiretypes';
import { wireTogetherAIListOutputSchema } from '~/modules/llms/server/openai/togetherai.wiretypes';

import { wireGroqModelsListOutputSchema } from './groq.wiretypes';

// [Azure] / [OpenAI]
const _knownOpenAIChatModels: ManualMappings = [
Expand Down Expand Up @@ -778,23 +778,35 @@ export function perplexityAIModelSort(a: ModelDescriptionSchema, b: ModelDescrip

// Groq

const _knownGroqModels: ModelDescriptionSchema[] = [
const _knownGroqModels: ManualMappings = [
// {
// id: 'lama2-70b-4096',
// label: 'Llama 2 70B Chat',
// description: 'Llama 2 is a collection of pretrained and fine-tuned generative text models.',
// contextWindow: 4096,
// interfaces: [LLM_IF_OAI_Chat],
// },
{
id: 'lama2-70b-4096',
label: 'Llama 2 70B Chat',
description: 'Llama 2 is a collection of pretrained and fine-tuned generative text models.',
contextWindow: 4096,
interfaces: [LLM_IF_OAI_Chat],
},
{
id: 'mixtral-8x7b-32768',
idPrefix: 'mixtral-8x7b-32768',
label: 'Mixtral 8x7B Instruct v0.1',
description: 'The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts.',
contextWindow: 32768,
interfaces: [LLM_IF_OAI_Chat],
}
];

export function groqModelToModelDescription(_model: unknown): ModelDescriptionSchema {
const model = wireGroqModelsListOutputSchema.parse(_model);
return fromManualMapping(_knownGroqModels, model.id, model.created, undefined, {
idPrefix: model.id,
label: model.id.replaceAll(/[_-]/g, ' '),
description: 'New Model',
contextWindow: 32768,
interfaces: [LLM_IF_OAI_Chat],
hidden: true,
});
}

export function groqModelDescriptions() {
// change this implementation once upstream implements some form of models listing
return _knownGroqModels;
Expand Down
12 changes: 6 additions & 6 deletions src/modules/llms/server/openai/openai.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { Brand } from '~/common/app.config';
import { fixupHost } from '~/common/util/urlUtils';

import { OpenAIWire, WireOpenAICreateImageOutput, wireOpenAICreateImageOutputSchema, WireOpenAICreateImageRequest } from './openai.wiretypes';
import { azureModelToModelDescription, groqModelDescriptions, lmStudioModelToModelDescription, localAIModelToModelDescription, mistralModelsSort, mistralModelToModelDescription, oobaboogaModelToModelDescription, openAIModelToModelDescription, openRouterModelFamilySortFn, openRouterModelToModelDescription, perplexityAIModelDescriptions, perplexityAIModelSort, togetherAIModelsToModelDescriptions } from './models.data';
import { azureModelToModelDescription, groqModelToModelDescription, lmStudioModelToModelDescription, localAIModelToModelDescription, mistralModelsSort, mistralModelToModelDescription, oobaboogaModelToModelDescription, openAIModelToModelDescription, openRouterModelFamilySortFn, openRouterModelToModelDescription, perplexityAIModelDescriptions, perplexityAIModelSort, togetherAIModelsToModelDescriptions } from './models.data';
import { llmsChatGenerateWithFunctionsOutputSchema, llmsListModelsOutputSchema, ModelDescriptionSchema } from '../llm.server.types';
import { wilreLocalAIModelsApplyOutputSchema, wireLocalAIModelsAvailableOutputSchema, wireLocalAIModelsListOutputSchema } from './localai.wiretypes';


const openAIDialects = z.enum([
'azure', 'groq', 'lmstudio', 'localai', 'mistral', 'oobabooga', 'openai', 'openrouter', 'perplexity', 'togetherai',
]);
Expand Down Expand Up @@ -133,10 +132,6 @@ export const llmOpenAIRouter = createTRPCRouter({
return { models };
}

// [Groq]: use a custom list of models
// https://console.groq.com/docs/models
if (access.dialect === 'groq')
return { models: groqModelDescriptions() };

// [Perplexity]: there's no API for models listing (upstream: https://docs.perplexity.ai/discuss/65cf7fd19ac9a5002e8f1341)
if (access.dialect === 'perplexity')
Expand Down Expand Up @@ -164,6 +159,11 @@ export const llmOpenAIRouter = createTRPCRouter({
// every dialect has a different way to enumerate models - we execute the mapping on the server side
switch (access.dialect) {

case 'groq':
models = openAIModels
.map(groqModelToModelDescription);
break;

case 'lmstudio':
models = openAIModels
.map(({ id }) => lmStudioModelToModelDescription(id));
Expand Down

0 comments on commit 79ff339

Please sign in to comment.