Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Certified Generative AI Engineer Associate Exam - Topic 6 Question 35 Discussion

A Generative AI Engineer is testing a simple prompt template in LangChain using the code below, but is getting an error:Pythonfrom langchain.chains import LLMChainfrom langchain_community.llms import OpenAIfrom langchain_core.prompts import PromptTemplateprompt_template = "Tell me a {adjective} joke"prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template)# ... (Error-prone section)Assuming the API key was properly defined, what change does the Generative AI Engineer need to make to fix their chain?
C) prompt_template = 'Tell me a {adjective} joke' prompt = PromptTemplate(input_variables=['adjective'], template=prompt_template) llm = OpenAI() llm_chain = LLMChain(prompt=prompt, llm=llm) llm_chain.generate([{'adjective': 'funny'}])
A) (Incorrect structure)
B) (Incorrect structure)
D) (Incorrect structure)

Databricks Certified Generative AI Engineer Associate Exam - Topic 6 Question 35 Discussion

Actual exam question for Databricks's Databricks Certified Generative AI Engineer Associate exam
Question #: 35
Topic #: 6
[All Databricks Certified Generative AI Engineer Associate Questions]

A Generative AI Engineer is testing a simple prompt template in LangChain using the code below, but is getting an error:

Python

from langchain.chains import LLMChain

from langchain_community.llms import OpenAI

from langchain_core.prompts import PromptTemplate

prompt_template = "Tell me a {adjective} joke"

prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template)

# ... (Error-prone section)

Assuming the API key was properly defined, what change does the Generative AI Engineer need to make to fix their chain?

Show Suggested Answer Hide Answer
Suggested Answer: C

The error in the original snippet usually stems from the improper instantiation of the LLMChain or the incorrect call to the .generate() method. In LangChain, an LLMChain requires two primary components: an LLM (the engine) and a Prompt (the template). Option C provides the correct syntax: first, the PromptTemplate is defined with the correct input_variables. Second, the OpenAI model is instantiated. Third, the LLMChain binds the model and the prompt together. Finally, the .generate() method expects a list of dictionaries, where each dictionary represents a set of inputs for the prompt variables. Options A, B, and D in the original image contain syntax errors such as passing the variable directly into the chain initialization or missing the dictionary list format required by the standard LangChain API for batch-like generation.


Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel