maitai-python 1.0.39__tar.gz → 1.0.40b0__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.
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/PKG-INFO +1 -1
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_maitai.py +2 -2
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_maitai_async.py +2 -3
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_types.py +13 -3
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_utils.py +7 -1
- maitai_python-1.0.40b0/maitai/tools/__init__.py +69 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/version.py +1 -1
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_python.egg-info/SOURCES.txt +1 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/setup.py +1 -1
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/README.md +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_azure.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_config.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_context.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_evaluator.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_inference.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/chat/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.39 → maitai_python-1.0.40b0}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ import maitai
|
|
|
12
12
|
from maitai._config import config
|
|
13
13
|
from maitai._evaluator import Evaluator
|
|
14
14
|
from maitai._inference import InferenceException, InferenceWarning
|
|
15
|
-
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
|
|
15
|
+
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query, ToolFunction
|
|
16
16
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
17
17
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
18
18
|
from maitai_common.utils.types import EvaluateCallback
|
|
@@ -134,7 +134,7 @@ class Completions:
|
|
|
134
134
|
stream_options: Union[Optional[openai_chat_types.ChatCompletionStreamOptionsParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
135
135
|
temperature: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
136
136
|
tool_choice: Union[openai_chat_types.ChatCompletionToolChoiceOptionParam, openai.NotGiven] = openai.NOT_GIVEN,
|
|
137
|
-
tools: Union[Iterable[openai_chat_types.ChatCompletionToolParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
137
|
+
tools: Union[Iterable[Union[openai_chat_types.ChatCompletionToolParam, ToolFunction]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
138
138
|
top_logprobs: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
139
139
|
top_p: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
140
140
|
user: Union[str, openai.NotGiven] = openai.NOT_GIVEN,
|
|
@@ -11,7 +11,7 @@ import maitai
|
|
|
11
11
|
from maitai._config import config
|
|
12
12
|
from maitai._evaluator import Evaluator
|
|
13
13
|
from maitai._inference import InferenceException, InferenceWarning
|
|
14
|
-
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
|
|
14
|
+
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query, ToolFunction
|
|
15
15
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
16
16
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
17
17
|
from maitai_common.utils.types import EvaluateCallback
|
|
@@ -132,8 +132,7 @@ class AsyncCompletions:
|
|
|
132
132
|
stream_options: Union[Optional[openai_chat_types.ChatCompletionStreamOptionsParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
133
133
|
temperature: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
134
134
|
tool_choice: Union[openai_chat_types.ChatCompletionToolChoiceOptionParam, openai.NotGiven] = openai.NOT_GIVEN,
|
|
135
|
-
tools: Union[Iterable[openai_chat_types.ChatCompletionToolParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
136
|
-
top_logprobs: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
135
|
+
tools: Union[Iterable[Union[openai_chat_types.ChatCompletionToolParam, ToolFunction]], openai.NotGiven] = openai.NOT_GIVEN, top_logprobs: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
137
136
|
top_p: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
138
137
|
user: Union[str, openai.NotGiven] = openai.NOT_GIVEN,
|
|
139
138
|
extra_headers: Optional[Headers] = None,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from datetime import datetime
|
|
3
|
-
from typing import Mapping, Union
|
|
3
|
+
from typing import Any, Mapping, Protocol, Union
|
|
4
4
|
|
|
5
5
|
import openai.types.chat as openai_chat_types
|
|
6
6
|
from betterproto import Casing
|
|
7
|
-
from typing_extensions import Literal
|
|
7
|
+
from typing_extensions import Literal, runtime_checkable
|
|
8
8
|
|
|
9
|
-
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionRequest, ChatCompletionResponse, EvaluateRequest, EvaluateResponse
|
|
9
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionRequest, ChatCompletionResponse, EvaluateRequest, EvaluateResponse, Tool
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Omit:
|
|
@@ -81,3 +81,13 @@ class MaitaiCompletion(ChatCompletionResponse):
|
|
|
81
81
|
if not tool_call.get("index"):
|
|
82
82
|
tool_call["index"] = j
|
|
83
83
|
return openai_chat_types.ChatCompletion(**data).model_dump_json()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@runtime_checkable
|
|
87
|
+
class ToolFunction(Protocol):
|
|
88
|
+
__name__: str
|
|
89
|
+
__doc__: str
|
|
90
|
+
__tool__: Tool
|
|
91
|
+
|
|
92
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
|
93
|
+
...
|
|
@@ -9,6 +9,7 @@ from betterproto import Casing
|
|
|
9
9
|
from openai.types import ChatModel
|
|
10
10
|
|
|
11
11
|
import maitai_gen.chat as chat_types
|
|
12
|
+
from maitai._types import ToolFunction
|
|
12
13
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
13
14
|
from maitai_common.version import version
|
|
14
15
|
|
|
@@ -115,7 +116,7 @@ def get_chat_completion_params(*,
|
|
|
115
116
|
stream_options: Union[Optional[openai_types.ChatCompletionStreamOptionsParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
116
117
|
temperature: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
117
118
|
tool_choice: Union[openai_types.ChatCompletionToolChoiceOptionParam, openai.NotGiven] = openai.NOT_GIVEN,
|
|
118
|
-
tools: Union[Iterable[openai_types.ChatCompletionToolParam], openai.NotGiven] = openai.NOT_GIVEN,
|
|
119
|
+
tools: Union[Iterable[Union[openai_types.ChatCompletionToolParam, ToolFunction]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
119
120
|
top_logprobs: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
120
121
|
top_p: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
121
122
|
user: Union[str, openai.NotGiven] = openai.NOT_GIVEN,
|
|
@@ -155,6 +156,11 @@ def get_chat_completion_params(*,
|
|
|
155
156
|
if tools != openai.NOT_GIVEN:
|
|
156
157
|
params.tools = []
|
|
157
158
|
for tool in tools:
|
|
159
|
+
if isinstance(tool, Callable) and not isinstance(tool, ToolFunction):
|
|
160
|
+
raise TypeError(f"Method passed into tools missing @tool decorator")
|
|
161
|
+
if isinstance(tool, ToolFunction):
|
|
162
|
+
params.tools.append(tool.__tool__)
|
|
163
|
+
continue
|
|
158
164
|
function = tool.get("function")
|
|
159
165
|
params.tools.append(
|
|
160
166
|
chat_types.Tool(
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
|
@@ -7,7 +7,7 @@ from maitai_common.version import version
|
|
|
7
7
|
setup(
|
|
8
8
|
name='maitai-python',
|
|
9
9
|
version=version,
|
|
10
|
-
packages=find_packages(exclude=("maitai_back", "maitai_back.*")),
|
|
10
|
+
packages=find_packages(exclude=("maitai_back", "maitai_back.*"), include=("maitai.*", "maitai", "maitai_common", "maitai_common.*", "maitai_gen", "maitai_gen.*")),
|
|
11
11
|
install_requires=[
|
|
12
12
|
'requests',
|
|
13
13
|
'openai==1.34.0',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maitai_python-1.0.39 → maitai_python-1.0.40b0}/maitai_common/processes/websocket_listener_thread.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|