I have two chains
<code>llm = OpenAI()
code_prompt = PromptTemplate(
input_variables=["task", "language"],
template="Write a very short {language} function that will {task}."
)
test_prompt = PromptTemplate(
input_variables=["language", "code"],
template="Write a unit test for the following {language} code:n{code}"
)
chain_code: Runnable = code_prompt | llm | {"language": StrOutputParser(), "code": StrOutputParser()}
chain_test: Runnable = test_prompt | llm | {"test": StrOutputParser(), "code": StrOutputParser()}
sequence: Runnable = chain_code | chain_test
result = sequence.invoke({ "task": "return a list of numbers", "language":"python" })
print(">>>>>> GENERATED CODE:")
print(result["code"])
print(">>>>>> GENERATED TEST:")
print(result["test"])
</code>
<code>llm = OpenAI()
code_prompt = PromptTemplate(
input_variables=["task", "language"],
template="Write a very short {language} function that will {task}."
)
test_prompt = PromptTemplate(
input_variables=["language", "code"],
template="Write a unit test for the following {language} code:n{code}"
)
chain_code: Runnable = code_prompt | llm | {"language": StrOutputParser(), "code": StrOutputParser()}
chain_test: Runnable = test_prompt | llm | {"test": StrOutputParser(), "code": StrOutputParser()}
sequence: Runnable = chain_code | chain_test
result = sequence.invoke({ "task": "return a list of numbers", "language":"python" })
print(">>>>>> GENERATED CODE:")
print(result["code"])
print(">>>>>> GENERATED TEST:")
print(result["test"])
</code>
llm = OpenAI()
code_prompt = PromptTemplate(
input_variables=["task", "language"],
template="Write a very short {language} function that will {task}."
)
test_prompt = PromptTemplate(
input_variables=["language", "code"],
template="Write a unit test for the following {language} code:n{code}"
)
chain_code: Runnable = code_prompt | llm | {"language": StrOutputParser(), "code": StrOutputParser()}
chain_test: Runnable = test_prompt | llm | {"test": StrOutputParser(), "code": StrOutputParser()}
sequence: Runnable = chain_code | chain_test
result = sequence.invoke({ "task": "return a list of numbers", "language":"python" })
print(">>>>>> GENERATED CODE:")
print(result["code"])
print(">>>>>> GENERATED TEST:")
print(result["test"])
The output of chain_code will be input for chain_test.
The code works but prints same result for code and test. How can I fix this?