A plugin can reverse invoke Dify’s internal LLM capabilities, including all model types and functions within the platform, such as TTS and Rerank. If you are unfamiliar with the basics of reverse invocation, first read Reverse Invocation of Dify Services.
Every model invocation takes a ModelConfig type parameter. Its structure is defined in the General Specifications Definition and varies slightly by model type.
For example, LLM type models also require completion_params and mode parameters. You can construct this structure manually or use model-selector type parameters or configurations.
Invoke LLM#
Entry Point#
Interface#
If the model you are invoking does not have tool_call capability, the tools passed here will not take effect.
Use Case#
This example invokes OpenAI’s gpt-4o-mini model within a Tool:
Note that the code passes the query parameter from tool_parameters.
Best Practice#
Avoid constructing LLMModelConfig manually. Instead, let users select the model they want in the UI by adding a model parameter to the tool’s parameter list:
Because the scope of the model parameter is llm, users can only select llm type models. The previous use case then becomes:
Invoke Summary#
This interface summarizes a piece of text using the system model within your current workspace.
Entry Point#
Interface#
text: The text to summarize.instruction: Additional instructions, letting you control the style of the summary.
Invoke TextEmbedding#
Entry Point#
Interface#
Invoke Rerank#
Entry Point#
Interface#
Invoke TTS#
Entry Point#
Interface#
The bytes stream returned by the tts interface is an mp3 audio byte stream, and each iteration returns a complete audio segment. For more in-depth processing, choose an appropriate audio library.
Invoke Speech2Text#
Entry Point#
Interface#
Here, file is an audio file encoded in mp3 format.
Invoke Moderation#
Entry Point#
Interface#
A return value of true indicates that the text contains sensitive content.
Related Resources#
- Reverse Invocation of Dify Services - Understand the fundamental concepts of reverse invocation
- Reverse Invocation of App - Learn how to invoke Apps within the platform
- Reverse Invocation of Tool - Learn how to invoke other plugins
- Model Plugin Development Guide - Learn how to develop custom model plugins
- Model Designing Rules - Understand the design principles of model plugins