-
Notifications
You must be signed in to change notification settings - Fork 1
/
chatOllama.ts
30 lines (27 loc) · 887 Bytes
/
chatOllama.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { ChatOllama } from '@langchain/community/chat_models/ollama';
const getOllamaSingleton = () =>
class OllamaSingleton {
static model = 'mistral';
static instance: ChatOllama | null = null;
static async getInstance() {
if (this.instance === null) {
this.instance = new ChatOllama({
baseUrl: process.env.OLLAMA_BASE_URL,
model: this.model,
numCtx: 32678,
});
}
return this.instance;
}
};
export type TChatOllamaSingleton = ReturnType<typeof getOllamaSingleton>;
let ChatOllamaSingleton: TChatOllamaSingleton;
if (process.env.NODE_ENV !== 'production') {
if (!global.ChatOllamaSingleton) {
global.ChatOllamaSingleton = getOllamaSingleton();
}
ChatOllamaSingleton = global.ChatOllamaSingleton;
} else {
ChatOllamaSingleton = getOllamaSingleton();
}
export default ChatOllamaSingleton;