A method, device, medium and equipment for implementing callback function based on Ollama framework

By implementing callback functions in the ollama framework, obtaining user input and generating adaptive reply statements, the framework's shortcomings in function calls are solved, and the support capabilities and user experience of complex applications are improved.

CN118568250BActive Publication Date: 2024-11-26AUTOMOTIVE DATA OF CHINA (TIANJIN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411044869.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-11-26
Estimated Expiration
2044-08-01

AI Technical Summary

Technical Problem

In terms of functional support, especially in function calls, the ollama framework is difficult to meet the needs of complex application scenarios. The existing functions are too simple to effectively meet the needs of complex applications.

Method used

By implementing callback functions in the ollama framework, receiving callback instructions, obtaining query statements entered by the user and the reply setting tags selected by the user, generating adaptive prompt templates, and generating replies based on the query statements and historical contents, performing evaluation and Adjust to ensure the quality and relevance of the reply statements, and finally encapsulate the qualified reply statements into standard statements in JSON format.

Benefits of technology

The function call function of the ollama framework is enhanced, the prompt processing mechanism is optimized, the user experience and interaction performance is improved, and the quality of the reply statements and the adaptability of the system is ensured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568250B_ABST
    Figure CN118568250B_ABST
Patent Text Reader

Abstract

The present application discloses an implementation method, apparatus, medium and equipment based on an Ollama framework callback function. When the callback function is called, the callback function obtains a query statement input by a user and a selected reply setting tag, and dynamically generates an adaptive prompt template based on the query statement and the reply setting tag to optimize the prompt processing mechanism and improve the user experience. In addition, based on the current query content and the historical query content and the corresponding historical reply content reply statement, a more accurate reply statement is generated by utilizing the relationship of the interactive context, the reply statement is evaluated to ensure the quality of the reply statement, and after the evaluation is qualified, the reply statement is encapsulated as a standard statement output in JSON format to enhance the adaptability and interactive performance of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of callback functions of the Ollama framework, and in particular to an implementation method, device, medium and equipment based on the Ollama framework callback function. Background Art

[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) are playing an increasingly important role in the field of natural language processing. These models use deep learning technology to understand and generate language close to human level, and are widely used in multiple scenarios such as text generation, language translation, and question-answering systems. However, large language models usually consume a lot of computing resources and storage space, which makes the use of large language models in resource-constrained and low-performance environments a serious constraint.

[0003] To solve the above problems, Ollama was born as a lightweight LLM framework. It uses model quantization technology to significantly reduce the size and computing requirements of the model while ensuring model performance, making it possible to run complex language models on low-performance devices. The quantized model not only saves storage space, but also improves operating efficiency, which has important practical value for resource-constrained application environments (such as mobile devices, embedded systems, etc.).

[0004] Although Ollama has made significant progress in resource optimization, it still has some deficiencies in functional support. In particular, Ollama has not yet provided an ideal solution in supporting tool-based scenarios such as function calling. The function calling function provided by the existing Ollama framework is too simple to meet the needs of complex application scenarios. Therefore, a method is needed to enhance the function calling function of the Ollama framework. Summary of the invention

[0005] In order to solve the above technical problems, the present application is proposed. The embodiments of the present application provide an implementation method, device, medium and equipment based on the Ollama framework callback function.

[0006] According to one aspect of the present application, a method for implementing a callback function based on the ollama framework is provided, comprising: receiving a callback instruction; wherein the callback instruction represents an instruction for calling a callback function; based on the callback instruction, obtaining a query statement input by a user and a reply setting tag selected by the user; wherein the query statement includes a query content input by a user, the query content includes the user's current query content and historical query content and corresponding historical reply content, and the reply setting tag represents the reply preference characteristics expected by the user; based on the query statement and the reply setting tag, generating an adapted prompt template; wherein the prompt template is a reply statement template for replying to the query statement; based on the current query content, the historical query content and the corresponding historical reply content and the prompt template, generating a reply statement for the query statement; evaluating the reply statement to obtain an evaluation result; if the evaluation result is qualified, encapsulating the reply statement as a standard statement output in JSON format.

[0007] In one embodiment, after obtaining the query statement input by the user and the reply setting tag selected by the user based on the callback instruction, the implementation method based on the Ollama framework callback function also includes: performing parameter verification on the query statement and the reply setting tag.

[0008] In one embodiment, the reply setting label includes personality traits and language preferences; wherein, generating an adapted prompt template based on the query statement and the reply setting label includes: generating a prompt template adapted to the reply setting label based on the historical reply content and the reply setting label; wherein, the prompt template includes a prompt word.

[0009] In one embodiment, the generation of a reply statement to the query statement based on the current query content, the historical query content and the corresponding historical reply content and the prompt template includes: querying the reply content of the current query content based on the current query content, the historical query content and the corresponding historical reply content; generating a reply statement to the query statement based on the prompt template and the reply content of the current query content.

[0010] In one embodiment, the evaluation of the reply statement to obtain the evaluation result includes: calculating the conciseness of the reply statement and the relevance between the reply statement and the query statement; and calculating the evaluation result based on the conciseness of the reply statement and the relevance.

[0011] In one embodiment, the implementation method based on the ollama framework callback function also includes: if the evaluation result is unqualified, adjusting the prompt template; if the evaluation result is still not unqualified after the prompt template is adjusted more than a preset number of times, regenerating a reply statement for the query statement.

[0012] In one embodiment, the encapsulating the reply statement into a standard statement output in JSON format includes: encapsulating the reply statement into a standard statement output in JSON format; wherein the standard statement includes a function name and calling parameters.

[0013] According to another aspect of the present application, there is provided an implementation device based on the Ollama framework callback function, comprising: a callback instruction receiving module, for receiving a callback instruction; wherein the callback instruction represents an instruction for calling a callback function; an input information acquisition module, for acquiring a query statement input by a user and a reply setting label selected by a user based on the callback instruction; wherein the query statement comprises a query content input by a user, the query content comprises the user's current query content and historical query content and corresponding historical reply content, and the reply setting label represents the reply preference characteristics expected by the user; a prompt template generation module, for generating an adapted prompt template based on the query statement and the reply setting label; wherein the prompt template is a reply statement template for replying to the query statement; a reply statement generation module, for generating a reply statement to the query statement based on the current query content, the historical query content and the corresponding historical reply content and the prompt template; a reply statement evaluation module, for evaluating the reply statement and obtaining an evaluation result; and a reply statement output module, for encapsulating the reply statement into a standard statement in JSON format for output if the evaluation result is qualified.

[0014] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and the computer program is used to execute any of the above-mentioned implementation methods based on the Ollama framework callback function.

[0015] According to another aspect of the present application, an electronic device is provided, comprising: a processor; a memory for storing instructions executable by the processor; the processor is used to execute any of the above-mentioned implementation methods based on the Ollama framework callback function.

[0016] The present application provides an implementation method, device, medium and equipment based on the Ollama framework callback function, which receives a callback instruction; wherein the callback instruction represents an instruction to call the callback function; based on the callback instruction, obtains the query statement input by the user and the reply setting label selected by the user; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical reply content, and the reply setting label represents the user's expected reply preference characteristics; based on the query statement and the reply setting label, generates an adaptive prompt template; wherein the prompt template is a reply statement template for replying to the query statement; based on the current query content, the historical query content and the corresponding historical reply content and the prompt template, generates a query statement reply statement; the reply statement is evaluated to obtain the evaluation result; if the evaluation result is qualified, the reply statement is encapsulated as a standard statement in JSON format and outputted; that is, when the callback function is called, the callback function obtains the query statement input by the user and the selected reply setting tag, and dynamically generates an adaptive prompt template based on the query statement and the reply setting tag to optimize the prompt processing mechanism and improve the user experience, and based on the reply statement of the current query content and the historical query content and the corresponding historical reply content, a more accurate reply statement is generated by utilizing the relationship of the interactive context, the reply statement is evaluated to ensure the quality of the reply statement, and after the evaluation is qualified, the reply statement is encapsulated as a standard statement in JSON format and outputted to enhance the adaptability and interactive performance of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] By describing the embodiments of the present application in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present application will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0018] Figure 1 It is a flowchart of an implementation method based on the Ollama framework callback function provided by an exemplary embodiment of the present application.

[0019] Figure 2 It is a structural diagram of an implementation device based on the Ollama framework callback function provided by an exemplary embodiment of the present application.

[0020] Figure 3 It is a structural diagram of an electronic device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0021] Below, the exemplary embodiments according to the present application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application, and it should be understood that the present application is not limited to the exemplary embodiments described here.

[0022] Figure 1 FIG. 1 is a flowchart of an implementation method based on an Ollama framework callback function provided by an exemplary embodiment of the present application. Figure 1 As shown, the implementation method based on the ollama framework callback function includes the following steps:

[0023] Step 110: Receive a callback instruction.

[0024] The callback instruction refers to an instruction for calling a callback function.

[0025] Ollama is a lightweight, extensible framework for building and running large language models (LLMs) on local machines. It provides a simple API to create, run, and manage models, as well as a library of pre-built models that can be easily used in a variety of applications. Ollama is a very useful project that provides a simple, lightweight, and extensible solution for running large language models locally.

[0026] LangGraph is a new member of Langchain, and is an extension of LangChain's LangChainExpression Language (LCEL). It can coordinate multiple LLMs or states by using a directed acyclic graph. It is more complicated to use than LCEL, but the logic is clearer. Everyone has learned langchain in the early stage, and it will be much easier to learn langGraph now. This is also the learning cost I mentioned above. We can also regard it as an agent framework extended from langchain. The original agent implementation of langchain has been re-implemented in LangGraph, so it is easier for the system that originally used Langchain to access it. LangGraph is mainly a graph and a node. Each node in the process on the graph can be a tool call or a model. The graph can be regarded as a running flowchart, including each node. The flow condition state can also be added between nodes: as the context state parameter passed between nodes.

[0027] LangGraph is a framework for building stateful and multi-role Agents applications. It is not a new framework independent of Langchain, but an extension library built on Langchain that can work seamlessly with Langchain's existing chains (Chains), LangChain Expression Language (LCEL), etc. LangGraph can coordinate multiple Chains, Agents, Too|, etc. to work together to complete input tasks, and supports LLM call "loops" and more refined control of Agent processes.

[0028] An agent is an entity that can perceive the environment in some way and make decisions or take actions accordingly. Through system message prompts and the use of tools, agents can communicate, reason, execute, plan, etc., and can be used in multiple scenarios.

[0029] This application develops callback functions based on the Ollama framework and the Langraph agent environment. By defining a common function base class (BaseFunction), the data processing function is encapsulated into a callback function, and a unified interface and calling method are provided to seamlessly integrate the existing language system. In addition, various chat functions are implemented by inheriting the base class, following a consistent development model, and improving code reusability.

[0030] Step 120: Based on the callback instruction, obtain the query statement input by the user and the answer setting tag selected by the user.

[0031] Among them, the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical reply content, and the reply setting label represents the reply preference characteristics expected by the user.

[0032] After receiving the callback instruction, the callback function receives the query statement entered by the user and the reply setting label selected by the user. It should be understood that the user can manually select the reply setting label, or skip the selection operation step and directly use the default reply setting label. In this application, the callback function receives the user's current query content, historical production line content and corresponding historical reply content, and combines the context of the interaction process to generate a reply content that better meets the user's expectations.

[0033] Step 130: Generate an adapted prompt template based on the query statement and the answer setting tags.

[0034] The prompt template is a reply statement template for replying to a query statement. This application dynamically constructs an adaptive prompt template based on a reply setting tag to provide a guidance template for subsequent generation of a reply form that better meets the user's expectations.

[0035] Step 140: Generate a reply statement to the query statement based on the current query content, historical query content, corresponding historical reply content and prompt template.

[0036] After generating an adapted prompt template, the present application generates a reply statement to the query statement based on the current query content, historical query content, corresponding historical reply content and the prompt template.

[0037] Step 150: Evaluate the reply statement to obtain an evaluation result.

[0038] After generating the response statement, the present application further evaluates the response statement to determine the quality of the response statement.

[0039] Step 160: If the evaluation result is qualified, the reply statement is encapsulated as a standard statement in JSON format and output.

[0040] If the evaluation result is qualified, it means that the quality of the reply statement meets the preset standards. At this time, the reply statement can be encapsulated as a standard statement output in JSON format to obtain an output statement in a standard format, so that interaction with other modules or models can be achieved.

[0041] The present application provides an implementation method of a callback function based on the Ollama framework, by receiving a callback instruction; wherein the callback instruction represents an instruction to call the callback function; based on the callback instruction, obtaining a query statement input by the user and a reply setting label selected by the user; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical reply content, and the reply setting label represents the user's expected reply preference characteristics; based on the query statement and the reply setting label, generating an adapted prompt template; wherein the prompt template is a reply statement template for replying to the query statement; based on the current query content, the historical query content and the corresponding historical reply content and the prompt template, generating a reply statement for the query statement ; Evaluate the reply statement and obtain the evaluation result; if the evaluation result is qualified, encapsulate the reply statement into a standard statement in JSON format and output it; that is, when the callback function is called, the callback function obtains the query statement input by the user and the selected reply setting tag, and dynamically generates an adaptive prompt template based on the query statement and the reply setting tag to optimize the prompt processing mechanism and improve the user experience, and based on the current query content and the historical query content and the corresponding historical reply content reply statement, a more accurate reply statement is generated by utilizing the relationship of the interactive context, and the reply statement is evaluated to ensure the quality of the reply statement, and after the evaluation is qualified, the reply statement is encapsulated into a standard statement in JSON format and outputted to enhance the adaptability and interactive performance of the system.

[0042] In one embodiment, after step 120, the above implementation method based on the Ollama framework callback function may further include: performing parameter verification on the query statement and the reply setting tag.

[0043] Specifically, after receiving JSON format data including query statements and response setting tags and other information, this application uses Parameter and Property classes to provide a flexible parameter definition and verification method, ensuring data correctness and functional reliability, and ensuring the integrity and legality of input data through parameter definition and type verification mechanisms.

[0044] In one embodiment, the reply setting label includes personality traits and language preferences; wherein, the specific implementation method of the above step 130 may be: based on the historical reply content and the reply setting label, generate a prompt template adapted to the reply setting label; wherein, the prompt template includes prompt words.

[0045] Specifically, the present application dynamically constructs a prompt template based on personality traits and language preferences, and the present application also adjusts the constructed prompt template in combination with historical reply content (including the set tags corresponding to the historical reply content) to obtain a prompt template of the same template or a similar template. Among them, the prompt template includes a prompt word, and the present application obtains the prompt template form of the reply sentence by setting the prompt word.

[0046] In one embodiment, the specific implementation method of the above step 140 can be: based on the current query content, historical query content and corresponding historical reply content, query the reply content of the current query content; based on the prompt template and the reply content of the current query content, generate a reply statement of the query statement.

[0047] Specifically, the present application combines the current query content with historical query content and corresponding historical reply content, queries the knowledge base to obtain the reply content of the current query content, and generates a reply statement that meets the user's expectations based on the prompt template and the reply content of the current query content.

[0048] Preferably, the present application can adjust the query strategy according to the relevance between the historical query content and the current query content. For example, the relevance between the historical query content and the current query content is high, that is, the user has been querying the same question or similar questions, which means that the historical reply content cannot meet the user's needs. At this time, the query strategy for querying the current reply content can be adjusted, such as adjusting the keyword order or weight, or regenerating keywords based on the repeated content of the historical query content and the current query content.

[0049] In one embodiment, the specific implementation method of the above step 150 can be: calculating the conciseness of the reply statement and the relevance between the reply statement and the query statement; and calculating the evaluation result based on the conciseness and relevance of the reply statement.

[0050] Specifically, the present application calculates the conciseness of the reply statement and the correlation between the reply statement and the query statement, and obtains an evaluation result based on the conciseness of the reply statement and the correlation between the reply statement and the query statement. For example, the simpler the reply statement and the higher the correlation between the reply statement and the query statement, the better the evaluation result.

[0051] In one embodiment, the above-mentioned implementation method based on the ollama framework callback function may also include: if the evaluation result is unqualified, adjusting the prompt template; if the evaluation result is still not unqualified after the prompt template is adjusted more than a preset number of times, regenerating a reply statement to the query statement.

[0052] Specifically, when the evaluation result is unqualified, the reply statement is iteratively generated until the evaluation result of the reply statement is qualified, or the iteration time exceeds the preset time, or the number of iterations exceeds the preset number. Specifically, the present application uses an evaluation and iterative generation mechanism. When it is determined to be unqualified through evaluation, the prompt template is first adjusted to obtain a more concise reply statement. If the prompt template is still unqualified after multiple adjustments, it means that the correlation between the reply statement generated at this time and the query statement is not high. At this time, the reply statement of the query statement needs to be regenerated. The present application optimizes the quality of the reply and improves the accuracy and relevance through an iterative generation and evaluation mechanism.

[0053] In one embodiment, the specific implementation method of the above step 160 may be: encapsulate the reply statement into a standard statement output in JSON format; wherein the standard statement includes a function name and call parameters.

[0054] Specifically, after generating a reply statement, the present application encapsulates the reply statement into a standard statement output in JSON format, which includes meta-information such as function name and call parameters to facilitate subsequent processing and data interaction, thereby supporting flexible calls across languages ​​and platforms.

[0055] In order to more intuitively demonstrate the processing logic of the callback function of this application, an example is provided below for illustration: Assume that the question entered by the user is "What is the weather like today?", and the personality trait of the assistant is specified as "friendly and helpful".

[0056] 1. Input processing

[0057] Receive input data in JSON format, including questions, personality traits, language preferences, etc. Parameter validation is performed to ensure the integrity and legitimacy of the input.

[0058] 2. Build a prompt template

[0059] Dynamically construct a prompt template based on the input personality characteristics "friendly and helpful".

[0060] Among them, the prompt template can be as follows:

[0061] "You are a friendly and helpful AI assistant. Please provide conccise answer to the following question: [Question]".

[0062] 3. Generate reply statements

[0063] Fill the user question "What is the weather like today?" into the [Question] placeholder in the prompt template. Use the prompt template to generate a response, such as "Today's weather is sunny and warm, with a high temperature of 25℃. It's a perfect day for outdoor activities!"

[0064] 4. Iterative Optimization

[0065] Evaluate whether the generated response meets the requirements of brevity, relevance, etc. If the response is not ideal, adjust the prompt template or regenerate it as needed to improve the response quality.

[0066] 5. Packaging output

[0067] Encapsulate the optimized reply content in JSON format, including necessary meta information, such as function name, calling parameters, etc.

[0068] Output example:

[0069] {

[0070] "function_name": "chat_response",

[0071] "input": {

[0072] "question": "What is the weather like today?",

[0073] "personality": "friendly and helpful",

[0074] "language": "en"

[0075] },

[0076] "output": "Today's weather is sunny and warm, with a high temperature of 25°C. It's a perfect day for outdoor activities!"

[0077] }

[0078] 6. Exception handling

[0079] During the processing, possible exceptions are captured, such as input errors, network timeouts, etc. Through proper error handling and logging, the stability and maintainability of the system are ensured.

[0080] Figure 2 FIG. 1 is a schematic diagram of a structure of an implementation device based on an Ollama framework callback function provided by an exemplary embodiment of the present application. Figure 2 As shown, the implementation device 20 based on the Ollama framework callback function includes: a callback instruction receiving module 21, which is used to receive a callback instruction; wherein the callback instruction represents an instruction to call the callback function; an input information acquisition module 22, which is used to obtain the query statement input by the user and the reply setting label selected by the user based on the callback instruction; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical reply content, and the reply setting label represents the user's expected reply preference characteristics; a prompt template generation module 23, which is used to generate an adaptive prompt template based on the query statement and the reply setting label; wherein the prompt template is a reply statement template for replying to the query statement; a reply statement generation module 24, which is used to generate a reply statement for the query statement based on the current query content, historical query content and the corresponding historical reply content and the prompt template; a reply statement evaluation module 25, which is used to evaluate the reply statement and obtain an evaluation result; a reply statement output module 26, which is used to encapsulate the reply statement into a standard statement output in JSON format if the evaluation result is qualified.

[0081] The present application provides an implementation device based on the Ollama framework callback function, which receives a callback instruction through a callback instruction receiving module 21; wherein the callback instruction represents an instruction to call a callback function; the input information acquisition module 22 obtains the query statement input by the user and the reply setting label selected by the user based on the callback instruction; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical reply content, and the reply setting label represents the user's expected reply preference characteristics; the prompt template generation module 23 generates an adapted prompt template based on the query statement and the reply setting label; wherein the prompt template is a reply statement template for replying to the query statement; the reply statement generation module 24 generates a prompt template based on the current query content, the historical query content and the corresponding historical reply content and the prompt template. The reply statement evaluation module 25 evaluates the reply statement and obtains the evaluation result; if the evaluation result is qualified, the reply statement output module 26 encapsulates the reply statement as a standard statement in JSON format and outputs it; that is, when the callback function is called, the callback function obtains the query statement input by the user and the selected reply setting label, and dynamically generates an adaptive prompt template based on the query statement and the reply setting label to optimize the prompt processing mechanism and improve the user experience, and based on the current query content and the historical query content and the corresponding historical reply content reply statement, a more accurate reply statement is generated by utilizing the relationship between the interactive context, and the reply statement is evaluated to ensure the quality of the reply statement, and after the evaluation is qualified, the reply statement is encapsulated as a standard statement in JSON format and outputted to enhance the adaptability and interactive performance of the system.

[0082] In one embodiment, the above-mentioned implementation device 20 based on the Ollama framework callback function can be further configured to: perform parameter verification on the query statement and the reply setting tag.

[0083] In one embodiment, the reply setting label includes personality traits and language preferences; wherein, the prompt template generation module 23 can be further configured to: generate a prompt template adapted to the reply setting label based on historical reply content and the reply setting label; wherein, the prompt template includes prompt words.

[0084] In one embodiment, the above-mentioned reply statement generation module 24 can be further configured to: query the reply content of the current query content based on the current query content, historical query content and corresponding historical reply content; generate a reply statement of the query statement based on the prompt template and the reply content of the current query content.

[0085] In one embodiment, the reply statement evaluation module 25 may be further configured to: calculate the conciseness of the reply statement and the relevance between the reply statement and the query statement; and calculate the evaluation result based on the conciseness and relevance of the reply statement.

[0086] In one embodiment, the above-mentioned implementation device 20 based on the ollama framework callback function can be further configured as: if the evaluation result is unqualified, adjust the prompt template; if the evaluation result is still not unqualified after the prompt template is adjusted more than a preset number of times, regenerate the reply statement of the query statement.

[0087] In one embodiment, the reply statement output module 26 may be further configured to: encapsulate the reply statement into a standard statement in JSON format and output it; wherein the standard statement includes a function name and call parameters.

[0088] Below, reference Figure 3 The electronic device according to the embodiment of the present application is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signal from them.

[0089] Figure 3 A block diagram of an electronic device according to an embodiment of the present application is illustrated.

[0090] like Figure 3 As shown, the electronic device 10 includes one or more processors 11 and a memory 12 .

[0091] The processor 11 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 10 to perform desired functions.

[0092] The memory 12 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 11 may run the program instructions to implement the methods of the various embodiments of the present application described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.

[0093] In one example, the electronic device 10 may further include: an input device 13 and an output device 14 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0094] When the electronic device is a stand-alone device, the input device 13 may be a communication network connector, which is used to receive the collected input signals from the first device and the second device.

[0095] In addition, the input device 13 may also include, for example, a keyboard, a mouse, and the like.

[0096] The output device 14 can output various information to the outside, including the determined distance information, direction information, etc. The output device 14 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0097] Of course, to simplify, Figure 3 Only some of the components related to the present application in the electronic device 10 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 10 may also include any other appropriate components.

[0098] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the method according to various embodiments of the present application described in the above-mentioned "Exemplary Method" section of this specification.

[0099] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0100] In addition, an embodiment of the present application may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the steps of the method according to various embodiments of the present application described in the above "Exemplary Method" section of this specification.

[0101] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0102] The basic principles of the present application are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present application are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present application. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, not for limitation, and the above details do not limit the present application to being implemented by adopting the above specific details.

[0103] The block diagrams of the devices, apparatuses, equipment, and systems involved in this application are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagram. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including", "comprising", "having", etc. are open words, referring to "including but not limited to", and can be used interchangeably with them. The words "or" and "and" used here refer to the words "and / or" and can be used interchangeably with them, unless the context clearly indicates otherwise. The words "such as" used here refer to the phrase "such as but not limited to", and can be used interchangeably with them.

[0104] It should also be noted that in the apparatus, device and method of the present application, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present application.

[0105] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present application. Therefore, the present application is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

[0106] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present application to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.

Claims

1. A method for implementing a callback function based on the Ollama framework, characterized in that: include: Receive a callback instruction; wherein the callback instruction represents an instruction to call a callback function; Based on the callback instruction, the query statement input by the user and the answer setting label selected by the user are obtained; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical answer content, and the answer setting label indicates the answer preference characteristics expected by the user, and the answer setting label includes personality characteristics and language preferences; Based on the historical reply content and the reply setting tag, a prompt template adapted to the reply setting tag is generated; wherein the prompt template is a reply statement template for replying to the query statement, and the prompt template includes a prompt word; Generate a reply statement to the query statement based on the current query content, the historical query content and the corresponding historical reply content and the prompt template; Evaluate the response statement to obtain an evaluation result; If the evaluation result is qualified, the reply statement is encapsulated as a standard statement in JSON format and output; If the evaluation result is unqualified, adjusting the prompt template; If the evaluation result is still not unqualified after the prompt template is adjusted for more than a preset number of times, a reply statement to the query statement is regenerated.

2. The implementation method based on the Ollama framework callback function according to claim 1, characterized in that: After obtaining the query statement input by the user and the answer setting tag selected by the user based on the callback instruction, the implementation method based on the Ollama framework callback function also includes: Perform parameter verification on the query statement and the response setting tag.

3. The implementation method based on the Ollama framework callback function according to claim 1, characterized in that: The generating of the reply statement of the query statement based on the current query content, the historical query content and the corresponding historical reply content and the prompt template includes: Based on the current query content, the historical query content and the corresponding historical reply content, query the reply content of the current query content; Based on the prompt template and the reply content of the current query content, a reply statement of the query statement is generated.

4. The implementation method based on the Ollama framework callback function according to claim 1, characterized in that: The evaluating the reply statement to obtain the evaluation result includes: Calculating the conciseness of the reply statement and the relevance between the reply statement and the query statement; The evaluation result is calculated based on the conciseness of the reply sentence and the relevance.

5. The implementation method based on the Ollama framework callback function according to claim 1, characterized in that: The output of encapsulating the reply statement into a standard statement in JSON format includes: The reply statement is encapsulated as a standard statement in JSON format and output; wherein the standard statement includes a function name and calling parameters.

6. An implementation device based on the Ollama framework callback function, characterized in that: include: A callback instruction receiving module, used to receive a callback instruction; wherein the callback instruction represents an instruction to call a callback function; An input information acquisition module, used to acquire the query statement input by the user and the answer setting label selected by the user based on the callback instruction; wherein the query statement includes the query content input by the user, the query content includes the user's current query content and historical query content and the corresponding historical answer content, and the answer setting label indicates the answer preference characteristics expected by the user, and the answer setting label includes personality characteristics and language preferences; A prompt template generation module, used to generate a prompt template adapted to the reply setting tag based on the historical reply content and the reply setting tag; wherein the prompt template is a reply sentence template for replying to the query sentence, and the prompt template includes a prompt word; A reply statement generating module, used for generating a reply statement of the query statement based on the current query content, the historical query content and the corresponding historical reply content and the prompt template; A reply statement evaluation module, used to evaluate the reply statement and obtain an evaluation result; A reply statement output module is used to encapsulate the reply statement into a standard statement in JSON format and output it if the evaluation result is qualified; The implementation device based on the ollama framework callback function is further configured as follows: If the evaluation result is unqualified, adjusting the prompt template; If the evaluation result is still not unqualified after the prompt template is adjusted for more than a preset number of times, a reply statement to the query statement is regenerated.

7. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the implementation method based on the Ollama framework callback function described in any one of claims 1 to 5 above.

8. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is used to execute the implementation method based on the Ollama framework callback function described in any one of claims 1-5 above.