Comments (1)
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)
- ChatPrompTemplate with MessagesPlaceholder ser/des broken
- "Human: " added to the prompt. HOT 2
- openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid value for 'content': expected a string, got null HOT 3
- ImportError: cannot import name 'LangSmithParams' from 'langchain_core.language_models.chat_models'(import langchain_google_genai) in collab environment HOT 3
- DOC: Need improvement in the langchain js docs v0.2
- ImportError: cannot import name 'AutoModelForCausalLM' from partially initialized module 'transformers' (most likely due to a circular import)
- Chroma - wrong relevance scores. HOT 1
- Milvus Vector Store: Collection Not Created During Initialization
- ChatOllama & Ollama from langchain_ollama partner package does not provide support to pass base_url HOT 5
- TypeError: 'VectorParams' object is not subscriptable HOT 6
- langchain-huggingface: Using ChatHuggingFace requires hf token for local TGI using localhost HuggingFaceEndpoint HOT 3
- Detected a JSON file that does not conform to the Unstructured schema. partition_json currently only processes serialized Unstructured output while using langchain S3DirectoryLoader HOT 1
- QianfanEmbeddingsEndpoint error in LangChain 0.2.9
- dumpd costs extra 1s per invoke
- DOC: Running Output-fixing parser example code results in an error HOT 1
- Agent Executor using some specific search tools is causing an error HOT 3
- graph_transformers.llm.py create_simple_model not constraining relationships with enums when using OpenAI LLM
- TypeError('Object of type CallbackManagerForToolRun is not JSON serializable') on Coder agent HOT 8
- DOC: Page Navigation link references (href); Page's navigation links at the bottom incorrectly references the same page instead of the next.
- Callbacks called different times when passed in a list or callback manager. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langchain.