ragflow/rag
Song Fuchang a1f06a4fdc
Feat: Support tool calling in Generate component (#7572)
### What problem does this PR solve?

Hello, our use case requires LLM agent to invoke some tools, so I made a
simple implementation here.

This PR does two things:

1. A simple plugin mechanism based on `pluginlib`:

This mechanism lives in the `plugin` directory. It will only load
plugins from `plugin/embedded_plugins` for now.

A sample plugin `bad_calculator.py` is placed in
`plugin/embedded_plugins/llm_tools`, it accepts two numbers `a` and `b`,
then give a wrong result `a + b + 100`.

In the future, it can load plugins from external location with little
code change.

Plugins are divided into different types. The only plugin type supported
in this PR is `llm_tools`, which must implement the `LLMToolPlugin`
class in the `plugin/llm_tool_plugin.py`.
More plugin types can be added in the future.

2. A tool selector in the `Generate` component:

Added a tool selector to select one or more tools for LLM:


![image](https://github.com/user-attachments/assets/74a21fdf-9333-4175-991b-43df6524c5dc)

And with the `bad_calculator` tool, it results this with the `qwen-max`
model:


![image](https://github.com/user-attachments/assets/93aff9c4-8550-414a-90a2-1a15a5249d94)


### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
2025-05-16 16:32:19 +08:00
..
app Fix: docx get image exception. (#7636) 2025-05-14 12:24:48 +08:00
llm Feat: Support tool calling in Generate component (#7572) 2025-05-16 16:32:19 +08:00
nlp Feat: add image preview to retrieval test. (#7610) 2025-05-13 14:30:36 +08:00
res Format file format from Windows/dos to Unix (#1949) 2024-08-15 09:17:36 +08:00
svr Fix: missing graph resolution and community extraction in graphrag tasks (#7586) 2025-05-13 09:21:03 +08:00
utils Fix: whole knowledge graph lost after removing any document in the knowledge base (#7151) 2025-04-30 09:43:17 +08:00
__init__.py Update comments (#4569) 2025-01-21 20:52:28 +08:00
benchmark.py Refactor embedding batch_size (#3825) 2024-12-03 16:22:39 +08:00
prompts.py Fix: docx get image exception. (#7636) 2025-05-14 12:24:48 +08:00
raptor.py <think> tag is missing. (#7256) 2025-04-24 11:44:10 +08:00
settings.py Feat: Adds OpenSearch2.19.1 as the vector_database support (#7140) 2025-04-24 16:03:31 +08:00