maitai-python 1.1.23b0__tar.gz → 1.1.25__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.1.23b0 → maitai_python-1.1.25}/PKG-INFO +1 -1
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_evaluator.py +2 -1
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_maitai.py +30 -4
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_maitai_async.py +30 -4
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/processes/io_thread.py +9 -3
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/processes/websocket_listener_thread.py +1 -1
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/utils/proto_utils.py +1 -3
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/utils/types.py +12 -4
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/version.py +1 -1
- maitai_python-1.1.25/maitai_gen/annotation/__init__.py +55 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/application/__init__.py +1 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/model/__init__.py +1 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_python.egg-info/SOURCES.txt +1 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/README.md +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_azure.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_config.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_context.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_inference.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_types.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/_utils.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/backtest/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/billing/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/chat/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/metric/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/rates/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/setup.cfg +0 -0
- {maitai_python-1.1.23b0 → maitai_python-1.1.25}/setup.py +0 -0
|
@@ -8,7 +8,8 @@ from betterproto import Casing
|
|
|
8
8
|
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._maitai_client import MaitaiClient
|
|
11
|
-
from maitai._utils import __version__ as version
|
|
11
|
+
from maitai._utils import __version__ as version
|
|
12
|
+
from maitai._utils import chat_completion_chunk_to_response
|
|
12
13
|
from maitai_common.utils.types import EvaluateCallback
|
|
13
14
|
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompletionRequest, ChatCompletionResponse, EvaluateRequest, EvaluateResponse, EvaluationContentType
|
|
14
15
|
from maitai_gen.metric import RequestTimingMetric
|
|
@@ -13,13 +13,35 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
13
13
|
import maitai
|
|
14
14
|
from maitai._config import config
|
|
15
15
|
from maitai._evaluator import Evaluator
|
|
16
|
-
from maitai._inference import
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
from maitai._inference import (
|
|
17
|
+
InferenceException,
|
|
18
|
+
InferenceWarning,
|
|
19
|
+
MaitaiConnectionError,
|
|
20
|
+
)
|
|
21
|
+
from maitai._types import (
|
|
22
|
+
Body,
|
|
23
|
+
Headers,
|
|
24
|
+
MaitaiChunk,
|
|
25
|
+
MaitaiCompletion,
|
|
26
|
+
Query,
|
|
27
|
+
ToolFunction,
|
|
28
|
+
)
|
|
29
|
+
from maitai._utils import (
|
|
30
|
+
convert_open_ai_chat_completion_chunk,
|
|
31
|
+
convert_openai_chat_completion,
|
|
32
|
+
get_chat_completion_params,
|
|
33
|
+
required_args,
|
|
34
|
+
)
|
|
19
35
|
from maitai.tools import Tools
|
|
20
36
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
21
37
|
from maitai_common.utils.types import EvaluateCallback
|
|
22
|
-
from maitai_gen.chat import
|
|
38
|
+
from maitai_gen.chat import (
|
|
39
|
+
ChatCompletionParams,
|
|
40
|
+
ChatCompletionRequest,
|
|
41
|
+
ChatMessage,
|
|
42
|
+
ClientParams,
|
|
43
|
+
EvaluationContentType,
|
|
44
|
+
)
|
|
23
45
|
from maitai_gen.config import InferenceLocations
|
|
24
46
|
from maitai_gen.inference import InferenceStreamResponse
|
|
25
47
|
from maitai_gen.metric import RequestTimingMetric
|
|
@@ -145,6 +167,7 @@ class Completions:
|
|
|
145
167
|
logit_bias: Union[Optional[Dict[str, int]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
146
168
|
logprobs: Union[Optional[bool], openai.NotGiven] = openai.NOT_GIVEN,
|
|
147
169
|
max_tokens: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
170
|
+
max_completion_tokens: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
148
171
|
n: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
149
172
|
presence_penalty: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
150
173
|
response_format: Union[
|
|
@@ -233,6 +256,8 @@ class Completions:
|
|
|
233
256
|
logprobs = maitai_config.logprobs
|
|
234
257
|
if max_tokens == openai.NOT_GIVEN and maitai_config.max_tokens is not None:
|
|
235
258
|
max_tokens = maitai_config.max_tokens
|
|
259
|
+
if max_completion_tokens and max_completion_tokens != openai.NOT_GIVEN:
|
|
260
|
+
max_tokens = max_completion_tokens
|
|
236
261
|
if n == openai.NOT_GIVEN:
|
|
237
262
|
n = maitai_config.n
|
|
238
263
|
if frequency_penalty == openai.NOT_GIVEN:
|
|
@@ -499,6 +524,7 @@ def _process_inference_stream(
|
|
|
499
524
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
500
525
|
timing.time_request_end = time.time()
|
|
501
526
|
maitai.Inference.store_request_timing_data(timing)
|
|
527
|
+
if chunk.usage:
|
|
502
528
|
return
|
|
503
529
|
except MaitaiConnectionError as e:
|
|
504
530
|
if "gpt" not in retry_args.get("model", "") and "gpt" in retry_args.get(
|
|
@@ -13,13 +13,35 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
13
13
|
import maitai
|
|
14
14
|
from maitai._config import config
|
|
15
15
|
from maitai._evaluator import Evaluator
|
|
16
|
-
from maitai._inference import
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
from maitai._inference import (
|
|
17
|
+
InferenceException,
|
|
18
|
+
InferenceWarning,
|
|
19
|
+
MaitaiConnectionError,
|
|
20
|
+
)
|
|
21
|
+
from maitai._types import (
|
|
22
|
+
Body,
|
|
23
|
+
Headers,
|
|
24
|
+
MaitaiChunk,
|
|
25
|
+
MaitaiCompletion,
|
|
26
|
+
Query,
|
|
27
|
+
ToolFunction,
|
|
28
|
+
)
|
|
29
|
+
from maitai._utils import (
|
|
30
|
+
convert_open_ai_chat_completion_chunk,
|
|
31
|
+
convert_openai_chat_completion,
|
|
32
|
+
get_chat_completion_params,
|
|
33
|
+
required_args,
|
|
34
|
+
)
|
|
19
35
|
from maitai.tools import Tools
|
|
20
36
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
21
37
|
from maitai_common.utils.types import EvaluateCallback
|
|
22
|
-
from maitai_gen.chat import
|
|
38
|
+
from maitai_gen.chat import (
|
|
39
|
+
ChatCompletionParams,
|
|
40
|
+
ChatCompletionRequest,
|
|
41
|
+
ChatMessage,
|
|
42
|
+
ClientParams,
|
|
43
|
+
EvaluationContentType,
|
|
44
|
+
)
|
|
23
45
|
from maitai_gen.config import InferenceLocations
|
|
24
46
|
from maitai_gen.inference import InferenceStreamResponse
|
|
25
47
|
from maitai_gen.metric import RequestTimingMetric
|
|
@@ -143,6 +165,7 @@ class AsyncCompletions:
|
|
|
143
165
|
logit_bias: Union[Optional[Dict[str, int]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
144
166
|
logprobs: Union[Optional[bool], openai.NotGiven] = openai.NOT_GIVEN,
|
|
145
167
|
max_tokens: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
168
|
+
max_completion_tokens: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
146
169
|
n: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
147
170
|
presence_penalty: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
148
171
|
response_format: Union[
|
|
@@ -231,6 +254,8 @@ class AsyncCompletions:
|
|
|
231
254
|
logprobs = maitai_config.logprobs
|
|
232
255
|
if max_tokens == openai.NOT_GIVEN and maitai_config.max_tokens is not None:
|
|
233
256
|
max_tokens = maitai_config.max_tokens
|
|
257
|
+
if max_completion_tokens and max_completion_tokens != openai.NOT_GIVEN:
|
|
258
|
+
max_tokens = max_completion_tokens
|
|
234
259
|
if n == openai.NOT_GIVEN:
|
|
235
260
|
n = maitai_config.n
|
|
236
261
|
if frequency_penalty == openai.NOT_GIVEN:
|
|
@@ -498,6 +523,7 @@ async def _process_inference_stream_async(
|
|
|
498
523
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
499
524
|
timing.time_request_end = time.time()
|
|
500
525
|
maitai.Inference.store_request_timing_data(timing)
|
|
526
|
+
if chunk.usage:
|
|
501
527
|
return
|
|
502
528
|
except MaitaiConnectionError as e:
|
|
503
529
|
if "gpt" not in retry_args.get("model", "") and "gpt" in retry_args.get(
|
|
@@ -36,12 +36,18 @@ class IOThread(Thread):
|
|
|
36
36
|
try:
|
|
37
37
|
self.process()
|
|
38
38
|
except Exception as e:
|
|
39
|
-
self.print(
|
|
39
|
+
self.print(
|
|
40
|
+
e,
|
|
41
|
+
f"[{self.child_name}] Exception hit processing",
|
|
42
|
+
traceback.format_exc(),
|
|
43
|
+
)
|
|
40
44
|
finally:
|
|
41
45
|
self.is_running = False
|
|
42
46
|
|
|
43
47
|
delta = time.time() - self.last_loop_start
|
|
44
|
-
self.avg_loop_time = (
|
|
48
|
+
self.avg_loop_time = (
|
|
49
|
+
(self.avg_loop_time * self.completed_loops) * delta
|
|
50
|
+
) / (self.completed_loops + 1)
|
|
45
51
|
self.completed_loops += 1
|
|
46
52
|
next_run = self.interval - delta
|
|
47
53
|
await asyncio.sleep(max(0, next_run))
|
|
@@ -51,7 +57,7 @@ class IOThread(Thread):
|
|
|
51
57
|
def terminate(self):
|
|
52
58
|
self.run_thread = False
|
|
53
59
|
self.cleaned = True
|
|
54
|
-
self.print(f
|
|
60
|
+
self.print(f"{self.child_name} cleaned up")
|
|
55
61
|
|
|
56
62
|
def process(self):
|
|
57
63
|
return None
|
|
@@ -13,7 +13,5 @@ def openai_messages_to_proto(messages: Iterable[ChatCompletionMessageParam]):
|
|
|
13
13
|
elif isinstance(message, ChatCompletionMessage):
|
|
14
14
|
proto_messages.append(ChatMessage().from_pydict(message.to_pydict()))
|
|
15
15
|
else:
|
|
16
|
-
proto_messages.append(
|
|
17
|
-
ChatMessage().from_pydict(message)
|
|
18
|
-
)
|
|
16
|
+
proto_messages.append(ChatMessage().from_pydict(message))
|
|
19
17
|
return proto_messages
|
|
@@ -5,12 +5,18 @@ from typing import Callable, Union
|
|
|
5
5
|
import maitai_gen.chat as chat_types
|
|
6
6
|
from maitai_gen.chat import *
|
|
7
7
|
|
|
8
|
-
ChunkQueue = queue.Queue[
|
|
9
|
-
|
|
8
|
+
ChunkQueue = queue.Queue[
|
|
9
|
+
Union[chat_types.ChatCompletionChunk, StopIteration, Exception]
|
|
10
|
+
]
|
|
11
|
+
AsyncChunkQueue = asyncio.Queue[
|
|
12
|
+
Union[chat_types.ChatCompletionChunk, StopIteration, Exception]
|
|
13
|
+
]
|
|
10
14
|
|
|
11
15
|
|
|
12
16
|
class QueueIterable:
|
|
13
|
-
def __init__(
|
|
17
|
+
def __init__(
|
|
18
|
+
self, chunk_queue: Union[ChunkQueue, AsyncChunkQueue], timeout=None
|
|
19
|
+
) -> None:
|
|
14
20
|
self.queue = chunk_queue
|
|
15
21
|
self.done = False
|
|
16
22
|
self.timeout = timeout
|
|
@@ -27,7 +33,9 @@ class QueueIterable:
|
|
|
27
33
|
while not self.done:
|
|
28
34
|
try:
|
|
29
35
|
# Wait for an item from the queue, block if necessary
|
|
30
|
-
item = self.queue.get(
|
|
36
|
+
item = self.queue.get(
|
|
37
|
+
timeout=self.timeout
|
|
38
|
+
) # Wait for 10 seconds, adjust as needed
|
|
31
39
|
if isinstance(item, StopIteration):
|
|
32
40
|
self.done = True # Set done to True to prevent further blocking
|
|
33
41
|
raise StopIteration
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
2
|
+
# sources: annotation.proto
|
|
3
|
+
# plugin: python-betterproto
|
|
4
|
+
# This file has been @generated
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import (
|
|
8
|
+
List,
|
|
9
|
+
Optional,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
import betterproto
|
|
13
|
+
|
|
14
|
+
from .. import chat as _chat__
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(eq=False, repr=False)
|
|
18
|
+
class RequestData(betterproto.Message):
|
|
19
|
+
messages: List["_chat__.ChatMessage"] = betterproto.message_field(1)
|
|
20
|
+
tools: List["_chat__.Tool"] = betterproto.message_field(2)
|
|
21
|
+
label: Optional["_chat__.ChatMessage"] = betterproto.message_field(
|
|
22
|
+
3, optional=True, group="_label"
|
|
23
|
+
)
|
|
24
|
+
request_id: str = betterproto.string_field(4)
|
|
25
|
+
saved: bool = betterproto.bool_field(5)
|
|
26
|
+
excluded: bool = betterproto.bool_field(6)
|
|
27
|
+
date_created: int = betterproto.int64_field(7)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(eq=False, repr=False)
|
|
31
|
+
class AnnotationMetadata(betterproto.Message):
|
|
32
|
+
company_name: str = betterproto.string_field(1)
|
|
33
|
+
app_name: str = betterproto.string_field(2)
|
|
34
|
+
intent_name: str = betterproto.string_field(3)
|
|
35
|
+
incomplete_sessions: List[str] = betterproto.string_field(4)
|
|
36
|
+
excluded_sessions: List[str] = betterproto.string_field(5)
|
|
37
|
+
contact_email: str = betterproto.string_field(6)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(eq=False, repr=False)
|
|
41
|
+
class GetSessionsResponse(betterproto.Message):
|
|
42
|
+
sessions: List["AnnotationSession"] = betterproto.message_field(1)
|
|
43
|
+
metadata: "AnnotationMetadata" = betterproto.message_field(2)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(eq=False, repr=False)
|
|
47
|
+
class AnnotationSession(betterproto.Message):
|
|
48
|
+
session_id: str = betterproto.string_field(1)
|
|
49
|
+
date_created: int = betterproto.int64_field(2)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(eq=False, repr=False)
|
|
53
|
+
class FinetuningData(betterproto.Message):
|
|
54
|
+
messages: List["_chat__.ChatMessage"] = betterproto.message_field(1)
|
|
55
|
+
tools: List["_chat__.Tool"] = betterproto.message_field(2)
|
|
@@ -24,6 +24,7 @@ maitai_common/utils/__init__.py
|
|
|
24
24
|
maitai_common/utils/proto_utils.py
|
|
25
25
|
maitai_common/utils/types.py
|
|
26
26
|
maitai_gen/__init__.py
|
|
27
|
+
maitai_gen/annotation/__init__.py
|
|
27
28
|
maitai_gen/application/__init__.py
|
|
28
29
|
maitai_gen/backtest/__init__.py
|
|
29
30
|
maitai_gen/billing/__init__.py
|
|
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
|
|
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
|