Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/api/chat/messages/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CohereClient } from 'cohere-ai';
import Groq from 'groq-sdk';
import OpenAI from 'openai';

import { litellm } from '@/lib/provider/LiteLLM';
import { Provider } from '@/config/provider';
import { ApiConfig } from '@/types/app';
import { toCohereRole } from '@/utils/provider/cohere';
Expand Down Expand Up @@ -185,6 +186,15 @@ export async function POST(req: Request) {
const output = OpenAIStream(response);
return new StreamingTextResponse(output);
}
case Provider.LiteLLM: {
const response = await litellm.chat.completions.create({
model: config.model.model_id,
stream: true,
messages,
});
const output = OpenAIStream(response);
return new StreamingTextResponse(output);
}
default:
return new Response('Invalid Provider', { status: 400 });
}
Expand Down
12 changes: 10 additions & 2 deletions config/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HuggingFaceModelId, HuggingFaceModelName } from '@/config/provider/hugg
import { MistralModelId, MistralModelName } from '@/config/provider/mistral';
import { OpenAIModelId, OpenAIModelName } from '@/config/provider/openai';
import { PerplexityModelId, PerplexityModelName } from '@/config/provider/perplexity';
import { LiteLLMModelId, LiteLLMModelName } from '@/config/provider/litellm';

export type AllModelId =
| AmazonModelId
Expand All @@ -21,7 +22,8 @@ export type AllModelId =
| MistralModelId
| GoogleModelId
| OpenAIModelId
| PerplexityModelId;
| PerplexityModelId
| LiteLLMModelId;

export type AllModelName =
| AmazonModelName
Expand All @@ -34,7 +36,8 @@ export type AllModelName =
| MistralModelName
| GoogleModelName
| OpenAIModelName
| PerplexityModelName;
| PerplexityModelName
| LiteLLMModelName;

export enum Provider {
Amazon = 'Amazon',
Expand All @@ -48,6 +51,7 @@ export enum Provider {
HuggingFace = 'HuggingFace',
Mistral = 'Mistral',
Perplexity = 'Perplexity',
LiteLLM = 'LiteLLM',

Custom = 'Custom',
}
Expand Down Expand Up @@ -100,6 +104,10 @@ export const Providers: {
id: 'perplexity',
name: Provider.Perplexity,
},
{
id: 'litellm',
name: Provider.LiteLLM,
},
{
id: 'custom',
name: Provider.Custom,
Expand Down
31 changes: 31 additions & 0 deletions config/provider/litellm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Model } from '@/types/model';

export type LiteLLMModelId = string;
export type LiteLLMModelName = string;

export const model: Model[] = [
{
id: 'openai/gpt-4o-mini',
name: 'GPT-4o Mini (via LiteLLM)',
maxInputTokens: null,
maxOutputTokens: 16384,
maxTokens: 128000,
price: 0.6,
},
{
id: 'anthropic/claude-3-5-sonnet-20240620',
name: 'Claude 3.5 Sonnet (via LiteLLM)',
maxInputTokens: null,
maxOutputTokens: 8192,
maxTokens: 200000,
price: 18.0,
},
{
id: 'openai/gpt-4o',
name: 'GPT-4o (via LiteLLM)',
maxInputTokens: null,
maxOutputTokens: 16384,
maxTokens: 128000,
price: 15.0,
},
];
6 changes: 6 additions & 0 deletions lib/provider/LiteLLM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import OpenAI from 'openai';

export const litellm = new OpenAI({
apiKey: process.env.LITELLM_API_KEY ?? '',
baseURL: process.env.LITELLM_BASE_URL ?? 'http://localhost:4000/v1',
});