Ajax lm is causing parser error with sql agent

I'm having trouble getting the agent to generate an SQL query based on the prompt. Every time I try to execute the agent, it gives me an error message saying "This output parser only works with ChatGeneration output". The SQL is being generated properly using Ajax in Turbo without any errors. Can someone assist me with this issue?

I just need it to successfully create an SQL query for me.

Answer №1

Here is the code I have developed for you:

system_prefix = """You are an agent designed to interact with a SQL database.
Given an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.
Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.
You can order the results by a relevant column to return the most interesting examples in the database.
Never query for all the columns from a specific table, only ask for the relevant columns given the question.
You have access to tools for interacting with the database.
Only use the given tools. Only use the information returned by the tools to construct your final answer.
You MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.

DO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.

If the question does not seem related to the database, just return "I don't know" as the answer."""

few_shot_prompt = FewShotPromptTemplate(
    example_selector=example_selector,
    example_prompt=PromptTemplate.from_template(
        "User input: {input}\nSQL query: {query}"
    ),
    input_variables=["input", "dialect", "top_k"],
    prefix=system_prefix,
    suffix="",
    partial_variables={"format_instructions": new_parser.get_format_instructions()},
)



full_prompt = ChatPromptTemplate.from_messages(
    [
        SystemMessagePromptTemplate(prompt=few_shot_prompt),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
        
    ]
)


agent = create_sql_agent(
    llm=llm,
    db=db,
    prompt=full_prompt,
    verbose=True,
    agent_type="openai-tools",
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm encountering an error when trying to pass multiple parameters in an AJAX request

I am trying to pass three parameters to my ajax code. Here is the snippet of my code: $(document).ready(function () { SearchText(); }); function SearchText() { $("#txt712").autocomplete({ source: function (request, resp ...

Saving information to a hidden div using jStorage

Currently, I am utilizing jStorage for storing data in local storage. When I store the data using console.log() and later retrieve it using $.jStorage.get(), I found that the values are not being assigned to the hidden div. Can someone provide guidance o ...

How can I use Symfony and AJAX to upload files that are included in JavaScript JSON objects?

My client is uploading files embedded in JSON objects which include metadata for each file. The challenge I am facing is not knowing the exact number of files they will upload, so I need a dynamic solution. Currently, I have a javascript object called fi ...

Ways to assign the value of an alert to an element

Within this piece of code, my intention is to retrieve the alert value and apply it to an element. Description: The AJAX code I have written checks for values in a database, fetches new values from the database, and then displays these fetched values in a ...

AJAX - transmitting JSON data unencoded over the network

PURPOSE & CONTEXT Analyze two text samples that describe different products. Sample 1 is extracted from a form textarea and sent via AJAX to compare it with Sample 2, retrieved from a database. I am experimenting with sending it as a JSON object beca ...

Is there a way to prevent a web page from refreshing automatically for a defined duration using programming techniques?

I am currently working on a specific mobile wireframe web page that includes a timer for users to answer a question after the web content body has loaded. There are two possible outcomes when answering the question: 1) If the user fails to answer in time, ...

Understanding the process of parsing JSON response using JavaScript

I am facing an issue with reading a JSON object in JavaScript. I have received this JSON object as a response and now I need to create a jstree based on it. Here is my JavaScript code: var repoId = $('#frmHdnV').val(); // variable to hold req ...

Having trouble with uploading an image in Laravel using a modal?

For my laravel inventory system, I am facing an issue with uploading images for products. The old code I used for image upload is not working in my current project where I am utilizing a modal and ajax request to save inputs in the database. Can anyone pro ...

Completing a form and saving data to a document

I have a form that successfully writes to a text file using PHP. However, after submitting the form, the page reloads and shows a blank page. Currently, there is a message that appears using jQuery after the form is submitted. My goal is to prevent the pa ...

Tips on obtaining the ultimate URL using jQuery/AJAX

When executing $.get or .load with jQuery, the requests smoothly follow 302 redirects to provide me with the desired response. This response can be utilized in the callback function of $.get, or linked directly to the designated element for .load. Even th ...

Scrapy utilizes AJAX to send a request in order to receive the response of the dynamically generated

Is there a way to efficiently extract data from websites like this? To display all available offers, the "Show More Results" button at the bottom of the page needs to be clicked multiple times until all offers are shown. Each click triggers an AJAX reques ...

"Exploring the method of adding information to a table with the help of

Here is the structure of my HTML table: <table id="tableOrderDetail" class="table-striped table-bordered" style="align: center; width: 100%;"> <thead> <tr> <th width="5%">Sr. No.</th> <th width="25%">Product N ...

Leveraging the power of jquery-tmpl with the responseText

I am currently working on populating jquery-templates retrieved through an ajax call from a different folder on the server. I attempted to fill the responseTexts using .tmpl({..}) but unfortunately, it didn't work as expected. Here is my approach: va ...

"Exploring the dynamic world of AJAX events in the select

Currently, I am utilizing an editable primefaces selectOneMenu to exhibit certain values. The desired functionality is that when a user chooses an item from the list, a textarea should be automatically updated. On the other hand, if the user manually types ...

Instructions for sending an array of integers as an argument from JavaScript to Python

I have a JavaScript function that extracts the values of multiple checkboxes and stores them in an array: var selectedValues = $('.item:checked').map(function(){return parseInt($(this).attr('name'));}).get(); My goal is to pass this a ...

Refresh the page with user input after a button is clicked without reloading the entire page, using Python Flask

My python/flask web page accepts user input and returns it back to the user without reloading the page. Instead of using a POST request, I have implemented Ajax/JavaScript to handle user input, process it through flask in python, and display the result to ...

What is the purpose of implementing asynchronous loading for JavaScript in my webpack setup?

I am facing difficulties with handling unusual codes. I am trying to add some query parameters using $.ajaxPrefilter in all jQuery ajax requests. I came across the following code snippet which seems to ensure synchronous loading order, but in my entry.js ...

Creating a js.erb file that functions independently of ajax in Ruby on Rails 4

I am currently working on a project with the following setup: index.html.erb -> link_to "click me " , 'customers/index' , :remote => true . controller -> customers def index end index.js.erb alert('in my js file'); The alert ...

Accessing Flipkart API using CORS: A step-by-step guide

Trying to retrieve data from the following URL using a jQuery ajax call: Ajax request $.ajax({ type:"GET", url: 'https://affiliate-api.flipkart.net/affiliate/report/orders/detail/xml?startDate=2015-05-01&amp;endDate=2015-05-30&amp;st ...

Validation in PHP and Javascript is only partially effective

I encountered an issue with my form validation setup that utilizes JavaScript, Ajax, and PHP. While the errors are correctly displayed when the form is filled incorrectly, I am unable to submit the form even if there are no errors. Clicking the submit butt ...