scrimba
Learn Langchain
Aside: RunnableSequence
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Aside: RunnableSequence
Expand for more info
index.js
run
preview
console
import { ChatOpenAI } from 'langchain/chat_models/openai'
import { PromptTemplate } from 'langchain/prompts'
import { StringOutputParser } from 'langchain/schema/output_parser'

const openAIApiKey = process.env.OPENAI_API_KEY
const llm = new ChatOpenAI({ openAIApiKey })

const punctuationTemplate = `Given a sentence, add punctuation where needed.
sentence: {sentence}
sentence with punctuation:
`
const punctuationPrompt = PromptTemplate.fromTemplate(punctuationTemplate)

const grammarTemplate = `Given a sentence correct the grammar.
sentence: {punctuated_sentence}
sentence with correct grammar:
`
const grammarPrompt = PromptTemplate.fromTemplate(grammarTemplate)

const response = await chain.invoke({
sentence: 'i dont liked mondays',
language: 'french'
})

console.log(response)
Console
!
ReferenceError: chain is not defined
,
!
ReferenceError: chain is not defined
,
!
ReferenceError: chain is not defined
,
/index.html
-4:57