feat(ts-sdk): add Together LLM provider
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { OpenAILLM } from "./openai";
|
||||
import { LLMConfig, Message } from "../types";
|
||||
import { LLMResponse } from "./base";
|
||||
|
||||
export class TogetherLLM extends OpenAILLM {
|
||||
constructor(config: LLMConfig) {
|
||||
const apiKey = config.apiKey || process.env.TOGETHER_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error("Together API key is required");
|
||||
}
|
||||
|
||||
super({
|
||||
...config,
|
||||
apiKey,
|
||||
baseURL:
|
||||
config.baseURL ||
|
||||
"https://api.together.xyz/v1",
|
||||
model:
|
||||
config.model ||
|
||||
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
});
|
||||
}
|
||||
|
||||
async generateResponse(
|
||||
messages: Message[],
|
||||
responseFormat?: { type: string },
|
||||
tools?: any[],
|
||||
): Promise<string | LLMResponse> {
|
||||
try {
|
||||
return await super.generateResponse(
|
||||
messages,
|
||||
responseFormat,
|
||||
tools,
|
||||
);
|
||||
} catch (err) {
|
||||
const message =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: String(err);
|
||||
|
||||
throw new Error(
|
||||
`Together LLM failed: ${message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async generateChat(
|
||||
messages: Message[],
|
||||
): Promise<LLMResponse> {
|
||||
try {
|
||||
return await super.generateChat(messages);
|
||||
} catch (err) {
|
||||
const message =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: String(err);
|
||||
|
||||
throw new Error(
|
||||
`Together LLM failed: ${message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
import { OpenAIEmbedder } from "../embeddings/openai";
|
||||
import { OllamaEmbedder } from "../embeddings/ollama";
|
||||
import { LMStudioEmbedder } from "../embeddings/lmstudio";
|
||||
@@ -22,6 +23,7 @@ import { RedisDB } from "../vector_stores/redis";
|
||||
import { OllamaLLM } from "../llms/ollama";
|
||||
import { LMStudioLLM } from "../llms/lmstudio";
|
||||
import { DeepSeekLLM } from "../llms/deepseek";
|
||||
import { TogetherLLM } from "../llms/together";
|
||||
import { SupabaseDB } from "../vector_stores/supabase";
|
||||
import { SQLiteManager } from "../storage/SQLiteManager";
|
||||
import { MemoryHistoryManager } from "../storage/MemoryHistoryManager";
|
||||
@@ -85,6 +87,8 @@ export class LLMFactory {
|
||||
return new LangchainLLM(config);
|
||||
case "deepseek":
|
||||
return new DeepSeekLLM(config);
|
||||
case "together":
|
||||
return new TogetherLLM(config);
|
||||
default:
|
||||
throw new Error(`Unsupported LLM provider: ${provider}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user