Replies: 1 comment 12 replies
-
Hello, @nmvega! I'm here to assist you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together! I found some similar issues that might help you resolve the
The error occurs because Here's how you can correct your code:
Here is the corrected version of your code: from langchain_core.runnables import RunnableLambda, RunnableSequence
from langchain.prompts import PromptTemplate
from langchain_huggingface import HuggingFaceEndpoint
# Define your model
model = HuggingFaceEndpoint(
huggingfacehub_api_token=os.environ['HUGGINGFACEHUB_API_TOKEN'],
repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
task="text-generation",
max_new_tokens=100,
do_sample=False,
temperature=0.9,
)
# Step 1: Create a joke
joke_template = PromptTemplate.from_template(
"""You are a comedian. Generate a joke on the following {topic}: Joke:"""
)
joke_chain = (
joke_template
| model
| RunnableLambda(lambda output: {"joke": output['text']})
)
# Step 2: Translate the joke
translator_template = PromptTemplate.from_template(
"""You are a translator. Given text input, translate it to {language}: Translation:"""
)
translator_chain = (
translator_template
| model
| RunnableLambda(lambda output: {"translated_joke": output['text']})
)
# Combine both chains into a sequential runnable chain
sequence = joke_chain | translator_chain
# Setup chain input data
input_data = {"topic": "Cats and Dogs", "language": "Spanish"}
# Run the chain and get the translated joke
translated_joke = sequence.invoke(input_data, callbacks=callback_manager)
print("Translated Joke:", translated_joke['translated_joke']) This should resolve the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hello Friends:
I'm fairly new to LangChain and wanted to learn how to apply
RunnableSequence(...)
.Using books, I tried writing snippets but, sadly, could not get any to work. So, I then turned to
ChatGPT 4o
to synthesize the example below for me. Unfortunately, it, too, results in an exception that I cannot figure out to fix (despite researching it).The
exception
occurs at thestatement
:and the
exception
is:This makes sense because a
list() []
is, indeed, passed in; but I can't figure out what to replace that with to correct it. I couldn't find good examples on the web.Can anyone assist with correcting this? (Thank you in advance).
System Info
Python v3.12.5
pip(1) freeze
output:Beta Was this translation helpful? Give feedback.
All reactions