Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to add a manual delay between each API requests? #6017

Open
MotherSoraka opened this issue Jan 30, 2025 · 8 comments
Open

Possible to add a manual delay between each API requests? #6017

MotherSoraka opened this issue Jan 30, 2025 · 8 comments
Labels
enhancement New feature or request

Comments

@MotherSoraka
Copy link

Possible to add a manual delay between each API requests?
or between 2 components?
or define a global requests per seconds limit?

@MotherSoraka
Copy link
Author

@dosu

Copy link

dosubot bot commented Jan 30, 2025

To add a manual delay between API requests in Langflow, you can modify the make_request method in the APIRequest class within the langflow.components.data module. This is where API requests are handled, and you can introduce delays if needed [1][2].

Langflow uses the httpx library for handling API requests, which supports features like request delays and rate limiting through its configuration options and middleware capabilities [3]. You can explore these features to implement a global requests per second limit or introduce delays between components.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added the enhancement New feature or request label Jan 30, 2025
@MotherSoraka
Copy link
Author

is this not a future by defailt in LangFlow?
i have to edit the code?
@dosu

Copy link

dosubot bot commented Jan 30, 2025

Langflow does not have built-in support for request delays or rate limiting as a default feature. To implement these functionalities, you would need to modify the code, specifically in the APIRequestComponent class within the api_request.py module, which handles API request configurations [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@MotherSoraka
Copy link
Author

@dosu:

then modify this component for me and add a new field for delay in seconds, so it would hold the message for that amount before passing it on through its output:

from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output
from langflow.schema.message import Message


class TextOutputComponent(TextComponent):
    display_name = "Text Output"
    description = "Display a text output in the Playground."
    icon = "type"
    name = "TextOutput"

    inputs = [
        MultilineInput(
            name="input_value",
            display_name="Text",
            info="Text to be passed as output.",
        ),
    ]
    outputs = [
        Output(display_name="Message", name="text", method="text_response"),
    ]

    def text_response(self) -> Message:
        message = Message(
            text=self.input_value,
        )
        self.status = self.input_value
        return message

Copy link

dosubot bot commented Jan 30, 2025

To modify the TextOutputComponent class to include a delay feature, you can add a new field for the delay in seconds and incorporate this delay in the text_response method. Here's how you can do it:

import time
from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output
from langflow.schema.message import Message

class TextOutputComponent(TextComponent):
    display_name = "Text Output"
    description = "Display a text output in the Playground."
    icon = "type"
    name = "TextOutput"

    inputs = [
        MultilineInput(
            name="input_value",
            display_name="Text",
            info="Text to be passed as output.",
        ),
    ]
    outputs = [
        Output(display_name="Message", name="text", method="text_response"),
    ]

    # New attribute for delay
    delay_seconds: float = 0.0

    def text_response(self) -> Message:
        # Introduce a delay before processing the message
        if self.delay_seconds > 0:
            time.sleep(self.delay_seconds)
        
        message = Message(
            text=self.input_value,
        )
        self.status = self.input_value
        return message

In this modification, a delay_seconds attribute is added to the class. The text_response method uses time.sleep(self.delay_seconds) to introduce a delay before creating and returning the Message object. Adjust the delay_seconds value as needed to set the desired delay duration.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@MotherSoraka
Copy link
Author

@dosu
it didnt add a new field for me to put in the number of seconds for the delay

Copy link

dosubot bot commented Jan 30, 2025

To add a new field for inputting the number of seconds for the delay, you need to include a NumberInput in the inputs list of the TextOutputComponent class. Here's how you can modify the class to achieve this:

import time
from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output, NumberInput
from langflow.schema.message import Message

class TextOutputComponent(TextComponent):
    display_name = "Text Output"
    description = "Display a text output in the Playground."
    icon = "type"
    name = "TextOutput"

    inputs = [
        MultilineInput(
            name="input_value",
            display_name="Text",
            info="Text to be passed as output.",
        ),
        NumberInput(
            name="delay_seconds",
            display_name="Delay (seconds)",
            info="Number of seconds to delay the output.",
            default=0
        ),
    ]
    outputs = [
        Output(display_name="Message", name="text", method="text_response"),
    ]

    def text_response(self) -> Message:
        # Retrieve the delay value from the input
        delay_seconds = self.delay_seconds
        if delay_seconds > 0:
            time.sleep(delay_seconds)  # Introduce delay
        
        message = Message(
            text=self.input_value,
        )
        self.status = self.input_value
        return message

In this updated version:

  • A NumberInput field named delay_seconds is added to the inputs list. This allows you to specify the delay in seconds.
  • The text_response method retrieves the delay value from this input and uses it to introduce a delay before returning the message [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant