Spaces:
Runtime error
Runtime error
Initial project structure
#1
by
jponf
- opened
- .gitignore +130 -0
- .pre-commit-config.yaml +118 -0
- README.md +87 -2
- app.py +7 -56
- pyproject.toml +125 -0
- requirements-dev.txt +97 -0
- requirements.txt +72 -1
- tdagent/__init__.py +0 -0
- tdagent/tools/__init__.py +0 -0
- tdagent/tools/get_url_content.py +65 -0
- tdagent/tools/letter_counter.py +23 -0
- uv.lock +0 -0
.gitignore
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
env/
|
12 |
+
build/
|
13 |
+
develop-eggs/
|
14 |
+
dist/
|
15 |
+
downloads/
|
16 |
+
eggs/
|
17 |
+
.eggs/
|
18 |
+
lib/
|
19 |
+
lib64/
|
20 |
+
parts/
|
21 |
+
sdist/
|
22 |
+
var/
|
23 |
+
wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
|
28 |
+
# PyInstaller
|
29 |
+
# Usually these files are written by a python script from a template
|
30 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
31 |
+
*.manifest
|
32 |
+
*.spec
|
33 |
+
|
34 |
+
# Installer logs
|
35 |
+
pip-log.txt
|
36 |
+
pip-delete-this-directory.txt
|
37 |
+
|
38 |
+
# Unit test / coverage reports
|
39 |
+
htmlcov/
|
40 |
+
.tox/
|
41 |
+
.coverage
|
42 |
+
.coverage.*
|
43 |
+
.cache
|
44 |
+
nosetests.xml
|
45 |
+
coverage.xml
|
46 |
+
*.cover
|
47 |
+
.hypothesis/
|
48 |
+
.pytest_cache/
|
49 |
+
|
50 |
+
# Translations
|
51 |
+
*.mo
|
52 |
+
*.pot
|
53 |
+
|
54 |
+
# PyBuilder
|
55 |
+
target/
|
56 |
+
|
57 |
+
# Jupyter Notebook
|
58 |
+
.ipynb_checkpoints
|
59 |
+
|
60 |
+
# pyenv
|
61 |
+
.python-version
|
62 |
+
|
63 |
+
# dotenv
|
64 |
+
.env
|
65 |
+
|
66 |
+
# virtualenv
|
67 |
+
.venv
|
68 |
+
venv/
|
69 |
+
ENV/
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# mkdocs documentation
|
75 |
+
/site
|
76 |
+
docs/*.png
|
77 |
+
|
78 |
+
# mypy
|
79 |
+
.mypy_cache/
|
80 |
+
|
81 |
+
# vscode cache
|
82 |
+
.vscode
|
83 |
+
|
84 |
+
# Pycharm files
|
85 |
+
.idea
|
86 |
+
|
87 |
+
### macOS template
|
88 |
+
*.DS_Store
|
89 |
+
.AppleDouble
|
90 |
+
.LSOverride
|
91 |
+
|
92 |
+
# serverless
|
93 |
+
**/.serverless
|
94 |
+
**/node_modules
|
95 |
+
|
96 |
+
# terraform
|
97 |
+
**/.terraform
|
98 |
+
*.tfstate*
|
99 |
+
|
100 |
+
# exclude temp files from source control
|
101 |
+
temp/
|
102 |
+
tmp/
|
103 |
+
|
104 |
+
# exclude data from source control by default
|
105 |
+
/data/*
|
106 |
+
|
107 |
+
!/data/sat2023-sample/
|
108 |
+
!/data/cnf-sample/
|
109 |
+
|
110 |
+
!/data/sat2023-cos-similarity-dataset/
|
111 |
+
/data/sat2023-cos-similarity-dataset/*
|
112 |
+
!/data/sat2023-cos-similarity-dataset/results_main_detailed.csv
|
113 |
+
|
114 |
+
# Configurations
|
115 |
+
/config/
|
116 |
+
|
117 |
+
# Logs
|
118 |
+
lightning_logs/
|
119 |
+
|
120 |
+
# Models
|
121 |
+
/models/
|
122 |
+
|
123 |
+
|
124 |
+
# Poetry code artifact settings
|
125 |
+
.poetry/
|
126 |
+
poetry.toml
|
127 |
+
|
128 |
+
# Mise
|
129 |
+
.mise.toml
|
130 |
+
mise.toml
|
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v2.4.0
|
4 |
+
hooks:
|
5 |
+
- id: requirements-txt-fixer
|
6 |
+
files: requirements.txt|requirements-dev.txt|requirements-test.txt
|
7 |
+
- id: trailing-whitespace
|
8 |
+
exclude: |
|
9 |
+
(?x)^(
|
10 |
+
notebooks/
|
11 |
+
)
|
12 |
+
args: [--markdown-linebreak-ext=md]
|
13 |
+
- id: end-of-file-fixer
|
14 |
+
exclude: |
|
15 |
+
(?x)^(
|
16 |
+
notebooks/
|
17 |
+
)
|
18 |
+
- id: check-yaml
|
19 |
+
- id: check-symlinks
|
20 |
+
- id: check-toml
|
21 |
+
- id: check-added-large-files
|
22 |
+
args: ["--maxkb=1000"]
|
23 |
+
- repo: https://github.com/asottile/add-trailing-comma
|
24 |
+
rev: v3.1.0
|
25 |
+
hooks:
|
26 |
+
- id: add-trailing-comma
|
27 |
+
- repo: https://github.com/psf/black
|
28 |
+
rev: 23.1.0
|
29 |
+
hooks:
|
30 |
+
- id: black
|
31 |
+
exclude: |
|
32 |
+
(?x)^(
|
33 |
+
notebooks/
|
34 |
+
)
|
35 |
+
- repo: https://github.com/pycqa/isort
|
36 |
+
rev: "5.12.0"
|
37 |
+
hooks:
|
38 |
+
- id: isort
|
39 |
+
exclude: |
|
40 |
+
(?x)^(
|
41 |
+
notebooks/
|
42 |
+
)
|
43 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
44 |
+
rev: v0.9.7
|
45 |
+
hooks:
|
46 |
+
- id: ruff # linter
|
47 |
+
exclude: |
|
48 |
+
(?x)^(
|
49 |
+
scripts/|
|
50 |
+
notebooks/
|
51 |
+
)
|
52 |
+
# - id: ruff-format
|
53 |
+
- repo: local
|
54 |
+
hooks:
|
55 |
+
- id: update-req
|
56 |
+
name: Update requirements.txt
|
57 |
+
stages: [pre-commit]
|
58 |
+
language: system
|
59 |
+
entry: uv
|
60 |
+
files: uv.lock|requirements.txt
|
61 |
+
pass_filenames: false
|
62 |
+
args:
|
63 |
+
[
|
64 |
+
"export",
|
65 |
+
"--format",
|
66 |
+
"requirements-txt",
|
67 |
+
"--no-hashes",
|
68 |
+
"--no-dev",
|
69 |
+
"-o",
|
70 |
+
"requirements.txt",
|
71 |
+
]
|
72 |
+
- id: update-dev-req
|
73 |
+
name: Update requirements-dev.txt
|
74 |
+
stages: [pre-commit]
|
75 |
+
language: system
|
76 |
+
entry: uv
|
77 |
+
files: uv.lock|requirements-dev.txt
|
78 |
+
pass_filenames: false
|
79 |
+
args:
|
80 |
+
[
|
81 |
+
"export",
|
82 |
+
"--format",
|
83 |
+
"requirements-txt",
|
84 |
+
"--no-hashes",
|
85 |
+
"--group",
|
86 |
+
"dev",
|
87 |
+
"--group",
|
88 |
+
"test",
|
89 |
+
"-o",
|
90 |
+
"requirements-dev.txt",
|
91 |
+
]
|
92 |
+
- id: mypy
|
93 |
+
name: Running mypy
|
94 |
+
stages: [commit]
|
95 |
+
language: system
|
96 |
+
entry: uv run mypy
|
97 |
+
args: [--install-types, --non-interactive]
|
98 |
+
types: [python]
|
99 |
+
exclude: |
|
100 |
+
(?x)^(
|
101 |
+
scripts/|
|
102 |
+
notebooks/
|
103 |
+
)
|
104 |
+
|
105 |
+
# - id: pytest
|
106 |
+
# name: pytest
|
107 |
+
# stages: [commit]
|
108 |
+
# language: system
|
109 |
+
# entry: poetry run pytest
|
110 |
+
# types: [python]
|
111 |
+
|
112 |
+
# - id: pytest-cov
|
113 |
+
# name: pytest
|
114 |
+
# stages: [push]
|
115 |
+
# language: system
|
116 |
+
# entry: poetry run pytest --cov --cov-fail-under=100
|
117 |
+
# types: [python]
|
118 |
+
# pass_filenames: false
|
README.md
CHANGED
@@ -7,7 +7,92 @@ sdk: gradio
|
|
7 |
sdk_version: 5.0.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
|
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
sdk_version: 5.0.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: tdb
|
12 |
---
|
13 |
|
14 |
+
# TDA Agent Tools
|
15 |
+
|
16 |
+
# Development setup
|
17 |
+
|
18 |
+
To start developing you need the following tools:
|
19 |
+
|
20 |
+
* [uv](https://docs.astral.sh/uv/)
|
21 |
+
|
22 |
+
To start, sync all the dependencies with `uv sync --all-groups`.
|
23 |
+
Then, install the pre-commit hooks (`uv run pre-commit install`) to
|
24 |
+
ensure that future commits comply with the bare minimum to keep
|
25 |
+
code _readable_.
|
26 |
+
|
27 |
+
Once `uv` has installed all the dependencies, install the `pre-commit`
|
28 |
+
hooks to run linting and requirement files update, etc., before creating
|
29 |
+
new commits:
|
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.
|
app.py
CHANGED
@@ -1,64 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
-
|
20 |
-
for val in history:
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
-
response = ""
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
-
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
from tdagent.tools.get_url_content import gr_get_url_http_content
|
4 |
+
from tdagent.tools.letter_counter import gr_letter_counter
|
|
|
|
|
5 |
|
6 |
|
7 |
+
gr_app = gr.TabbedInterface(
|
8 |
+
[
|
9 |
+
gr_get_url_http_content,
|
10 |
+
gr_letter_counter,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
],
|
12 |
)
|
13 |
|
|
|
14 |
if __name__ == "__main__":
|
15 |
+
gr_app.launch(mcp_server=True)
|
pyproject.toml
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "tdagent"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "TDA Agent Tools implemented for huggingface hackathon."
|
5 |
+
authors = [
|
6 |
+
{ name = "Pedro Completo Bento", email = "[email protected]" },
|
7 |
+
{ name = "Josep Pon Farreny", email = "[email protected]" },
|
8 |
+
{ name = "Miguel Rodin Rodriguez", email = "[email protected]" },
|
9 |
+
{ name = "Sofia Jeronimo dos Santos", email = "[email protected]" },
|
10 |
+
{ name = "Rodrigo Dominguez Sanz", email = "[email protected]" },
|
11 |
+
]
|
12 |
+
requires-python = ">=3.10,<4"
|
13 |
+
readme = "README.md"
|
14 |
+
license = ""
|
15 |
+
dependencies = ["gradio[mcp]>=5.32.1", "requests>=2.32.3"]
|
16 |
+
|
17 |
+
[project.scripts]
|
18 |
+
|
19 |
+
|
20 |
+
[dependency-groups]
|
21 |
+
dev = ["mypy~=1.14", "ruff>=0.9,<1", "pre-commit~=3.4", "pip-audit>=2.9.0"]
|
22 |
+
test = [
|
23 |
+
"pytest>=7.4.4,<8",
|
24 |
+
"pytest-cov>=4.1.0,<5",
|
25 |
+
"pytest-randomly>=3.15.0,<4",
|
26 |
+
"xdoctest>=1.1.2,<2",
|
27 |
+
]
|
28 |
+
|
29 |
+
[build-system]
|
30 |
+
requires = ["hatchling"]
|
31 |
+
build-backend = "hatchling.build"
|
32 |
+
|
33 |
+
[tool.uv]
|
34 |
+
package = false
|
35 |
+
default-groups = ["dev", "test"]
|
36 |
+
|
37 |
+
[tool.uv.workspace]
|
38 |
+
members = ["test"]
|
39 |
+
|
40 |
+
[tool.black]
|
41 |
+
target-version = ["py39", "py310", "py311"]
|
42 |
+
line-length = 88
|
43 |
+
|
44 |
+
[tool.isort]
|
45 |
+
profile = "black"
|
46 |
+
lines_after_imports = 2
|
47 |
+
|
48 |
+
[tool.mypy]
|
49 |
+
cache_dir = ".cache/mypy/"
|
50 |
+
ignore_missing_imports = true
|
51 |
+
no_implicit_optional = true
|
52 |
+
check_untyped_defs = true
|
53 |
+
strict_equality = true
|
54 |
+
disallow_any_generics = true
|
55 |
+
disallow_subclassing_any = true
|
56 |
+
disallow_untyped_calls = true
|
57 |
+
disallow_untyped_defs = true
|
58 |
+
disallow_incomplete_defs = true
|
59 |
+
disallow_untyped_decorators = true
|
60 |
+
warn_redundant_casts = true
|
61 |
+
warn_unused_ignores = true
|
62 |
+
exclude = "docs/"
|
63 |
+
plugins = ["pydantic.mypy"] # ["numpy.typing.mypy_plugin"]
|
64 |
+
|
65 |
+
[[tool.mypy.overrides]]
|
66 |
+
module = "tests.*"
|
67 |
+
disallow_untyped_defs = false
|
68 |
+
disallow_incomplete_defs = false
|
69 |
+
|
70 |
+
[tool.pytest.ini_options]
|
71 |
+
cache_dir = ".cache"
|
72 |
+
testpaths = ["tests", "tda_agent"]
|
73 |
+
addopts = [
|
74 |
+
"--strict",
|
75 |
+
"-r sxX",
|
76 |
+
"--cov-report=html",
|
77 |
+
"--cov-report=term-missing:skip-covered",
|
78 |
+
"--no-cov-on-fail",
|
79 |
+
"--xdoc",
|
80 |
+
]
|
81 |
+
console_output_style = "count"
|
82 |
+
markers = ""
|
83 |
+
filterwarnings = ["ignore::DeprecationWarning"]
|
84 |
+
|
85 |
+
[tool.ruff]
|
86 |
+
cache-dir = ".cache/ruff"
|
87 |
+
exclude = [
|
88 |
+
".git",
|
89 |
+
"__pycache__",
|
90 |
+
"docs/source/conf.py",
|
91 |
+
"old",
|
92 |
+
"build",
|
93 |
+
"dist",
|
94 |
+
".venv",
|
95 |
+
"scripts",
|
96 |
+
]
|
97 |
+
line-length = 88
|
98 |
+
|
99 |
+
[tool.ruff.lint]
|
100 |
+
select = ["ALL"]
|
101 |
+
ignore = ["D100", "D104", "D107", "D401", "EM102", "ERA001", "TRY003"]
|
102 |
+
|
103 |
+
[tool.ruff.lint.flake8-quotes]
|
104 |
+
inline-quotes = "double"
|
105 |
+
|
106 |
+
[tool.ruff.lint.flake8-bugbear]
|
107 |
+
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
|
108 |
+
extend-immutable-calls = ["typer.Argument", "typer.Option"]
|
109 |
+
|
110 |
+
[tool.ruff.lint.pep8-naming]
|
111 |
+
ignore-names = ["F", "L"]
|
112 |
+
|
113 |
+
[tool.ruff.lint.isort]
|
114 |
+
lines-after-imports = 2
|
115 |
+
|
116 |
+
[tool.ruff.lint.mccabe]
|
117 |
+
max-complexity = 18
|
118 |
+
|
119 |
+
[tool.ruff.lint.pydocstyle]
|
120 |
+
convention = "google"
|
121 |
+
|
122 |
+
[tool.ruff.lint.per-file-ignores]
|
123 |
+
"*/__init__.py" = ["F401"]
|
124 |
+
"tdagent/cli/**/*.py" = ["D103", "T201"]
|
125 |
+
"tests/*.py" = ["D103", "PLR2004", "S101"]
|
requirements-dev.txt
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file was autogenerated by uv via the following command:
|
2 |
+
# uv export --format requirements-txt --no-hashes --group dev --group test -o requirements-dev.txt
|
3 |
+
aiofiles==24.1.0
|
4 |
+
annotated-types==0.7.0
|
5 |
+
anyio==4.9.0
|
6 |
+
audioop-lts==0.2.1 ; python_full_version >= '3.13'
|
7 |
+
boolean-py==5.0
|
8 |
+
cachecontrol==0.14.3
|
9 |
+
certifi==2025.4.26
|
10 |
+
cfgv==3.4.0
|
11 |
+
charset-normalizer==3.4.2
|
12 |
+
click==8.2.1 ; sys_platform != 'emscripten'
|
13 |
+
colorama==0.4.6 ; sys_platform == 'win32'
|
14 |
+
coverage==7.8.2
|
15 |
+
cyclonedx-python-lib==9.1.0
|
16 |
+
defusedxml==0.7.1
|
17 |
+
distlib==0.3.9
|
18 |
+
exceptiongroup==1.3.0 ; python_full_version < '3.11'
|
19 |
+
fastapi==0.115.12
|
20 |
+
ffmpy==0.6.0
|
21 |
+
filelock==3.18.0
|
22 |
+
fsspec==2025.5.1
|
23 |
+
gradio==5.32.1
|
24 |
+
gradio-client==1.10.2
|
25 |
+
groovy==0.1.2
|
26 |
+
h11==0.16.0
|
27 |
+
hf-xet==1.1.2 ; platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
|
28 |
+
httpcore==1.0.9
|
29 |
+
httpx==0.28.1
|
30 |
+
httpx-sse==0.4.0
|
31 |
+
huggingface-hub==0.32.4
|
32 |
+
identify==2.6.12
|
33 |
+
idna==3.10
|
34 |
+
iniconfig==2.1.0
|
35 |
+
jinja2==3.1.6
|
36 |
+
license-expression==30.4.1
|
37 |
+
markdown-it-py==3.0.0
|
38 |
+
markupsafe==3.0.2
|
39 |
+
mcp==1.9.0
|
40 |
+
mdurl==0.1.2
|
41 |
+
msgpack==1.1.0
|
42 |
+
mypy==1.16.0
|
43 |
+
mypy-extensions==1.1.0
|
44 |
+
nodeenv==1.9.1
|
45 |
+
numpy==2.2.6
|
46 |
+
orjson==3.10.18
|
47 |
+
packageurl-python==0.16.0
|
48 |
+
packaging==25.0
|
49 |
+
pandas==2.2.3
|
50 |
+
pathspec==0.12.1
|
51 |
+
pillow==11.2.1
|
52 |
+
pip==25.1.1
|
53 |
+
pip-api==0.0.34
|
54 |
+
pip-audit==2.9.0
|
55 |
+
pip-requirements-parser==32.0.1
|
56 |
+
platformdirs==4.3.8
|
57 |
+
pluggy==1.6.0
|
58 |
+
pre-commit==3.8.0
|
59 |
+
py-serializable==2.0.0
|
60 |
+
pydantic==2.11.5
|
61 |
+
pydantic-core==2.33.2
|
62 |
+
pydantic-settings==2.9.1
|
63 |
+
pydub==0.25.1
|
64 |
+
pygments==2.19.1
|
65 |
+
pyparsing==3.2.3
|
66 |
+
pytest==7.4.4
|
67 |
+
pytest-cov==4.1.0
|
68 |
+
pytest-randomly==3.16.0
|
69 |
+
python-dateutil==2.9.0.post0
|
70 |
+
python-dotenv==1.1.0
|
71 |
+
python-multipart==0.0.20
|
72 |
+
pytz==2025.2
|
73 |
+
pyyaml==6.0.2
|
74 |
+
requests==2.32.3
|
75 |
+
rich==14.0.0
|
76 |
+
ruff==0.11.12
|
77 |
+
safehttpx==0.1.6
|
78 |
+
semantic-version==2.10.0
|
79 |
+
shellingham==1.5.4 ; sys_platform != 'emscripten'
|
80 |
+
six==1.17.0
|
81 |
+
sniffio==1.3.1
|
82 |
+
sortedcontainers==2.4.0
|
83 |
+
sse-starlette==2.3.6
|
84 |
+
starlette==0.46.2
|
85 |
+
toml==0.10.2
|
86 |
+
tomli==2.2.1 ; python_full_version <= '3.11'
|
87 |
+
tomlkit==0.13.2
|
88 |
+
tqdm==4.67.1
|
89 |
+
typer==0.16.0 ; sys_platform != 'emscripten'
|
90 |
+
typing-extensions==4.14.0
|
91 |
+
typing-inspection==0.4.1
|
92 |
+
tzdata==2025.2
|
93 |
+
urllib3==2.4.0
|
94 |
+
uvicorn==0.34.3 ; sys_platform != 'emscripten'
|
95 |
+
virtualenv==20.31.2
|
96 |
+
websockets==15.0.1
|
97 |
+
xdoctest==1.2.0
|
requirements.txt
CHANGED
@@ -1 +1,72 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file was autogenerated by uv via the following command:
|
2 |
+
# uv export --format requirements-txt --no-hashes --no-dev -o requirements.txt
|
3 |
+
aiofiles==24.1.0
|
4 |
+
annotated-types==0.7.0
|
5 |
+
anyio==4.9.0
|
6 |
+
audioop-lts==0.2.1 ; python_full_version >= '3.13'
|
7 |
+
certifi==2025.4.26
|
8 |
+
charset-normalizer==3.4.2
|
9 |
+
click==8.2.1 ; sys_platform != 'emscripten'
|
10 |
+
colorama==0.4.6 ; sys_platform == 'win32'
|
11 |
+
coverage==7.8.2
|
12 |
+
exceptiongroup==1.3.0 ; python_full_version < '3.11'
|
13 |
+
fastapi==0.115.12
|
14 |
+
ffmpy==0.6.0
|
15 |
+
filelock==3.18.0
|
16 |
+
fsspec==2025.5.1
|
17 |
+
gradio==5.32.1
|
18 |
+
gradio-client==1.10.2
|
19 |
+
groovy==0.1.2
|
20 |
+
h11==0.16.0
|
21 |
+
hf-xet==1.1.2 ; platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
|
22 |
+
httpcore==1.0.9
|
23 |
+
httpx==0.28.1
|
24 |
+
httpx-sse==0.4.0
|
25 |
+
huggingface-hub==0.32.4
|
26 |
+
idna==3.10
|
27 |
+
iniconfig==2.1.0
|
28 |
+
jinja2==3.1.6
|
29 |
+
markdown-it-py==3.0.0 ; sys_platform != 'emscripten'
|
30 |
+
markupsafe==3.0.2
|
31 |
+
mcp==1.9.0
|
32 |
+
mdurl==0.1.2 ; sys_platform != 'emscripten'
|
33 |
+
numpy==2.2.6
|
34 |
+
orjson==3.10.18
|
35 |
+
packaging==25.0
|
36 |
+
pandas==2.2.3
|
37 |
+
pillow==11.2.1
|
38 |
+
pluggy==1.6.0
|
39 |
+
pydantic==2.11.5
|
40 |
+
pydantic-core==2.33.2
|
41 |
+
pydantic-settings==2.9.1
|
42 |
+
pydub==0.25.1
|
43 |
+
pygments==2.19.1 ; sys_platform != 'emscripten'
|
44 |
+
pytest==7.4.4
|
45 |
+
pytest-cov==4.1.0
|
46 |
+
pytest-randomly==3.16.0
|
47 |
+
python-dateutil==2.9.0.post0
|
48 |
+
python-dotenv==1.1.0
|
49 |
+
python-multipart==0.0.20
|
50 |
+
pytz==2025.2
|
51 |
+
pyyaml==6.0.2
|
52 |
+
requests==2.32.3
|
53 |
+
rich==14.0.0 ; sys_platform != 'emscripten'
|
54 |
+
ruff==0.11.12 ; sys_platform != 'emscripten'
|
55 |
+
safehttpx==0.1.6
|
56 |
+
semantic-version==2.10.0
|
57 |
+
shellingham==1.5.4 ; sys_platform != 'emscripten'
|
58 |
+
six==1.17.0
|
59 |
+
sniffio==1.3.1
|
60 |
+
sse-starlette==2.3.6
|
61 |
+
starlette==0.46.2
|
62 |
+
tomli==2.2.1 ; python_full_version <= '3.11'
|
63 |
+
tomlkit==0.13.2
|
64 |
+
tqdm==4.67.1
|
65 |
+
typer==0.16.0 ; sys_platform != 'emscripten'
|
66 |
+
typing-extensions==4.14.0
|
67 |
+
typing-inspection==0.4.1
|
68 |
+
tzdata==2025.2
|
69 |
+
urllib3==2.4.0
|
70 |
+
uvicorn==0.34.3 ; sys_platform != 'emscripten'
|
71 |
+
websockets==15.0.1
|
72 |
+
xdoctest==1.2.0
|
tdagent/__init__.py
ADDED
File without changes
|
tdagent/tools/__init__.py
ADDED
File without changes
|
tdagent/tools/get_url_content.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import enum
|
2 |
+
from collections.abc import Sequence
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import requests
|
6 |
+
|
7 |
+
|
8 |
+
class HttpContentType(str, enum.Enum):
|
9 |
+
"""Http content type values."""
|
10 |
+
|
11 |
+
HTML = "text/html"
|
12 |
+
JSON = "application/json"
|
13 |
+
|
14 |
+
|
15 |
+
def get_url_http_content(
|
16 |
+
url: str,
|
17 |
+
content_type: Sequence[HttpContentType] | None = None,
|
18 |
+
timeout: int = 30,
|
19 |
+
) -> tuple[str, str]:
|
20 |
+
"""Get the content of a URL using an HTTP GET request.
|
21 |
+
|
22 |
+
Args:
|
23 |
+
url: The URL to fetch the content from.
|
24 |
+
content_type: If given it should contain the expected
|
25 |
+
content types in the response body. The server may
|
26 |
+
not honor the requested content types.
|
27 |
+
timeout: Request timeout in seconds. Defaults to 30.
|
28 |
+
|
29 |
+
Returns:
|
30 |
+
A pair of strings (content, error_message). If there is an
|
31 |
+
error getting content from the URL the `content` will be
|
32 |
+
empty and `error_message` will, usually, contain the error
|
33 |
+
cause. Otherwise, `error_message` will be empty and the
|
34 |
+
content will be filled with data fetched from the URL.
|
35 |
+
"""
|
36 |
+
headers = {}
|
37 |
+
|
38 |
+
if content_type:
|
39 |
+
headers["Accept"] = ",".join(content_type)
|
40 |
+
response = requests.get(
|
41 |
+
url,
|
42 |
+
headers=headers,
|
43 |
+
timeout=timeout,
|
44 |
+
)
|
45 |
+
|
46 |
+
try:
|
47 |
+
response.raise_for_status()
|
48 |
+
except requests.HTTPError as err:
|
49 |
+
return "", str(err)
|
50 |
+
|
51 |
+
return response.text, ""
|
52 |
+
|
53 |
+
|
54 |
+
gr_get_url_http_content = gr.Interface(
|
55 |
+
fn=get_url_http_content,
|
56 |
+
inputs=["text", "text"],
|
57 |
+
outputs="text",
|
58 |
+
title="Get the content of a URL using an HTTP GET request.",
|
59 |
+
description=(
|
60 |
+
"Get the content of a URL in one of the specified content types."
|
61 |
+
" The server may not honor the content type and if it fails the"
|
62 |
+
" reason should also be returned with the corresponding HTTP"
|
63 |
+
" error code."
|
64 |
+
),
|
65 |
+
)
|
tdagent/tools/letter_counter.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def letter_counter(word: str, letter: str) -> int:
|
5 |
+
"""Count the occurrences of a specific letter in a word.
|
6 |
+
|
7 |
+
Args:
|
8 |
+
word: The word or phrase to analyze
|
9 |
+
letter: The letter to count occurrences of
|
10 |
+
|
11 |
+
Returns:
|
12 |
+
The number of times the letter appears in the word
|
13 |
+
"""
|
14 |
+
return word.lower().count(letter.lower())
|
15 |
+
|
16 |
+
|
17 |
+
gr_letter_counter = gr.Interface(
|
18 |
+
fn=letter_counter,
|
19 |
+
inputs=["text", "text"],
|
20 |
+
outputs="number",
|
21 |
+
title="Letter Counter",
|
22 |
+
description="Count how many times a letter appears in a word",
|
23 |
+
)
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|