maitai-python 1.0.40b0__tar.gz → 1.0.41__tar.gz

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.
Files changed (47) hide show
  1. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/PKG-INFO +1 -1
  2. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_inference.py +4 -5
  3. maitai_python-1.0.41/maitai/tools/__init__.py +84 -0
  4. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/version.py +1 -1
  5. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/chat/__init__.py +3 -0
  6. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_python.egg-info/PKG-INFO +1 -1
  7. maitai_python-1.0.40b0/maitai/tools/__init__.py +0 -69
  8. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/README.md +0 -0
  9. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/__init__.py +0 -0
  10. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_azure.py +0 -0
  11. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_config.py +0 -0
  12. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_config_listener_thread.py +0 -0
  13. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_context.py +0 -0
  14. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_evaluator.py +0 -0
  15. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_maitai.py +0 -0
  16. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_maitai_async.py +0 -0
  17. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_maitai_client.py +0 -0
  18. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_types.py +0 -0
  19. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai/_utils.py +0 -0
  20. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/__init__.py +0 -0
  21. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/config/__init__.py +0 -0
  22. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/config/config_service.py +0 -0
  23. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/processes/__init__.py +0 -0
  24. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/processes/io_thread.py +0 -0
  25. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/processes/websocket_listener_thread.py +0 -0
  26. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/utils/__init__.py +0 -0
  27. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/utils/proto_utils.py +0 -0
  28. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_common/utils/types.py +0 -0
  29. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/__init__.py +0 -0
  30. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/application/__init__.py +0 -0
  31. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/company/__init__.py +0 -0
  32. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/config/__init__.py +0 -0
  33. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/embedding/__init__.py +0 -0
  34. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/event/__init__.py +0 -0
  35. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/inference/__init__.py +0 -0
  36. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/key/__init__.py +0 -0
  37. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/model/__init__.py +0 -0
  38. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/notification/__init__.py +0 -0
  39. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/sandbox/__init__.py +0 -0
  40. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/sentinel/__init__.py +0 -0
  41. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_gen/session/__init__.py +0 -0
  42. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_python.egg-info/SOURCES.txt +0 -0
  43. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_python.egg-info/dependency_links.txt +0 -0
  44. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_python.egg-info/requires.txt +0 -0
  45. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/maitai_python.egg-info/top_level.txt +0 -0
  46. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/setup.cfg +0 -0
  47. {maitai_python-1.0.40b0 → maitai_python-1.0.41}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maitai-python
3
- Version: 1.0.40b0
3
+ Version: 1.0.41
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai
@@ -70,8 +70,7 @@ class Inference(MaitaiClient):
70
70
  }
71
71
  response = requests.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE), stream=True)
72
72
  if response.status_code != 200:
73
- print(f"Failed to send inference request. Status code: {response.status_code}. Error: {response.text}")
74
- return
73
+ raise InferenceException(f"Failed to send inference request. Status code: {response.status_code}. Error: {response.text}")
75
74
  try:
76
75
  for line in response.iter_lines():
77
76
  if line:
@@ -96,11 +95,11 @@ class Inference(MaitaiClient):
96
95
  async with session.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE)) as response:
97
96
  if response.status != 200:
98
97
  error_text = await response.text()
99
- print(f"Failed to send inference request. Status code: {response.status}. Error: {error_text}")
98
+ exception = InferenceException(f"Failed to send inference request. Status code: {response.status}. Error: {error_text}")
100
99
  if chunk_queue:
101
- chunk_queue.put(StopIteration())
100
+ chunk_queue.put(exception)
102
101
  if async_chunk_queue:
103
- await async_chunk_queue.put(StopIteration())
102
+ await async_chunk_queue.put(exception)
104
103
  return
105
104
  async for line in response.content:
106
105
  if line:
@@ -0,0 +1,84 @@
1
+ import inspect
2
+ import re
3
+ from typing import get_type_hints
4
+
5
+ from maitai_gen.chat import Function, Tool
6
+
7
+
8
+ def tool(func):
9
+ function_description = func.__doc__
10
+ if not function_description:
11
+ raise ValueError("Missing docstring for tool")
12
+
13
+ def wrapper(*args, **kwargs):
14
+ return func(*args, **kwargs)
15
+
16
+ sig = inspect.signature(func)
17
+ params = sig.parameters
18
+
19
+ properties = {}
20
+ required = []
21
+ type_hints = get_type_hints(func)
22
+
23
+ param_descriptions = _extract_param_details(func.__doc__)
24
+ for param_name, param in params.items():
25
+ if param_name in type_hints:
26
+ param_type = type_hints[param_name].__name__
27
+ elif param.default is not param.empty and param.default is not None:
28
+ param_type = type(param.default).__name__
29
+ else:
30
+ param_type = "string"
31
+ properties[param_name] = {
32
+ "type": _parse_type(param_type),
33
+ "description": param_descriptions.get(param_name, ""),
34
+ }
35
+ if param.default is param.empty:
36
+ required.append(param_name)
37
+
38
+ wrapper.__tool__ = Tool(
39
+ type="function",
40
+ function=Function(
41
+ name=func.__name__,
42
+ description=function_description,
43
+ parameters={
44
+ "type": "object",
45
+ "properties": properties,
46
+ "required": required,
47
+ },
48
+ )
49
+ )
50
+ return wrapper
51
+
52
+
53
+ def _extract_param_details(docstring):
54
+ param_descriptions = {}
55
+ param_pattern = re.compile(r":param (\w+): (.+)")
56
+ args_pattern = re.compile(r"Args:\s*(.*?)(?=\n\S|$)", re.DOTALL)
57
+ arg_param_pattern = re.compile(r"(\w+): (.+)")
58
+
59
+ args_match = args_pattern.search(docstring)
60
+ if args_match:
61
+ args_section = args_match.group(1)
62
+ arg_lines = args_section.split("\n")
63
+ for line in arg_lines:
64
+ if line.strip():
65
+ param_match = arg_param_pattern.match(line.strip())
66
+ if param_match:
67
+ param_name, param_description = param_match.groups()
68
+ param_descriptions[param_name] = param_description.strip()
69
+ param_matches = param_pattern.findall(docstring)
70
+ for param, description in param_matches:
71
+ param_descriptions[param] = description.strip()
72
+ return param_descriptions
73
+
74
+
75
+ def _parse_type(type_string):
76
+ if type_string == "str" or type_string == "string":
77
+ return "string"
78
+ if type_string == "int" or type_string == "integer":
79
+ return "integer"
80
+ if type_string == "bool" or type_string == "boolean":
81
+ return "boolean"
82
+ if type_string == "float" or type_string == "number":
83
+ return "number"
84
+ return "string"
@@ -1,3 +1,3 @@
1
- version = "1.0.40b0"
1
+ version = "1.0.41"
2
2
  if __name__ == "__main__":
3
3
  print(version)
@@ -185,6 +185,9 @@ class ChatMessage(betterproto.Message):
185
185
  )
186
186
  name: Optional[str] = betterproto.string_field(3, optional=True, group="_name")
187
187
  tool_calls: List["ToolCall"] = betterproto.message_field(4)
188
+ tool_call_id: Optional[str] = betterproto.string_field(
189
+ 5, optional=True, group="_tool_call_id"
190
+ )
188
191
 
189
192
 
190
193
  @dataclass(eq=False, repr=False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maitai-python
3
- Version: 1.0.40b0
3
+ Version: 1.0.41
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai
@@ -1,69 +0,0 @@
1
- import inspect
2
- import re
3
- from typing import get_type_hints
4
-
5
- from maitai_gen.chat import Function, Tool
6
-
7
-
8
- def tool(func):
9
- function_description = _extract_function_description(func.__doc__)
10
- if not function_description:
11
- raise ValueError("Missing docstring for tool")
12
-
13
- def wrapper(*args, **kwargs):
14
- return func(*args, **kwargs)
15
-
16
- sig = inspect.signature(func)
17
- params = sig.parameters
18
-
19
- properties = {}
20
- required = []
21
- type_hints = get_type_hints(func)
22
-
23
- descriptions = _extract_param_descriptions(func.__doc__)
24
- for param_name, param in params.items():
25
- if param_name in type_hints:
26
- param_type = type_hints[param_name].__name__
27
- elif param.default is not param.empty and param.default is not None:
28
- param_type = type(param.default).__name__
29
- else:
30
- param_type = "string"
31
- properties[param_name] = {"type": param_type}
32
- if param_name in descriptions:
33
- properties[param_name]["description"] = descriptions[param_name]
34
- if param.default is param.empty:
35
- required.append(param_name)
36
-
37
- wrapper.__tool__ = Tool(
38
- type="function",
39
- function=Function(
40
- name=func.__name__,
41
- description=function_description,
42
- parameters={
43
- "type": "object",
44
- "properties": properties,
45
- "required": required,
46
- },
47
- )
48
- )
49
- return wrapper
50
-
51
-
52
- def _extract_function_description(docstring):
53
- lines = docstring.split("\n")
54
- description = []
55
- for line in lines:
56
- if not line.strip().startswith(":"):
57
- description.append(line.strip())
58
- else:
59
- break
60
- return " ".join(description).strip()
61
-
62
-
63
- def _extract_param_descriptions(docstring):
64
- param_descriptions = {}
65
- param_pattern = re.compile(r":param (\w+): (.+)")
66
- matches = param_pattern.findall(docstring)
67
- for param, description in matches:
68
- param_descriptions[param] = description.strip()
69
- return param_descriptions