veris-ai 0.1.1__py3-none-any.whl → 0.2.1__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/tool_mock.py +60 -47
- {veris_ai-0.1.1.dist-info → veris_ai-0.2.1.dist-info}/METADATA +1 -3
- veris_ai-0.2.1.dist-info/RECORD +6 -0
- veris_ai-0.1.1.dist-info/RECORD +0 -6
- {veris_ai-0.1.1.dist-info → veris_ai-0.2.1.dist-info}/WHEEL +0 -0
- {veris_ai-0.1.1.dist-info → veris_ai-0.2.1.dist-info}/licenses/LICENSE +0 -0
veris_ai/tool_mock.py
CHANGED
|
@@ -3,62 +3,77 @@ import json
|
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
5
|
from collections.abc import Callable
|
|
6
|
+
from contextlib import suppress
|
|
6
7
|
from functools import wraps
|
|
7
|
-
from typing import Any, Union, get_type_hints
|
|
8
|
+
from typing import Any, TypeVar, Union, get_args, get_origin, get_type_hints
|
|
8
9
|
|
|
9
10
|
import httpx
|
|
10
11
|
|
|
11
12
|
logger = logging.getLogger(__name__)
|
|
12
13
|
|
|
14
|
+
T = TypeVar("T")
|
|
15
|
+
|
|
16
|
+
|
|
13
17
|
class ToolMock:
|
|
14
18
|
"""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
19
|
|
|
22
|
-
def
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
"""Initialize the ToolMock class."""
|
|
22
|
+
|
|
23
|
+
def _convert_to_type(self, value: object, target_type: type) -> object:
|
|
23
24
|
"""Convert a value to the specified type."""
|
|
24
|
-
if target_type
|
|
25
|
+
if target_type is Any:
|
|
25
26
|
return value
|
|
26
|
-
|
|
27
|
-
# Handle basic types
|
|
27
|
+
|
|
28
28
|
if target_type in (str, int, float, bool):
|
|
29
29
|
return target_type(value)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if
|
|
30
|
+
|
|
31
|
+
origin = get_origin(target_type)
|
|
32
|
+
if origin is list:
|
|
33
33
|
if not isinstance(value, list):
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
error_msg = f"Expected list but got {type(value)}"
|
|
35
|
+
raise ValueError(error_msg)
|
|
36
|
+
item_type = get_args(target_type)[0]
|
|
36
37
|
return [self._convert_to_type(item, item_type) for item in value]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if hasattr(target_type, "__origin__") and target_type.__origin__ == dict:
|
|
38
|
+
|
|
39
|
+
if origin is dict:
|
|
40
40
|
if not isinstance(value, dict):
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
error_msg = f"Expected dict but got {type(value)}"
|
|
42
|
+
raise ValueError(error_msg)
|
|
43
|
+
key_type, value_type = get_args(target_type)
|
|
44
|
+
return {
|
|
45
|
+
self._convert_to_type(k, key_type): self._convert_to_type(v, value_type)
|
|
46
|
+
for k, v in value.items()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if origin is Union:
|
|
50
|
+
error_msg = (
|
|
51
|
+
f"Could not convert {value} to any of the union types {get_args(target_type)}"
|
|
52
|
+
)
|
|
53
|
+
for possible_type in get_args(target_type):
|
|
49
54
|
try:
|
|
50
55
|
return self._convert_to_type(value, possible_type)
|
|
51
56
|
except (ValueError, TypeError):
|
|
52
57
|
continue
|
|
53
|
-
raise ValueError(
|
|
54
|
-
|
|
58
|
+
raise ValueError(error_msg)
|
|
59
|
+
|
|
55
60
|
# For other types, try direct conversion
|
|
56
61
|
return target_type(value)
|
|
57
62
|
|
|
58
63
|
def mock(self, func: Callable) -> Callable:
|
|
59
64
|
"""Decorator for mocking tool calls."""
|
|
65
|
+
endpoint = os.getenv("VERIS_MOCK_ENDPOINT_URL")
|
|
66
|
+
if not endpoint:
|
|
67
|
+
error_msg = "VERIS_MOCK_ENDPOINT_URL environment variable is not set"
|
|
68
|
+
raise ValueError(error_msg)
|
|
69
|
+
# Default timeout of 30 seconds
|
|
70
|
+
timeout = float(os.getenv("VERIS_MOCK_TIMEOUT", "30.0"))
|
|
71
|
+
|
|
60
72
|
@wraps(func)
|
|
61
|
-
async def wrapper(
|
|
73
|
+
async def wrapper(
|
|
74
|
+
*args: tuple[object, ...],
|
|
75
|
+
**kwargs: dict[str, object],
|
|
76
|
+
) -> object:
|
|
62
77
|
# Check if we're in simulation mode
|
|
63
78
|
env_mode = os.getenv("ENV", "").lower()
|
|
64
79
|
if env_mode != "simulation":
|
|
@@ -68,16 +83,16 @@ class ToolMock:
|
|
|
68
83
|
logger.info(f"Simulating function: {func.__name__}")
|
|
69
84
|
sig = inspect.signature(func)
|
|
70
85
|
type_hints = get_type_hints(func)
|
|
71
|
-
|
|
86
|
+
|
|
72
87
|
# Extract return type object (not just the name)
|
|
73
88
|
return_type_obj = type_hints.pop("return", Any)
|
|
74
|
-
|
|
89
|
+
|
|
75
90
|
# Create parameter info
|
|
76
91
|
params_info = {}
|
|
77
92
|
bound_args = sig.bind(*args, **kwargs)
|
|
78
93
|
bound_args.apply_defaults()
|
|
79
|
-
|
|
80
|
-
ctx = bound_args.arguments.pop(
|
|
94
|
+
|
|
95
|
+
ctx = bound_args.arguments.pop("ctx", None)
|
|
81
96
|
session_id = None
|
|
82
97
|
if ctx:
|
|
83
98
|
try:
|
|
@@ -97,31 +112,29 @@ class ToolMock:
|
|
|
97
112
|
payload = {
|
|
98
113
|
"session_id": session_id,
|
|
99
114
|
"tool_call": {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
115
|
+
"function_name": func.__name__,
|
|
116
|
+
"parameters": params_info,
|
|
117
|
+
"return_type": return_type_obj.__name__,
|
|
118
|
+
"docstring": docstring,
|
|
119
|
+
},
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
# Send request to endpoint with timeout
|
|
108
|
-
async with httpx.AsyncClient(timeout=
|
|
109
|
-
response = await client.post(
|
|
123
|
+
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
124
|
+
response = await client.post(endpoint, json=payload)
|
|
110
125
|
response.raise_for_status()
|
|
111
126
|
mock_result = response.json()["result"]
|
|
112
127
|
logger.info(f"Mock response: {mock_result}")
|
|
113
|
-
|
|
128
|
+
|
|
114
129
|
# Parse the mock result if it's a string
|
|
115
130
|
if isinstance(mock_result, str):
|
|
116
|
-
|
|
131
|
+
with suppress(json.JSONDecodeError):
|
|
117
132
|
mock_result = json.loads(mock_result)
|
|
118
|
-
|
|
119
|
-
# If it's not valid JSON, treat it as a raw string
|
|
120
|
-
pass
|
|
121
|
-
|
|
133
|
+
|
|
122
134
|
# Convert the mock result to the expected return type
|
|
123
135
|
return self._convert_to_type(mock_result, return_type_obj)
|
|
124
136
|
|
|
125
137
|
return wrapper
|
|
126
138
|
|
|
139
|
+
|
|
127
140
|
veris = ToolMock()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: veris-ai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A Python package for Veris AI tools
|
|
5
5
|
Project-URL: Homepage, https://github.com/veris-ai/veris-python-sdk
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/veris-ai/veris-python-sdk/issues
|
|
@@ -9,8 +9,6 @@ License-Expression: MIT
|
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
Requires-Python: >=3.11
|
|
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
12
|
Provides-Extra: dev
|
|
15
13
|
Requires-Dist: black>=23.7.0; extra == 'dev'
|
|
16
14
|
Requires-Dist: mypy>=1.5.1; extra == 'dev'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
veris_ai/__init__.py,sha256=7mEfVmqxQCn5FZN_1ua3iykCB1NUeJ4RfVXaAzdp4Hw,101
|
|
2
|
+
veris_ai/tool_mock.py,sha256=jXFJLGuOlbis_gkTrZhAxqQdh9DDnS1Z-mWbFpCcvFM,5025
|
|
3
|
+
veris_ai-0.2.1.dist-info/METADATA,sha256=JYEuQcuWr_nBixZlWTsm7WV5hcM3cDSo3pFSED9DsBo,3419
|
|
4
|
+
veris_ai-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
veris_ai-0.2.1.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
|
|
6
|
+
veris_ai-0.2.1.dist-info/RECORD,,
|
veris_ai-0.1.1.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
veris_ai/__init__.py,sha256=7mEfVmqxQCn5FZN_1ua3iykCB1NUeJ4RfVXaAzdp4Hw,101
|
|
2
|
-
veris_ai/tool_mock.py,sha256=oakvTnzxJK2EURazn_ZHiO2XiwvLT87L7w1h-nTP9EU,5124
|
|
3
|
-
veris_ai-0.1.1.dist-info/METADATA,sha256=E4n72xdpcxN84J7LTk0QBpvGJWU_yoEQo_81s53HeCw,3495
|
|
4
|
-
veris_ai-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
-
veris_ai-0.1.1.dist-info/licenses/LICENSE,sha256=2g4i20atAgtD5einaKzhQrIB-JrPhyQgD3bC0wkHcCI,1065
|
|
6
|
-
veris_ai-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|