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 (langchain): support configurable fields and alternatives for guard and validator runnables #954

Open
kaushikb11 opened this issue Jul 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@kaushikb11
Copy link
Contributor

kaushikb11 commented Jul 22, 2024

Description

A configurable_fields method. This lets you configure particular fields of a runnable.
This is related to the .bind method on runnables, but allows you to specify parameters for a given step in a chain at runtime rather than specifying them beforehand.
A configurable_alternatives method. With this method, you can list out alternatives for any particular runnable that can be set during runtime, and swap them for those specified alternatives.

https://python.langchain.com/v0.2/docs/how_to/configure/

Expected Interface

base_guard = Guard().use_many(
    CompetitorCheck(competitors=["delta", "american airlines", "united"], on_fail="fix"),
    ToxicLanguage(on_fail="remove"),
).to_runnable()

configurable_guard = base_guard.configurable_alternatives(
    ConfigurableField(id="guard"),
    default_key="content",
    regex=Guard().use(
        RegexMatch(regex=r'\b[A-Z]{3}\b', on_fail="exception")
    ).to_runnable(),
)

# Define the LCEL chain components
prompt = ChatPromptTemplate.from_template("Answer this question {question}")
output_parser = StrOutputParser()

chain = prompt | model | output_parser | configurable_guard

# Use the default guard (CompetitorCheck and ToxicLanguage)
result_content = chain.invoke({"question": "What are the top five airlines for domestic travel in the US?"})
print("Content Check Result:", result_content)

# Use the RegexMatch guard
result_regex = chain.with_config(configurable={"guard": "regex"}).invoke(
    {"question": "List three major airport codes in the US."}
)
print("Regex Check Result:", result_regex)
@kaushikb11 kaushikb11 added the enhancement New feature or request label Jul 22, 2024
@Aman123lug
Copy link

Aman123lug commented Sep 15, 2024

@kaushikb11 I want to work on this issue. or are there any starter/good first issue?

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

2 participants