scrimba
Learn Langchain
Aside: Prompt Templates II
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

Aside: Prompt Templates II
AboutCommentsNotes
Aside: Prompt Templates II
Expand for more info
index.js
run
preview
console
import { ChatOpenAI } from "langchain/chat_models/openai"
import { PromptTemplate } from "langchain/prompts";

const openAIApiKey = process.env.OPENAI_API_KEY

const llm = new ChatOpenAI({ openAIApiKey })

const tweetTemplate = 'Generate a promotional tweet for a product, from this product description: {productDesc}'

const tweetPrompt = PromptTemplate.fromTemplate(tweetTemplate)

console.log(tweetPrompt)
Console
{lc:
1
, type:
"constructor"
, id:
[
"langchain"
,
"prompts"
,
"prompt"
,
"PromptTemplate"
]
, kwargs:
{input_variables:
[
"productDesc"
]
, template_format:
"f-string"
, template:
"Generate a promotional tweet for a product, from this product description: {productDesc}"
, partial_variables:
undefined
}
}
,
/index.html
-3:06