Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 867e357

Browse files
committed
v0.0.14
1 parent 38f5b75 commit 867e357

File tree

6 files changed

+94
-9
lines changed

6 files changed

+94
-9
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/),
66
and this project adheres to [SimpleTool](https://github.com/nchekwa/simpletool-python/tree/master).
77

8+
9+
# [0.0.14] - 2025-01-09 Milestone Alpha2
10+
11+
## Added
12+
- SimpleToolResponseModel
13+
- add correct handle __repr__ for SimpleTool child classes
14+
- add get_version for `setup.py` to automate version update
15+
- auto add annotation version in `__init__.py`
16+
817
# [0.0.13] - 2025-01-08 Milestone Alpha2
918

1019
## Fixed

setup.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
11
from setuptools import setup
2+
import re
3+
import os
4+
5+
6+
def get_version():
7+
# Read version from CHANGELOG.md
8+
with open('CHANGELOG.md', 'r', encoding='utf-8') as f:
9+
first_line = f.readline().strip()
10+
match = re.search(r'\[(\d+\.\d+\.\d+)\]', first_line)
11+
if match:
12+
version = match.group(1)
13+
14+
# Update version in __init__.py
15+
init_path = os.path.join('simpletool', '__init__.py')
16+
with open(init_path, 'r', encoding='utf-8') as init_file:
17+
init_content = init_file.read()
18+
19+
# Replace version in the header
20+
updated_init_content = re.sub(
21+
r'(version:)\s*',
22+
r'\1 ' + version,
23+
init_content
24+
)
25+
26+
with open(init_path, 'w', encoding='utf-8') as init_file:
27+
init_file.write(updated_init_content)
28+
29+
return version
30+
return '0.0.0' # fallback version if not found
31+
232

333
setup(name='simpletool',
4-
version='0.0.13',
34+
version=get_version(),
535
description='simpletool',
636
url='https://github.com/nchekwa/simpletool-python/tree/master',
737
author='Artur Zdolinski',

simpletool/__init__.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
This module contains the base class for all simple tools.
2+
name: SimpleTools
3+
author: Artur Zdolinski
4+
version:
35
"""
46
import asyncio
57
import os
@@ -14,7 +16,7 @@
1416
from pydantic import BaseModel, Field
1517
from pydantic.fields import FieldInfo
1618
from .types import Content, TextContent, ImageContent, FileContent, ResourceContent, BoolContent, ErrorContent
17-
from .models import SimpleInputModel
19+
from .models import SimpleInputModel, SimpleToolResponseModel
1820
from .schema import NoTitleDescriptionJsonSchema
1921
from .errors import SimpleToolError, ValidationError
2022

@@ -200,7 +202,16 @@ def __str__(self) -> str:
200202
}).encode("utf-8").decode("unicode_escape")
201203

202204
def __repr__(self):
203-
return f"SimpleTool(name='{self.name}', description={self.description})"
205+
# Create a SimpleToolResponseModel internally
206+
response_model = SimpleToolResponseModel(
207+
name=self.name,
208+
description=self.description,
209+
input_schema=self.input_schema
210+
)
211+
# Get the original repr
212+
original_repr = repr(response_model)
213+
# Replace with the actual child class name
214+
return original_repr.replace("SimpleToolResponseModel", self.__class__.__name__)
204215

205216
@validate_tool_output
206217
@set_timeout(DEFAULT_TIMEOUT)

simpletool/models.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""" Type definitions for the simpletool package."""
2-
from typing import Union, Type
3-
from pydantic import BaseModel, model_validator
2+
from typing import Union, Type, Optional
3+
from pydantic import BaseModel, model_validator, Field
44

55

66
class SimpleInputModel(BaseModel):
@@ -29,3 +29,35 @@ class SimpleToolModel(BaseModel):
2929
name: str
3030
description: Union[str, None] = None
3131
input_model: Type[SimpleInputModel]
32+
33+
34+
class SimpleToolResponseModel(BaseModel):
35+
"""
36+
Response model for the tools endpoint.
37+
38+
Attributes:
39+
name (str): The name of the tool.
40+
description (str): A description of the tool's functionality.
41+
input_schema (Optional[dict]): The input schema for the tool, if available.
42+
"""
43+
name: str = Field(..., description="Name of the tool")
44+
description: str = Field(..., description="Description of the tool's functionality")
45+
input_schema: Optional[dict] = Field(None, description="Input schema for the tool, if available")
46+
47+
# def __repr__(self):
48+
# return f"SimpleTool(name='{self.name}', description='{self.description}', input_schema={self.input_schema})"
49+
50+
class Config:
51+
"""Pydantic model configuration."""
52+
schema_extra = {
53+
"example": {
54+
"name": "example_tool",
55+
"description": "An example tool for demonstration",
56+
"input_schema": {
57+
"type": "object",
58+
"properties": {
59+
"input": {"type": "string"}
60+
}
61+
}
62+
}
63+
}

tests/test_simpletool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_simpletool_repr():
140140
tool = TestSimpleTool()
141141
repr_str = repr(tool)
142142

143-
assert repr_str == "SimpleTool(name='TestTool', description=A tool for testing)"
143+
assert repr_str == "TestSimpleTool(name='TestTool', description='A tool for testing', input_schema={'properties': {'test_field': {'type': 'string'}}, 'required': ['test_field'], 'type': 'object'})"
144144

145145

146146
def test_simpletool_async_context_manager():

tool_example.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ async def main(t: str):
3939
print(f"Type: {type(str(my_tool))}")
4040
print(str(my_tool))
4141

42-
print("\nTool Details - my_tool.info:")
42+
print("\nTool Details Print - my_tool.info:")
4343
print(f"Type: {type(my_tool.info)}")
4444
print(my_tool.info)
4545

46-
print("\nDictionary Representation - my_tool.to_dict:")
46+
print("\nDictionary - my_tool.to_dict:")
4747
print(f"Type: {type(my_tool.to_dict)}")
4848
print(my_tool.to_dict)
4949

50+
print("\nRepresentation - my_tool.__repr__():")
51+
print(f"Type: {type(repr(my_tool))}")
52+
print(repr(my_tool))
5053

5154
print("----------------------------------------------------------------------")
5255
# Demonstrate in/out - model/schema

0 commit comments

Comments
 (0)