Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sihyeong671 committed Aug 20, 2024
2 parents 0ad41b1 + 0d2d77a commit 6f7ec54
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions backend/src/langchain/langchain.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseChatModel } from "@langchain/core/language_models/chat_models";

type ModelList = {
[key: string]: string[];
};
}

const modelList: ModelList = {
ollama: [
Expand All @@ -18,18 +18,22 @@ const modelList: ModelList = {
"starling-lm",
"solar",
],
openai: ["gpt-3.5-turbo", "gpt-4o-mini"],
};
openai: [
"gpt-3.5-turbo",
"gpt-4o-mini"
]
}

const chatModelFactory = {
provide: "ChatModel",
useFactory: () => {

const modelType = process.env.YORKIE_INTELLIGENCE;
try {
try{
const [provider, model] = modelType.split(":", 2);
let chatModel: BaseChatModel | ChatOllama;
let chatModel: BaseChatModel | ChatOllama

if (modelList[provider] && modelList[provider].includes(model)) {
if (modelList[provider] && modelList[provider].includes(model)){
if (provider === "ollama") {
chatModel = new ChatOllama({
model: model,
Expand All @@ -42,12 +46,13 @@ const chatModelFactory = {
}
}

if (!chatModel) throw new Error(`${model} is not found. please check your model name`);
if (!chatModel) throw new Error();

return chatModel;
} catch {
throw new Error("~~~");
throw new Error(`${modelType} is not found. please check your model name`);
}

},
};

Expand Down

0 comments on commit 6f7ec54

Please sign in to comment.