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

feat: add LangChain Hub Component #2990

Merged
merged 19 commits into from
Aug 27, 2024

Conversation

erichare
Copy link
Collaborator

This PR adds support for a component which looks through the LangSmith Hub for prompt templates, allowing the user to input an API key and a particular prompt template to use.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 26, 2024
@erichare erichare marked this pull request as draft July 26, 2024 15:46
@dosubot dosubot bot added the enhancement New feature or request label Jul 26, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2990.dmtpw4p5recq1.amplifyapp.com

@zee229
Copy link

zee229 commented Jul 27, 2024

#2822 (comment)

@ogabrielluiz
Copy link
Contributor

Hey @erichare

I think the Langchain Hub integration should be a Prompt component that deals with as many messages the .pull returns and exposes all the variables as inputs, then formats them back into the messages.

@erichare
Copy link
Collaborator Author

erichare commented Jul 28, 2024 via email

@erichare
Copy link
Collaborator Author

@ogabrielluiz @zee229 does something like this make sense?

class LangSmithPromptComponent(PromptComponent):
    display_name: str = "LangSmith Prompt Component"
    description: str = "Prompt Component that uses LangSmith prompts"
    beta = True
    icon = "prompts"
    trace_type = "prompt"
    name = "LangSmith Prompt"

    inputs = PromptComponent._base_inputs + [
        SecretStrInput(
            name="langchain_api_key",
            display_name="Your LangChain API Key",
            info="The LangChain API Key to use.",
        ),
        StrInput(
            name="langsmith_prompt",
            display_name="LangSmith Prompt",
            info="The LangSmith prompt to use.",
            value="efriis/my-first-prompt",
        ),
    ]

    outputs = [
        Output(display_name="Prompt Message", name="prompt", method="build_prompt"),
    ]

    def build_prompt(
        self,
    ) -> Message:
        # Pull the prompt from LangChain Hub
        prompt_data = hub.pull(self.langsmith_prompt)

        # Extract the messages from the prompt data
        message_list = []
        for message_data in prompt_data.messages:
            message_list.append(message_data.prompt)

        # Create a Message object from the messages
        messages = Message(messages=message_list)

        # Set the status to the messages
        self.status = str(messages)
        
        return messages

I wasn't sure exactly how we would dynamically create inputs from the prompt template... here i pull the prompt template, then build the prompt based on all the messages - but, based on the comment of exposing them all as inputs, i wasn't sure of the best way - if they have to input a prompt template from langchain hub, is there a way to then create new inputs dynamically based on the variables?

@pward17
Copy link

pward17 commented Jul 29, 2024

@ogabrielluiz @zee229 does something like this make sense?

class LangSmithPromptComponent(PromptComponent):
    display_name: str = "LangSmith Prompt Component"
    description: str = "Prompt Component that uses LangSmith prompts"
    beta = True
    icon = "prompts"
    trace_type = "prompt"
    name = "LangSmith Prompt"

    inputs = PromptComponent._base_inputs + [
        SecretStrInput(
            name="langchain_api_key",
            display_name="Your LangChain API Key",
            info="The LangChain API Key to use.",
        ),
        StrInput(
            name="langsmith_prompt",
            display_name="LangSmith Prompt",
            info="The LangSmith prompt to use.",
            value="efriis/my-first-prompt",
        ),
    ]

    outputs = [
        Output(display_name="Prompt Message", name="prompt", method="build_prompt"),
    ]

    def build_prompt(
        self,
    ) -> Message:
        # Pull the prompt from LangChain Hub
        prompt_data = hub.pull(self.langsmith_prompt)

        # Extract the messages from the prompt data
        message_list = []
        for message_data in prompt_data.messages:
            message_list.append(message_data.prompt)

        # Create a Message object from the messages
        messages = Message(messages=message_list)

        # Set the status to the messages
        self.status = str(messages)
        
        return messages

I wasn't sure exactly how we would dynamically create inputs from the prompt template... here i pull the prompt template, then build the prompt based on all the messages - but, based on the comment of exposing them all as inputs, i wasn't sure of the best way - if they have to input a prompt template from langchain hub, is there a way to then create new inputs dynamically based on the variables?

We're currently focusing on this part. We discovered that the front end refreshes for the standard prompt component interface when the user clicks the "Check & Save" button in the edit template modal. Before we start developing our own methods to refresh this frontend component, hitting this button uses the /prompt endpoint which then passes the prompt to this file for processing src/backend/base/langflow/api/v1/validate.py . We wanted to check if this was how we should do this prompthub component before we went all in on it. @erichare @ogabrielluiz

@erichare
Copy link
Collaborator Author

Perfect. keep me posted on all that @pward17, and thanks for the feedback both @zee229 and @ogabrielluiz - still trying to get my feet wet in how this all operates so this is super valuable to me.

@zee229
Copy link

zee229 commented Jul 29, 2024

Perfect. keep me posted on all that @pward17, and thanks for the feedback both @zee229 and @ogabrielluiz - still trying to get my feet wet in how this all operates so this is super valuable to me.

Maybe we should all get on discord sometime and talk about these details to make it easier.

@erichare
Copy link
Collaborator Author

Perfect. keep me posted on all that @pward17, and thanks for the feedback both @zee229 and @ogabrielluiz - still trying to get my feet wet in how this all operates so this is super valuable to me.

Maybe we should all get on discord sometime and talk about these details to make it easier.

That would be fantastic

@ogabrielluiz
Copy link
Contributor

One important part is that this component is to load prompts not to edit them. Creating a Component that has more than one PromptInput is a bit of a pain

@zee229
Copy link

zee229 commented Jul 29, 2024

One important part is that this component is to load prompts not to edit them. Creating a Component that has more than one PromptInput is a bit of a pain

@ogabrielluiz Why do we need PromptInput here at all? If all messages are stored in Prompt Hub, and we just need to get them and add them as input fields.

@zee229
Copy link

zee229 commented Aug 2, 2024

@erichare @ogabrielluiz hey guys, any progress with it?

@zee229
Copy link

zee229 commented Aug 6, 2024

@erichare @ogabrielluiz hello, hows it going? do you have any progress with this feature?

@ogabrielluiz
Copy link
Contributor

Hey @erichare

Have you checked from_lc_prompt method on the Message class? Feel free to adapt it to this use case because it is not used anywhere.

@zee229
Copy link

zee229 commented Aug 6, 2024

Hey @erichare

Have you checked from_lc_prompt method on the Message class? Feel free to adapt it to this use case because it is not used anywhere.

@ogabrielluiz @erichare I think it is not necessary, because after pull from prompt hub you get ChatPromptTemplate object and it can be used to create an agent (it has all necessary messages and so on). The main difficulty is to update the frontend node when pulling the prompt (to display input variables).

@erichare
Copy link
Collaborator Author

erichare commented Aug 7, 2024

@erichare @ogabrielluiz hello, hows it going? do you have any progress with this feature?

Sorry for the delay on my end, i'm actually out this week, but I will pick it back up on Monday and update ASAP!

@zee229
Copy link

zee229 commented Aug 12, 2024

@ogabrielluiz @erichare @pward17 Hey, any chance you guys can schedule a meeting soon?

@erichare
Copy link
Collaborator Author

@ogabrielluiz @erichare @pward17 Hey, any chance you guys can schedule a meeting soon?

Yes! I'm back from the time off, let me know what day works best for you all, i'm very flexible this week

@zee229
Copy link

zee229 commented Aug 13, 2024

@ogabrielluiz @erichare @pward17 Hey, any chance you guys can schedule a meeting soon?

Yes! I'm back from the time off, let me know what day works best for you all, i'm very flexible this week

Hey, what about Thursday morning?

@erichare
Copy link
Collaborator Author

@ogabrielluiz @erichare @pward17 Hey, any chance you guys can schedule a meeting soon?

Yes! I'm back from the time off, let me know what day works best for you all, i'm very flexible this week

Hey, what about Thursday morning?

Perfect for me. I would be available anytime between 7am and 9am PDT, then again starting at 10am PDT

@zee229
Copy link

zee229 commented Aug 14, 2024

@ogabrielluiz @erichare @pward17 Hey, any chance you guys can schedule a meeting soon?

Yes! I'm back from the time off, let me know what day works best for you all, i'm very flexible this week

Hey, what about Thursday morning?

Perfect for me. I would be available anytime between 7am and 9am PDT, then again starting at 10am PDT

Okay, lets meet in 10am PDT. Our emails are [email protected] , [email protected]

@erichare erichare changed the title #2822 LangSmith Hub Component #2822 LangChain Hub Component Aug 20, 2024
@erichare erichare closed this Aug 20, 2024
@erichare erichare deleted the feat/2822-langsmith-component branch August 20, 2024 16:58
@erichare erichare restored the feat/2822-langsmith-component branch August 21, 2024 08:37
@ogabrielluiz ogabrielluiz linked an issue Aug 23, 2024 that may be closed by this pull request
@ogabrielluiz ogabrielluiz changed the title #2822 LangChain Hub Component feat: add LangChain Hub Component Aug 23, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 23, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 26, 2024
@ogabrielluiz
Copy link
Contributor

LGTM!

@ogabrielluiz ogabrielluiz merged commit 5eb0d9d into langflow-ai:main Aug 27, 2024
28 checks passed
@erichare erichare deleted the feat/2822-langsmith-component branch October 22, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Component for interacting with LangSmith Prompt Hub
4 participants