實作 few-shot 提示
現在把元件組合成一個 chain 吧!你在前一個練習建立的 few-shot 提示仍可使用,examples 和 example_prompt 也都已備妥。
完成此練習所需的所有 LangChain 類別都已為你預先載入。
本練習屬於課程
使用 LangChain 開發 LLM 應用
練習說明
- 使用
ChatOpenAI類別實例化一個 OpenAI chat LLM。 - 使用
|運算子把提示樣板與 LLM 建立為一個 chain,然後以.invoke()方法呼叫它。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
prompt_template = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
suffix="Question: {input}",
input_variables=["input"],
)
# Create an OpenAI chat LLM
llm = ____(model="gpt-4o-mini", api_key='')
# Create and invoke the chain
llm_chain = ____
print(____({"input": "What is Jack's favorite technology on DataCamp?"}))