Customizing Large Language Model (LLM) Invocation Method
In previous chapters, we have mentioned that VMind calls the Large Language Model (LLM) during the processes of data processing, data aggregation, and chart generation. By default, we call the LLM via HTTP requests. You can specify the URL of the LLM service and set the header for authentication when initializing the VMind instance.
However, in some special cases, you may need to customize the way the LLM service is called. For example, you may want to request the service via RPC, or you may want to do some extra processing after the model returns the results, and then return the processed results to VMind. To meet these needs, we provide an option to set the customRequestFunc
object when initializing the VMind object. You can use this option to customize the way the LLM service is called at different stages.
The type definition of customRequestFunc
is as follows:
The customRequestFunc
object has two properties: chartAdvisor
and dataQuery
, which correspond to the three functions of chart generation (vmind.generateChart
) and data aggregation (vmind.dataQuery
) in VMind. Each property is a function of type RequestFunc
, the parameters of which are the prompt information prompt
, the user input display intention userPrompt
, and the options
object when the model executes the task. When VMind requests the LLM service, it will call your custom function and pass these three parameters. You need to use prompt
and userPrompt
to request the LLM service in your custom function and return the model's generated results in the format of LLMResponse
. The structure of LLMResponse
is the same as that of the OpenAI completions API (for details, see The chat completion object).
Note that the functions in customRequestFunc
are asynchronous, and VMind will use await
to wait for the end of the model request.
Below is an example of using RPC to call the LLM service during the chart generation process: