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

DOC: No example of usage implementation is provided for the langchain.chains.query_constructor.base.load_query_constructor_runnable function #21478

Open
2 tasks done
moneebullah25 opened this issue May 9, 2024 · 0 comments
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables

Comments

@moneebullah25
Copy link

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

Description:

Currently, the load_query_constructor_runnable function documentation lacks doesn't have usage examples or scenarios, making it challenging for developers to understand.

URL to the documentation: https://api.python.langchain.com/en/latest/chains/langchain.chains.query_constructor.base.load_query_constructor_runnable.html#langchain.chains.query_constructor.base.load_query_constructor_runnable

Idea or request for content:

I tried running the function and below is the complete code and output:

from langchain.chains.query_constructor.base import load_query_constructor_runnable
from langchain.chains.query_constructor.schema import AttributeInfo
from langchain_openai import ChatOpenAI
from langchain.chains.query_constructor.ir import (
    Comparator,
    Comparison,
    Operation,
    Operator,
    StructuredQuery,
)

# Define your document contents and attribute information
document_contents = """
product_name: Widget, price: $20
product_name: Gadget, price: $35
product_name: Gizmo, price: $50
"""

attribute_info: AttributeInfo = [
    {"name": "product_name", "type": "string"},
    {"name": "price", "type": "number"},
]

model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.5)

# Create a runnable for constructing queries
runnable = load_query_constructor_runnable(
    llm=model,
    document_contents=document_contents,
    attribute_info=attribute_info,
    allowed_comparators=[Comparator.EQ, Comparator.LT, Comparator.GT],
    allowed_operators=[Operator.AND, Operator.NOT, Operator.OR],
    enable_limit=True,
    schema_prompt="Describe the query schema using allowed comparators and operators.",
    fix_invalid=True,
)

# Now you can use the runnable to construct queries based on user input
user_input = "Show me products with price less than 30"
query = runnable.middle[0].invoke(user_input).content
print(f"Constructed query: {query}")

Output:

Constructed query: 1. Wireless Bluetooth Earbuds - $29.99
2. Portable Phone Charger - $24.99
3. Travel Makeup Bag - $19.99
4. Insulated Water Bottle - $15.99
5. LED Desk Lamp - $27.99
6. Resistance Bands Set - $12.99
7. Stainless Steel Mixing Bowls - $19.99
8. Yoga Mat - $24.99
9. Essential Oil Diffuser - $28.99
10. Electric Handheld Milk Frother - $14.99

However the output is wrong and is not providing the references to the original documents provided. Needed usage implementation.

@dosubot dosubot bot added Ɑ: Runnables Related to Runnables 🔌: openai Primarily related to OpenAI integrations 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables
Projects
None yet
Development

No branches or pull requests

1 participant