Large language model-based question processing method and apparatus, electronic device, and storage medium
View Patent ↗Provided are a query processing method based on a large language model, an electronic device, and a storage medium. The query processing method based on a large language model includes acquiring a to-be-processed target query; generating a prompt based on a to-be-used target data model, target format information of a specified data format, and the target query; inputting the prompt into the large language model to obtain a target parsing result of the specified data format outputted by the large language model; and modifying the target parsing result based on the target data model.
1 . A query processing method based on a large language model, being executed by an electronic device having a query processing function and the method comprising:
acquiring a target query;
generating a prompt based on a target data model, target format information of a specified data format, and the target query, wherein the target data model comprises data tables preconstructed based on a data dimension and a data measure, the target format information comprises a dimension field, a measure field, and a filtering condition, wherein the filtering condition comprises a target filter field, a filtering value of the target filter field, and an operator of the target filter field, and wherein the data dimension comprises at least one of an order number, an order date, a region, a province, a city, a product name, a product category, a product subcategory, a customer name, a customer type code, a shipping date, or a mailing method; and the data measure comprises at least one of a quantity, a sales amount, a cost, or a profit;
using the prompt as input of the large language model to query the target data model through the large language model, and obtaining output of the large language model in the specified data format as a target parsing result, wherein the target parsing result is a serialized result;
determining an answer to the target query by modifying the target parsing result based on the target data model; and
displaying the answer to the target query through the electronic device;
wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
for a filtering condition in the target parsing result, determining a field type of a target filter field according to a filtering value of the target filter field, matching the target filter field with data fields in the target data model with reference to the field type of the target filter field, modifying the target filter field according to a matching result of the target filter field, and determining the answer to the target query based on the modified target filter field.
2 . The query processing method based on the large language model of claim 1 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
in response to the target filter field being of a character type, acquiring the filtering value of the target filter field from the filtering condition; and
matching the filtering value of the target filter field with field values of the data fields in the target data model and modifying the target filter field according to the matching result.
3 . The query processing method based on the large language model of claim 2 , wherein matching the filtering value of the target filter field with the field values of the data fields in the target data model and modifying the target filter field according to the matching result comprises:
in response to the target filter field belonging to the data fields, acquiring a field value of the target filter field from the target data model;
matching the filtering value of the target filter field with the field value of the target filter field from the target data model to obtain a first matching result;
in response to the first matching result being a matching failure, matching the filtering value of the target filter field with a field value of another data field in the target data model to obtain a second matching result; and
in response to the second matching result being a matching success, modifying the target filter field to another data field successfully matched.
4 . The query processing method based on the large language model of claim 3 , wherein modifying the target filter field according to the matching result further comprises:
in response to the second matching result being a matching failure, performing word segmentation on the target parsing result to obtain word segmentation information; and
matching the word segmentation information with the data fields in the target data model and modifying the target filter field to a data field successfully matched.
5 . The query processing method based on the large language model of claim 2 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model further comprises:
in response to all data fields in the target data model failing to match with the target filter field, inputting the filtering value of the target filter field as a query and the field values of the data fields as options into the large language model to obtain a target data field selected by the large language model and modifying the target filter field to the target data field.
6 . The query processing method based on the large language model of claim 2 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model further comprises:
in response to the target filter field being of a date type, performing date formatting on the filtering value of the target filter field to obtain a date-type value; and
matching the date-type value with a field value of the target filter field in the target data model and modifying the target filter field according to a matching result.
7 . The query processing method based on the large language model of claim 1 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
for a target dimension in the target parsing result, in response to the filtering condition using the target dimension as the target filter field and the operator of the target filter field being “equal to” or “containing”, deleting the target dimension from the target parsing result.
8 . The query processing method based on the large language model of claim 1 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
in response to modifying the target filter field in the filtering condition to a target data field based on the target data model and the target filter field being a target dimension or a target measure in the target parsing result, modifying the target dimension or the target measure in the target parsing result to the target data field.
9 . The query processing method based on the large language model of claim 1 , wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
in response to target filter fields in at least two filtering conditions being the same, combining the at least two filtering conditions.
10 . The query processing method based on the large language model of claim 1 , wherein generating the prompt based on the target data model and the target query comprises:
acquiring a data field in the target data model and acquiring the target format information of the specified data format; and
constructing the prompt based on the data field in the target data model, the target format information, and the target query,
wherein the target parsing result is configured for establishment of a relationship between the target query and the data field in the target data model.
11 . An electronic device, comprising:
at least one processor; and
a memory communicatively connected to the at least one processor,
wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the following:
acquiring a target query;
generating a prompt based on a target data model, target format information of a specified data format, and the target query, wherein the target data model comprises data tables preconstructed based on a data dimension and a data measure, the target format information comprises a dimension field, a measure field, and a filtering condition, wherein the filtering condition comprises a target filter field, a filtering value of the target filter field, and an operator of the target filter field, wherein the data dimension comprises at least one of an order number, an order date, a region, a province, a city, a product name, a product category, a product subcategory, a customer name, a customer type code, a shipping date, or a mailing method; and the data measure comprises at least one of a quantity, a sales amount, a cost, or a profit;
using the prompt as input of a large language model to query the target data model through the large language model, and obtaining output of the large language model in the specified data format as a target parsing result, wherein the target parsing result is a serialized result;
determining an answer to the target query by modifying the target parsing result based on the target data model; and
displaying the answer to the target query;
wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
for a filtering condition in the target parsing result, determining a field type of a target filter field according to a filtering value of the target filter field, matching the target filter field with data fields in the target data model with reference to the field type of the target filter field, modifying the target filter field according to a matching result of the target filter field, and determining the answer to the target query based on the modified target filter field.
12 . The electronic device of claim 11 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model by:
in response to the target filter field being of a character type, acquiring the filtering value of the target filter field from the filtering condition; and
matching the filtering value of the target filter field with field values of the data fields in the target data model and modifying the target filter field according to the matching result.
13 . The electronic device of claim 12 , wherein the at least one processor is enabled to perform matching the filtering value of the target filter field with the field values of the data fields in the target data model and modifying the target filter field according to the matching result by:
in response to the target filter field belonging to the data fields, acquiring a field value of the target filter field from the target data model;
matching the filtering value of the target filter field with the field value of the target filter field from the target data model to obtain a first matching result;
in response to the first matching result being a matching failure, matching the filtering value of the target filter field with a field value of another data field in the target data model to obtain a second matching result; and
in response to the second matching result being a matching success, modifying the target filter field to another data field successfully matched.
14 . The electronic device of claim 13 , wherein the at least one processor is enabled to perform modifying the target filter field according to the matching result further by:
in response to the second matching result being a matching failure, performing word segmentation on the target parsing result to obtain word segmentation information; and
matching the word segmentation information with the data fields in the target data model and modifying the target filter field to a data field successfully matched.
15 . The electronic device of claim 12 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model further by:
in response to all data fields in the target data model failing to match with the target filter field, inputting the filtering value of the target filter field as a query and the field values of the data fields as options into the large language model to obtain a target data field selected by the large language model and modifying the target filter field to the target data field.
16 . The electronic device of claim 12 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model further by:
in response to the target filter field being of a date type, performing date formatting on the filtering value of the target filter field to obtain a date-type value; and
matching the date-type value with a field value of the target filter field in the target data model and modifying the target filter field according to a matching result.
17 . The electronic device of claim 11 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model by:
for a target dimension in the target parsing result, in response to the filtering condition using the target dimension as the target filter field and the operator of the target filter field being “equal to” or “containing”, deleting the target dimension from the target parsing result.
18 . The electronic device of claim 11 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model by:
in response to modifying the target filter field in the filtering condition to a target data field based on the target data model and the target filter field being a target dimension or a target measure in the target parsing result, modifying the target dimension or the target measure in the target parsing result to the target data field.
19 . The electronic device of claim 11 , wherein the at least one processor is enabled to perform determining the answer to the target query by modifying the target parsing result based on the target data model by:
in response to target filter fields in at least two filtering conditions being the same, combining the at least two filtering conditions.
20 . A non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the following:
acquiring a target query;
generating a prompt based on a target data model, target format information of a specified data format, and the target query, wherein the target data model comprises data tables preconstructed based on a data dimension and a data measure, the target format information comprises a dimension field, a measure field, and a filtering condition, wherein the filtering condition comprises a target filter field, a filtering value of the target filter field, and an operator of the target filter field, and wherein the data dimension comprises at least one of an order number, an order date, a region, a province, a city, a product name, a product category, a product subcategory, a customer name, a customer type code, a shipping date, or a mailing method; and the data measure comprises at least one of a quantity, a sales amount, a cost, or a profit;
using the prompt as input of a large language model to query the target data model through the large language model, and obtaining output of the large language model in the specified data format as a target parsing result, wherein the target parsing result is a serialized result;
determining an answer to the target query by modifying the target parsing result based on the target data model; and
displaying the answer to the target query through an electronic device;
wherein determining the answer to the target query by modifying the target parsing result based on the target data model comprises:
for a filtering condition in the target parsing result, determining a field type of a target filter field according to a filtering value of the target filter field, matching the target filter field with data fields in the target data model with reference to the field type of the target filter field, modifying the target filter field according to a matching result of the target filter field, and determining the answer to the target query based on the modified target filter field.