Coder Social home page Coder Social logo

DOC: No example of usage implementation is provided for the langchain.chains.query_constructor.base.load_query_constructor_runnable function about langchain HOT 1 OPEN

moneebullah25 avatar moneebullah25 commented on July 30, 2024 1
DOC: No example of usage implementation is provided for the langchain.chains.query_constructor.base.load_query_constructor_runnable function

from langchain.

Comments (1)

wood001 avatar wood001 commented on July 30, 2024

run you code, and client will send prompt as following:

Your goal is to structure the user\'s query to match the request schema provided below.

Describe the query schema using allowed comparators and operators.

<< Example 1. >>
Data Source:
'''json
{
    "content": "Lyrics of a song",
    "attributes": {
        "artist": {
            "type": "string",
            "description": "Name of the song artist"
        },
        "length": {

        "type": "integer",
            "description": "Length of the song in seconds"
        },
        "genre": {
            "type": "string",
            "description": "The song genre, one of "pop", "rock" or "rap""
        }
    }
}
'''

User Query:
What are songs by Taylor Swift or Katy Perry about teenage romance under 3 minutes long in the dance pop genre

Structured Request:
'''json
{
    "query": "teenager love",
    "filter": "and(or(eq(\\"artist\\", \\"Taylor Swift\\"), eq(\\"artist\\", \\"Katy Perry\\")), lt(\\"length\\", 180), eq(\\"genre\\", \\"pop\\"))"
}
'''


<< Example 2. >>
Data Source:
'''json
{
    "content": "Lyrics of a song",
    "attributes": {
        "artist": {
            "type": "string",
            "description": "Name of the song artist"
        },
        "length": {
            "type": "integer",
            "description": "Length of the song in seconds"
        },
        "genre": {
            "type": "string",
            "description": "The song genre, one of "pop", "rock" or "rap""
        }
    }
}
'''

User Query:
What are songs that were not published on Spotify

Structured Request:
'''json
{
    "query": "",
    "filter": "NO_FILTER"
}
'''


<< Example 3. >>
Data Source:
'''json
{
    "content": "Lyrics of a song",
    "attributes": {
        "artist": {
            "type": "string",
            "description": "Name of the song artist"
        },
        "length": {
            "type": "integer",
            "description": "Length of the song in seconds"
        },
        "genre": {
            "type": "string",
            "description": "The song genre, one of "pop", "rock" or "rap""
        }
    }
}
'''

User Query:
What are three songs about love

Structured Request:
'''json
{
    "query": "love",
    "filter": "NO_FILTER",
    "limit": 2
}
'''


<< Example 4. >>
Data Source:
'''json
{
    "content": "Hardware Products Price List",
    "attributes": {
    "product_name": {
        "type": "string"
    },
    "price": {
        "type": "number"
    }
}
}
'''

User Query:
Show me products with price less than 30

Structured Request:

so I change the document_contents content, and get the correct answer.

# Define your document contents and attribute information
document_contents = "Hardware Products Price List"

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

# Create a runnable for constructing queries
runnable = load_query_constructor_runnable(
    llm=llm,
    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 = "What are products that price less than 30"
query = runnable.invoke(user_input)
print(f"Constructed query: {query}")

you can try, query will been one StructuredQuery object.

from langchain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.