How to pass API response to prompt #5501
Replies: 1 comment
-
Hey @ayushk-singh! I'm here to help you with any questions or issues you have. Let's tackle this together! To pass the response from your API to a prompt component in Langflow, you can use the from langflow.components.inputs import ChatInput
from langflow.components.models import OpenAIModelComponent
from langflow.components.outputs import ChatOutput
from langflow.components.prompts import PromptComponent
from langflow.graph import Graph
def basic_prompting_graph(api_response: str, template: str | None = None):
if template is None:
template = """Answer the user as if you were a pirate.
User: {user_input}
Answer:
"""
chat_input = ChatInput()
chat_input.message_response = api_response # Set the API response here
prompt_component = PromptComponent()
prompt_component.set(
template=template,
user_input=chat_input.message_response,
)
openai_component = OpenAIModelComponent()
openai_component.set(input_value=prompt_component.build_prompt)
chat_output = ChatOutput()
chat_output.set(input_value=openai_component.text_response)
return Graph(start=chat_input, end=chat_output) In this setup, To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Hi, I am new to langflow I want to pass the response from my API to prompt component
API response format:
[ { "type": "reel", "avg_likes": 350, "avg_shares": 65, "avg_comments": 90 }, { "type": "carousel", "avg_likes": 185, "avg_shares": 45, "avg_comments": 32.5 }, { "type": "static", "avg_likes": 120, "avg_shares": 17.5, "avg_comments": 12.5 } ]
Beta Was this translation helpful? Give feedback.
All reactions