-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollamaModel.js
34 lines (27 loc) · 975 Bytes
/
ollamaModel.js
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
31
32
33
34
import { Ollama } from "@langchain/community/llms/ollama";
import {ChatOllama} from "@langchain/community/chat_models/ollama";
import {ChatPromptTemplate} from "@langchain/core/prompts";
import {CommaSeparatedListOutputParser} from "langchain/output_parsers";
async function main() {
const llm = new Ollama({
model: "mistral"
})
const chatModel = new ChatOllama({
model: "mistral"
})
const template =
"You are a helpful assistant that translates {input_language} to {output_language}.";
const humanTemplate = "{text}";
const chatPrompt = ChatPromptTemplate.fromMessages([
["system", template],
["user", humanTemplate]
])
const parser = new CommaSeparatedListOutputParser()
const chain = chatPrompt.pipe(chatModel).pipe(parser)
console.log(await chain.invoke({
input_language: "English",
output_language: "Bulgarian",
text: "I love programming"
}))
}
main()