Performance: Prompt composition and chaining
This concept affects the speed and responsiveness of generating outputs by managing how prompts are combined and processed in sequence.
Jump into concepts and practice - no test required
const composedChain = new SequentialChain({chains: [chain1, chain2, chain3], inputVariables: ['userInput']});
const finalResponse = await composedChain.invoke({userInput});const response1 = await chain1.invoke({input: userInput}); const response2 = await chain2.invoke({input: response1}); const response3 = await chain3.invoke({input: response2});
| Pattern | Network Calls | Latency Impact | User Interaction Delay | Verdict |
|---|---|---|---|---|
| Multiple sequential calls | 3 calls for 3 prompts | High latency due to waiting on each call | Longer delay before UI update | [X] Bad |
| Composed prompt chain | 1 combined call | Lower latency by reducing calls | Faster UI update and response | [OK] Good |
final_output?
prompt1 = Prompt(template="Hello, {name}!")
prompt2 = Prompt(template="How can I help you today?")
chain = Chain().add(prompt1).add(prompt2)
final_output = chain.run({"name": "Alice"})prompt1 = Prompt(template="What is your name?") chain = Chain() chain.add(prompt1) chain.run()