Josep Pon Farreny commited on
Commit
f24ac08
·
1 Parent(s): 3b57587

doc: Add how to add a new tool into README

Browse files
Files changed (1) hide show
  1. README.md +65 -2
README.md CHANGED
@@ -30,6 +30,69 @@ new commits:
30
 
31
  ```bash
32
  uv run pre-commit install
33
- ````
34
 
35
- # Add a new tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  ```bash
32
  uv run pre-commit install
33
+ ```
34
 
35
+ # Adding new tools
36
+
37
+ For the sake of clarity, we organize tools under the directory
38
+ `tdagent/tools/`, and then add them to the `app.py` list of
39
+ interfaces.
40
+
41
+ As an example, let's create a tool that adds up two numbers. First,
42
+ we create a new file `tdagent/tools/calc_tool.py` with the following
43
+ content:
44
+
45
+ ```Python
46
+ import gradio as gr
47
+
48
+
49
+ def add_numbers(num1: float, num2: str) -> float:
50
+ """Compute the addition of two numbers `num1 + num2`.
51
+
52
+ Args:
53
+ num1: First number to add.
54
+ num2: Second number to add.
55
+
56
+ Returns:
57
+ The result of computing `num1 + num2`.
58
+ """
59
+ return num1 + num2
60
+
61
+
62
+ gr_add_numbers = gr.Interface(
63
+ fn=add_numbers,
64
+ inputs=["number", "number"],
65
+ outputs="number",
66
+ title="Add two numbers",
67
+ description="Compute the addition of two numbers",
68
+ )
69
+ ```
70
+
71
+ Naming the file `calc_tool.py` is convenient as it let us add
72
+ additional tools to calculate operations inside the same Python
73
+ module.
74
+
75
+ Then, we modify the `app.py` file to include our new tool.
76
+
77
+ ```Python
78
+ import gradio as gr
79
+
80
+ from tdagent.tools.get_url_content import gr_get_url_http_content
81
+ ... # Other tools already present before
82
+ from tdagent.tools.calc_tool import gr_add_numbers
83
+
84
+
85
+ gr_app = gr.TabbedInterface(
86
+ [
87
+ gr_get_url_http_content,
88
+ ..., # Other tools already present before
89
+ gr_add_numbers
90
+ ],
91
+ )
92
+
93
+ if __name__ == "__main__":
94
+ gr_app.launch(mcp_server=True)
95
+ ```
96
+
97
+ In future updates we might change the `app.py` to automatically
98
+ include any `gr.Interface`, but for now this works just fine.