-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandr.js
27 lines (20 loc) · 981 Bytes
/
commandr.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
import { PromptTemplate } from '@langchain/core/prompts'
import { ChatCohere } from '@langchain/cohere'
import { StringOutputParser } from '@langchain/core/output_parsers'
import { RunnableSequence } from '@langchain/core/runnables'
const q_template = `You are Omar, a friendly and helpful AI assistant. Given some conversation history (if any) and a question, answer the question using the conversation history to improve the answer. Always maintain a friendly tone.
# Your answer will be displayed in a CLI terminal. Make sure it's clear, compatible, and not messy.
# Don't respond in markdown.
Conversation History: {history}
Question: {question}
AI Answer: `;
const q_prompt = PromptTemplate.fromTemplate(q_template)
const llm = new ChatCohere({ model: 'command-r-plus',temperature : 0.5 })
// @ts-ignore
const answer_chain = RunnableSequence.from([
q_prompt,
llm,
new StringOutputParser()
// (prevResult) => console.log(prevResult),
])
export { answer_chain }