veris-ai 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of veris-ai might be problematic. Click here for more details.
- veris_ai/__init__.py +7 -0
- veris_ai/tool_mock.py +128 -0
- veris_ai-0.1.0.dist-info/METADATA +139 -0
- veris_ai-0.1.0.dist-info/RECORD +6 -0
- veris_ai-0.1.0.dist-info/WHEEL +4 -0
- veris_ai-0.1.0.dist-info/licenses/LICENSE +21 -0
veris_ai/__init__.py
ADDED
veris_ai/tool_mock.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import json
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from functools import wraps
|
|
7
|
+
from typing import Any, Union, get_type_hints
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
class ToolMock:
|
|
14
|
+
"""Class for mocking tool calls."""
|
|
15
|
+
def __init__(self):
|
|
16
|
+
self.endpoint = os.getenv("VERIS_MOCK_ENDPOINT_URL")
|
|
17
|
+
if not self.endpoint:
|
|
18
|
+
raise ValueError("VERIS_MOCK_ENDPOINT_URL environment variable is not set")
|
|
19
|
+
# Default timeout of 30 seconds
|
|
20
|
+
self.timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "30.0"))
|
|
21
|
+
|
|
22
|
+
def _convert_to_type(self, value: Any, target_type: type) -> Any: # type: ignore
|
|
23
|
+
"""Convert a value to the specified type."""
|
|
24
|
+
if target_type == Any:
|
|
25
|
+
return value
|
|
26
|
+
|
|
27
|
+
# Handle basic types
|
|
28
|
+
if target_type in (str, int, float, bool):
|
|
29
|
+
return target_type(value)
|
|
30
|
+
|
|
31
|
+
# Handle List types
|
|
32
|
+
if hasattr(target_type, "__origin__") and target_type.__origin__ == list:
|
|
33
|
+
if not isinstance(value, list):
|
|
34
|
+
raise ValueError(f"Expected list but got {type(value)}")
|
|
35
|
+
item_type = target_type.__args__[0]
|
|
36
|
+
return [self._convert_to_type(item, item_type) for item in value]
|
|
37
|
+
|
|
38
|
+
# Handle Dict types
|
|
39
|
+
if hasattr(target_type, "__origin__") and target_type.__origin__ == dict:
|
|
40
|
+
if not isinstance(value, dict):
|
|
41
|
+
raise ValueError(f"Expected dict but got {type(value)}")
|
|
42
|
+
key_type, value_type = target_type.__args__
|
|
43
|
+
return {self._convert_to_type(k, key_type): self._convert_to_type(v, value_type)
|
|
44
|
+
for k, v in value.items()}
|
|
45
|
+
|
|
46
|
+
# Handle Union types
|
|
47
|
+
if hasattr(target_type, "__origin__") and target_type.__origin__ == Union:
|
|
48
|
+
for possible_type in target_type.__args__:
|
|
49
|
+
try:
|
|
50
|
+
return self._convert_to_type(value, possible_type)
|
|
51
|
+
except (ValueError, TypeError):
|
|
52
|
+
continue
|
|
53
|
+
raise ValueError(f"Could not convert {value} to any of the union types {target_type.__args__}") # noqa
|
|
54
|
+
|
|
55
|
+
# For other types, try direct conversion
|
|
56
|
+
return target_type(value)
|
|
57
|
+
|
|
58
|
+
def mock(self, func: Callable) -> Callable:
|
|
59
|
+
"""Decorator for mocking tool calls."""
|
|
60
|
+
@wraps(func)
|
|
61
|
+
async def wrapper(*args, **kwargs):
|
|
62
|
+
# Check if we're in simulation mode
|
|
63
|
+
env_mode = os.getenv("ENV", "").lower()
|
|
64
|
+
if env_mode != "simulation":
|
|
65
|
+
# If not in simulation mode, execute the original function
|
|
66
|
+
return await func(*args, **kwargs)
|
|
67
|
+
|
|
68
|
+
logger.info(f"Simulating function: {func.__name__}")
|
|
69
|
+
sig = inspect.signature(func)
|
|
70
|
+
type_hints = get_type_hints(func)
|
|
71
|
+
|
|
72
|
+
# Extract return type object (not just the name)
|
|
73
|
+
return_type_obj = type_hints.pop("return", Any)
|
|
74
|
+
|
|
75
|
+
# Create parameter info
|
|
76
|
+
params_info = {}
|
|
77
|
+
bound_args = sig.bind(*args, **kwargs)
|
|
78
|
+
bound_args.apply_defaults()
|
|
79
|
+
|
|
80
|
+
for param_name, param_value in bound_args.arguments.items():
|
|
81
|
+
params_info[param_name] = {
|
|
82
|
+
"value": param_value,
|
|
83
|
+
"type": type_hints.get(param_name, Any).__name__,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Get function docstring
|
|
87
|
+
docstring = inspect.getdoc(func) or ""
|
|
88
|
+
|
|
89
|
+
ctx = bound_args.arguments.pop('ctx', None)
|
|
90
|
+
session_id = None
|
|
91
|
+
if ctx:
|
|
92
|
+
try:
|
|
93
|
+
session_id = ctx.request_context.lifespan_context.session_id
|
|
94
|
+
except AttributeError:
|
|
95
|
+
logger.warning("Cannot get session_id from context.")
|
|
96
|
+
|
|
97
|
+
# Prepare payload
|
|
98
|
+
payload = {
|
|
99
|
+
"session_id": session_id,
|
|
100
|
+
"tool_call": {
|
|
101
|
+
'function_name': func.__name__,
|
|
102
|
+
'parameters': params_info,
|
|
103
|
+
'return_type': return_type_obj.__name__,
|
|
104
|
+
'docstring': docstring,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# Send request to endpoint with timeout
|
|
109
|
+
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
|
110
|
+
response = await client.post(self.endpoint, json=payload)
|
|
111
|
+
response.raise_for_status()
|
|
112
|
+
mock_result = response.json()["result"]
|
|
113
|
+
logger.info(f"Mock response: {mock_result}")
|
|
114
|
+
|
|
115
|
+
# Parse the mock result if it's a string
|
|
116
|
+
if isinstance(mock_result, str):
|
|
117
|
+
try:
|
|
118
|
+
mock_result = json.loads(mock_result)
|
|
119
|
+
except json.JSONDecodeError:
|
|
120
|
+
# If it's not valid JSON, treat it as a raw string
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
# Convert the mock result to the expected return type
|
|
124
|
+
return self._convert_to_type(mock_result, return_type_obj)
|
|
125
|
+
|
|
126
|
+
return wrapper
|
|
127
|
+
|
|
128
|
+
veris = ToolMock()
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: veris-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for Veris AI tools
|
|
5
|
+
Project-URL: Homepage, https://github.com/veris-ai/veris-python-sdk
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/veris-ai/veris-python-sdk/issues
|
|
7
|
+
Author-email: Mehdi Jamei <mehdi@veris.ai>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: httpx>=0.24.0
|
|
12
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
13
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: black>=23.7.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: mypy>=1.5.1; extra == 'dev'
|
|
17
|
+
Requires-Dist: pre-commit>=3.3.3; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-asyncio>=0.21.1; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.11.4; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# Veris AI Python SDK
|
|
25
|
+
|
|
26
|
+
A Python package for Veris AI tools with simulation capabilities.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
You can install the package using `uv`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Install the package
|
|
34
|
+
uv add veris-ai
|
|
35
|
+
|
|
36
|
+
# Install with development dependencies
|
|
37
|
+
uv add "veris-ai[dev]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Environment Setup
|
|
41
|
+
|
|
42
|
+
The package requires the following environment variables:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Required: URL for the mock endpoint
|
|
46
|
+
VERIS_MOCK_ENDPOINT_URL=http://your-mock-endpoint.com
|
|
47
|
+
|
|
48
|
+
# Optional: Timeout in seconds (default: 30.0)
|
|
49
|
+
VERIS_MOCK_TIMEOUT=30.0
|
|
50
|
+
|
|
51
|
+
# Optional: Set to "simulation" to enable mock mode
|
|
52
|
+
ENV=simulation
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Python Version
|
|
56
|
+
|
|
57
|
+
This project requires Python 3.11 or higher. We use [pyenv](https://github.com/pyenv/pyenv) for Python version management.
|
|
58
|
+
|
|
59
|
+
To set up the correct Python version:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Install Python 3.11.0 using pyenv
|
|
63
|
+
pyenv install 3.11.0
|
|
64
|
+
|
|
65
|
+
# Set the local Python version for this project
|
|
66
|
+
pyenv local 3.11.0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from veris_ai import veris
|
|
73
|
+
|
|
74
|
+
@veris.mock()
|
|
75
|
+
async def your_function(param1: str, param2: int) -> dict:
|
|
76
|
+
"""
|
|
77
|
+
Your function documentation here.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
param1: Description of param1
|
|
81
|
+
param2: Description of param2
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
A dictionary containing the results
|
|
85
|
+
"""
|
|
86
|
+
# Your implementation here
|
|
87
|
+
return {"result": "actual implementation"}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
When `ENV=simulation` is set, the decorator will:
|
|
91
|
+
1. Capture the function signature, type hints, and docstring
|
|
92
|
+
2. Send this information to the mock endpoint
|
|
93
|
+
3. Convert the mock response to the expected return type
|
|
94
|
+
4. Return the mock result
|
|
95
|
+
|
|
96
|
+
When not in simulation mode, the original function will be executed normally.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
This project uses `pyproject.toml` for dependency management and `uv` for package installation.
|
|
101
|
+
|
|
102
|
+
### Development Dependencies
|
|
103
|
+
|
|
104
|
+
To install the package with development dependencies:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv add "veris-ai[dev]"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
This will install the following development tools:
|
|
111
|
+
- **Ruff**: Fast Python linter
|
|
112
|
+
- **pytest**: Testing framework
|
|
113
|
+
- **pytest-asyncio**: Async support for pytest
|
|
114
|
+
- **pytest-cov**: Coverage reporting for pytest
|
|
115
|
+
- **black**: Code formatter
|
|
116
|
+
- **mypy**: Static type checker
|
|
117
|
+
- **pre-commit**: Git hooks for code quality
|
|
118
|
+
|
|
119
|
+
### Code Quality
|
|
120
|
+
|
|
121
|
+
This project uses [Ruff](https://github.com/charliermarsh/ruff) for linting and code quality checks. Ruff is a fast Python linter written in Rust.
|
|
122
|
+
|
|
123
|
+
To run Ruff:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
ruff check .
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
To automatically fix issues:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
ruff check --fix .
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The Ruff configuration is defined in `pyproject.toml` under the `[tool.ruff]` section.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
veris_ai/__init__.py,sha256=7mEfVmqxQCn5FZN_1ua3iykCB1NUeJ4RfVXaAzdp4Hw,101
|
|
2
|
+
veris_ai/tool_mock.py,sha256=NTaBr8xkAp3tiB3naWCcm27KWO5JSzcr9BcurfhlCfs,5125
|
|
3
|
+
veris_ai-0.1.0.dist-info/METADATA,sha256=DzCmToKvOycKfE3ilpcEEl7mlz0a0w5yITXemoc4DWU,3495
|
|
4
|
+
veris_ai-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
veris_ai-0.1.0.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
|
|
6
|
+
veris_ai-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Veris AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|