Replies: 3 comments 8 replies
-
Hey @LIJUN-XU, nice to see you diving into another adventure with Langflow! How's everything going on your end? Based on your request, you want to make a POST request within a Langflow flow using a user-input word as a parameter, and add properties like To achieve this, you need to modify the
Here's an updated version of the def post_document(
self,
session: requests.Session,
document: Document,
url: str,
headers: Optional[dict] = None,
params: Optional[dict] = None, # New parameter for additional properties
) -> Document:
try:
# Ensure headers dictionary is initialized
if headers is None:
headers = {}
# Set Content-Type to application/json
headers['Content-Type'] = 'application/json'
# Prepare the data to be sent in the request body
data = {
"query": document.page_content, # Assuming document.page_content contains the user-input word
}
# Update data with additional properties from params if provided
if params:
data.update(params)
# Convert data to JSON string
json_data = orjson_dumps(data)
# Make the POST request with JSON data
response = session.post(url, headers=headers, data=json_data)
try {
response_json = response.json()
result = orjson_dumps(response_json, indent_2=False)
} except Exception {
result = response.text
}
self.repr_value = result
return Document(
page_content=result,
metadata={
"source": url,
"headers": headers,
"status_code": response.status_code, # Fixed to show the status code correctly
},
)
} except Exception as exc {
return Document(
page_content=str(exc),
metadata={
"source": url,
"headers": headers,
"status_code": 500,
},
)
} In this updated method, a new parameter To use this updated method, you would need to pass the additional properties as a dictionary when calling it, for example: additional_properties = {"fetchCount": 5, "page": 4}
# Assuming you have a Document object `user_input_document` and other necessary variables defined
result_document = post_request_instance.post_document(session, user_input_document, url, headers, additional_properties) This approach allows you to dynamically add properties to the user input before sending it as the body of the HTTP request. You can find more details about the I hope this helps! If you have any further questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi! 👋 We are using other channels as our official means of communication with users. We apologize for the delayed response. Thank you for your understanding. Best regards, |
Beta Was this translation helpful? Give feedback.
-
i want to use user input word as param. Then Adding some props(eg:{query: input word, fetchCount:5,page:4}). last , the object as request's body send http request. Thank you for your support.
Beta Was this translation helpful? Give feedback.
All reactions