-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multiple providers in addition to anthropic
- Loading branch information
Showing
12 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ModelFactory } from './providers/modelFactory'; | ||
import { AnthropicFactory } from './providers/anthropic'; | ||
import { OpenAiFactory } from './providers/openAi'; | ||
import { GeminiFactory } from './providers/gemini'; | ||
import { OllamaFactory } from './providers/ollama'; | ||
|
||
export function getModelFactory(provider: string): ModelFactory { | ||
switch (provider.toLowerCase()) { | ||
case 'anthropic': { | ||
return new AnthropicFactory(); | ||
} | ||
case 'openai': { | ||
return new OpenAiFactory(); | ||
} | ||
case 'gemini': { | ||
return new GeminiFactory(); | ||
} | ||
case 'ollama': { | ||
return new OllamaFactory(); | ||
} | ||
default: { | ||
throw new Error(`Unsupported provider: ${provider}`); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createAnthropic } from '@ai-sdk/anthropic'; | ||
import type { ModelFactory } from './modelFactory'; | ||
|
||
export function getAnthropicModel(apiKey: string, modelName: string = 'claude-3-5-sonnet-20240620') { | ||
const anthropic = createAnthropic({ | ||
apiKey, | ||
}); | ||
|
||
return anthropic(modelName); | ||
} | ||
|
||
export class AnthropicFactory implements ModelFactory { | ||
createModel(apiKey: string, modelName: string) { | ||
return getAnthropicModel(apiKey, modelName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createGoogleGenerativeAI } from '@ai-sdk/google'; | ||
import type { ModelFactory } from './modelFactory'; | ||
|
||
export function getGeminiModel(apiKey: string, modelName: string = 'gemini-1.5-pro-latest') { | ||
const model = createGoogleGenerativeAI({ | ||
apiKey, | ||
}); | ||
|
||
return model(modelName); | ||
} | ||
|
||
export class GeminiFactory implements ModelFactory { | ||
createModel(apiKey: string, modelName: string) { | ||
return getGeminiModel(apiKey, modelName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { LanguageModel } from 'ai'; | ||
export interface ModelFactory { | ||
createModel(apiKey: string, modelName: string): LanguageModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createOllama } from 'ollama-ai-provider'; | ||
import type { ModelFactory } from './modelFactory'; | ||
|
||
export function getOllamaModel(apiKey: string, modelName: string = 'llama3.2:latest') { | ||
const model = createOllama({ | ||
baseURL: 'http://172.21.208.1:11434', | ||
}); | ||
return model(modelName); | ||
} | ||
|
||
export class OllamaFactory implements ModelFactory { | ||
createModel(apiKey: string, modelName: string) { | ||
return getOllamaModel(apiKey, modelName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createOpenAI } from '@ai-sdk/openai'; | ||
import type { ModelFactory } from './modelFactory'; | ||
|
||
export function getOpenAiModel(apiKey: string, modelName: string = 'gpt-4o-mini') { | ||
const model = createOpenAI({ | ||
apiKey, | ||
}); | ||
|
||
return model(modelName); | ||
} | ||
|
||
export class OpenAiFactory implements ModelFactory { | ||
createModel(apiKey: string, modelName: string) { | ||
return getOpenAiModel(apiKey, modelName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
interface Env { | ||
ANTHROPIC_API_KEY: string; | ||
PROVIDER: string; | ||
MODEL_NAME: string; | ||
GOOGLE_GENERATIVE_AI_API_KEY: string; | ||
} |