maitai-python 1.0.38b1__tar.gz → 1.0.39b0__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 (45) hide show
  1. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/PKG-INFO +1 -1
  2. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_inference.py +2 -9
  3. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_maitai.py +37 -9
  4. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_maitai_async.py +36 -10
  5. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_maitai_client.py +4 -2
  6. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_types.py +3 -2
  7. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/processes/websocket_listener_thread.py +1 -1
  8. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/version.py +1 -1
  9. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/chat/__init__.py +12 -0
  10. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_python.egg-info/PKG-INFO +1 -1
  11. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/README.md +0 -0
  12. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/__init__.py +0 -0
  13. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_azure.py +0 -0
  14. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_config.py +0 -0
  15. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_config_listener_thread.py +0 -0
  16. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_context.py +0 -0
  17. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_evaluator.py +0 -0
  18. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai/_utils.py +0 -0
  19. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/__init__.py +0 -0
  20. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/config/__init__.py +0 -0
  21. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/config/config_service.py +0 -0
  22. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/processes/__init__.py +0 -0
  23. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/processes/io_thread.py +0 -0
  24. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/utils/__init__.py +0 -0
  25. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/utils/proto_utils.py +0 -0
  26. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_common/utils/types.py +0 -0
  27. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/__init__.py +0 -0
  28. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/application/__init__.py +0 -0
  29. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/company/__init__.py +0 -0
  30. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/config/__init__.py +0 -0
  31. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/embedding/__init__.py +0 -0
  32. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/event/__init__.py +0 -0
  33. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/inference/__init__.py +0 -0
  34. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/key/__init__.py +0 -0
  35. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/model/__init__.py +0 -0
  36. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/notification/__init__.py +0 -0
  37. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/sandbox/__init__.py +0 -0
  38. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/sentinel/__init__.py +0 -0
  39. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_gen/session/__init__.py +0 -0
  40. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_python.egg-info/SOURCES.txt +0 -0
  41. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_python.egg-info/dependency_links.txt +0 -0
  42. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_python.egg-info/requires.txt +0 -0
  43. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/maitai_python.egg-info/top_level.txt +0 -0
  44. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/setup.cfg +0 -0
  45. {maitai_python-1.0.38b1 → maitai_python-1.0.39b0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maitai-python
3
- Version: 1.0.38b1
3
+ Version: 1.0.39b0
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai
@@ -29,10 +29,7 @@ class Inference(MaitaiClient):
29
29
  super().__init__()
30
30
 
31
31
  @classmethod
32
- def infer(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool, evaluation_enabled: bool, evaluate_callback: EvaluateCallback = None,
33
- timeout=None, context_retrieval_enabled=False, context_query='', return_request=False, fallback_model=None, user_id: str = "", assistant=False) -> Iterable[InferenceStreamResponse]:
34
- chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback,
35
- context_retrieval_enabled, context_query, return_request, fallback_model, user_id, assistant)
32
+ def infer(cls, chat_request: ChatCompletionRequest, evaluate_callback, timeout) -> Iterable[InferenceStreamResponse]:
36
33
  if evaluate_callback:
37
34
  q = ChunkQueue()
38
35
  cls.run_async(cls.send_inference_request_async(chat_request, chunk_queue=q, evaluation_callback=evaluate_callback))
@@ -41,11 +38,7 @@ class Inference(MaitaiClient):
41
38
  return cls.send_inference_request(chat_request)
42
39
 
43
40
  @classmethod
44
- async def infer_async(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool,
45
- evaluation_enabled: bool, evaluate_callback: EvaluateCallback = None, timeout=None, context_retrieval_enabled=False,
46
- context_query='', fallback_model=None, user_id="", assistant=False) -> AsyncIterable[InferenceStreamResponse]:
47
- chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback,
48
- context_retrieval_enabled, context_query, False, fallback_model, user_id, assistant)
41
+ async def infer_async(cls, chat_request: ChatCompletionRequest, evaluate_callback, timeout) -> AsyncIterable[InferenceStreamResponse]:
49
42
  q = AsyncChunkQueue()
50
43
  cls.run_async(cls.send_inference_request_async(chat_request, async_chunk_queue=q, evaluation_callback=evaluate_callback))
51
44
  return QueueIterable(q, timeout=timeout)
@@ -16,7 +16,7 @@ from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
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
19
- from maitai_gen.chat import ChatCompletionParams, ChatMessage, EvaluationContentType
19
+ from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest, ChatMessage, ClientParams, EvaluationContentType
20
20
  from maitai_gen.config import InferenceLocations
21
21
  from maitai_gen.inference import InferenceStreamResponse
22
22
 
@@ -71,17 +71,25 @@ class Maitai:
71
71
  http_client=http_client,
72
72
  _strict_response_validation=_strict_response_validation,
73
73
  )
74
- self.chat = Chat(self.client)
74
+ client_params = None
75
+ if base_url or default_headers or default_query:
76
+ client_params = ClientParams(
77
+ base_url=base_url or "",
78
+ default_headers=default_headers or {},
79
+ default_query=default_query or {},
80
+ )
81
+ self.chat = Chat(self.client, client_params)
75
82
 
76
83
 
77
84
  class Chat:
78
- def __init__(self, client=None):
79
- self.completions = Completions(client)
85
+ def __init__(self, client=None, client_params: ClientParams = None):
86
+ self.completions = Completions(client, client_params)
80
87
 
81
88
 
82
89
  class Completions:
83
- def __init__(self, client: Optional[openai.Client] = None):
90
+ def __init__(self, client: Optional[openai.Client] = None, client_params: Optional[ClientParams] = None):
84
91
  self.client = client
92
+ self.client_params = client_params or ClientParams()
85
93
 
86
94
  @required_args(["session_id", "action_type", "application_ref_name", "messages"],
87
95
  ["session_id", "intent", "application_ref_name", "messages"],
@@ -201,9 +209,25 @@ class Completions:
201
209
  response_timeout = None
202
210
  if isinstance(timeout, float) or isinstance(timeout, int):
203
211
  response_timeout = timeout
204
- response = maitai.Inference.infer(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
205
- context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, return_request=return_request, fallback_model=fallback_model, user_id=user_id,
206
- assistant=assistant)
212
+ chat_request: ChatCompletionRequest = maitai.Inference.create_inference_request(
213
+ application_ref_name=application_ref_name,
214
+ session_id=session_id,
215
+ reference_id=reference_id,
216
+ intent=intent,
217
+ apply_corrections=apply_corrections,
218
+ evaluation_enabled=evaluation_enabled,
219
+ completion_params=completion_params,
220
+ callback=callback,
221
+ context_retrieval_enabled=context_retrieval_enabled,
222
+ context_query=context_query,
223
+ return_request=return_request,
224
+ fallback_model=fallback_model,
225
+ user_id=user_id,
226
+ assistant=assistant,
227
+ client_params=self.client_params,
228
+ )
229
+
230
+ response = maitai.Inference.infer(chat_request, callback, response_timeout)
207
231
  if stream:
208
232
  return _process_inference_stream(response)
209
233
  # ChatCompletion only
@@ -216,7 +240,11 @@ class Completions:
216
240
  raise InferenceException("No data received")
217
241
  else:
218
242
  if self.client is None:
219
- self.client = openai.OpenAI()
243
+ self.client = openai.OpenAI(
244
+ default_query=self.client_params.default_query or None,
245
+ default_headers=self.client_params.default_headers or None,
246
+ base_url=self.client_params.base_url or None,
247
+ )
220
248
  response = self.client.chat.completions.create(
221
249
  messages=messages,
222
250
  model=model,
@@ -15,7 +15,7 @@ from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
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
18
- from maitai_gen.chat import ChatCompletionParams, ChatMessage, EvaluationContentType
18
+ from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest, ChatMessage, ClientParams, EvaluationContentType
19
19
  from maitai_gen.config import InferenceLocations
20
20
  from maitai_gen.inference import InferenceStreamResponse
21
21
 
@@ -70,19 +70,25 @@ class MaitaiAsync:
70
70
  _strict_response_validation=_strict_response_validation,
71
71
  )
72
72
 
73
- self.chat = AsyncChat(self.client)
73
+ client_params = None
74
+ if base_url or default_headers or default_query:
75
+ client_params = ClientParams(
76
+ base_url=base_url or "",
77
+ default_headers=default_headers or {},
78
+ default_query=default_query or {},
79
+ )
80
+ self.chat = AsyncChat(self.client, client_params)
74
81
 
75
82
 
76
83
  class AsyncChat:
77
- def __init__(self, client=None):
78
- self.completions = AsyncCompletions(client)
84
+ def __init__(self, client=None, client_params: ClientParams = None):
85
+ self.completions = AsyncCompletions(client, client_params)
79
86
 
80
87
 
81
88
  class AsyncCompletions:
82
- def __init__(self, client: Optional[openai.AsyncClient] = None):
83
- if client is None:
84
- client = openai.AsyncClient()
89
+ def __init__(self, client: Optional[openai.AsyncClient] = None, client_params: Optional[ClientParams] = None):
85
90
  self.client = client
91
+ self.client_params = client_params or ClientParams()
86
92
 
87
93
  @required_args(["session_id", "action_type", "application_ref_name", "messages"],
88
94
  ["session_id", "intent", "application_ref_name", "messages"],
@@ -202,8 +208,24 @@ class AsyncCompletions:
202
208
  response_timeout = None
203
209
  if isinstance(timeout, float) or isinstance(timeout, int):
204
210
  response_timeout = timeout
205
- response = await maitai.Inference.infer_async(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
206
- context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, fallback_model=fallback_model, user_id=user_id, assistant=assistant)
211
+ chat_request: ChatCompletionRequest = maitai.Inference.create_inference_request(
212
+ application_ref_name=application_ref_name,
213
+ session_id=session_id,
214
+ reference_id=reference_id,
215
+ intent=intent,
216
+ apply_corrections=apply_corrections,
217
+ evaluation_enabled=evaluation_enabled,
218
+ completion_params=completion_params,
219
+ callback=callback,
220
+ context_retrieval_enabled=context_retrieval_enabled,
221
+ context_query=context_query,
222
+ return_request=False,
223
+ fallback_model=fallback_model,
224
+ user_id=user_id,
225
+ assistant=assistant,
226
+ client_params=self.client_params,
227
+ )
228
+ response = await maitai.Inference.infer_async(chat_request, callback, response_timeout)
207
229
  if stream:
208
230
  return _process_inference_stream_async(response)
209
231
  # ChatCompletion only
@@ -216,7 +238,11 @@ class AsyncCompletions:
216
238
  raise InferenceException("No data received")
217
239
  else:
218
240
  if self.client is None:
219
- self.client = openai.OpenAI()
241
+ self.client = openai.AsyncOpenAI(
242
+ default_headers=self.client_params.default_headers or None,
243
+ default_query=self.client_params.default_query or None,
244
+ base_url=self.client_params.base_url or None,
245
+ )
220
246
  response = await self.client.chat.completions.create(
221
247
  messages=messages,
222
248
  model=model,
@@ -2,7 +2,7 @@ import asyncio
2
2
  import threading
3
3
 
4
4
  from maitai._config import config
5
- from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest
5
+ from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest, ClientParams
6
6
 
7
7
 
8
8
  class MaitaiClient:
@@ -36,7 +36,7 @@ class MaitaiClient:
36
36
 
37
37
  @classmethod
38
38
  def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback=None,
39
- context_retrieval_enabled=False, context_query=None, return_request=False, fallback_model=None, user_id="", assistant=False):
39
+ context_retrieval_enabled=False, context_query=None, return_request=False, fallback_model=None, user_id="", assistant=False, client_params: ClientParams = None):
40
40
  infer_request: ChatCompletionRequest = ChatCompletionRequest()
41
41
  infer_request.application_ref_name = application_ref_name
42
42
  infer_request.reference_id = reference_id
@@ -53,4 +53,6 @@ class MaitaiClient:
53
53
  infer_request.fallback_model = fallback_model
54
54
  infer_request.user_id = user_id
55
55
  infer_request.assistant = assistant
56
+ if client_params is not None:
57
+ infer_request.client_params = client_params
56
58
  return infer_request
@@ -1,3 +1,4 @@
1
+ import json
1
2
  from datetime import datetime
2
3
  from typing import Mapping, Union
3
4
 
@@ -27,7 +28,7 @@ class MaitaiChunk(ChatCompletionChunk):
27
28
  self.from_pydict(chat_completion_chunk.to_pydict())
28
29
 
29
30
  def model_dump_json(self):
30
- return self.to_pydict(casing=Casing.SNAKE)
31
+ return json.dumps(self.to_pydict(casing=Casing.SNAKE))
31
32
 
32
33
  def openai_dump_json(self):
33
34
  data = self.to_pydict(casing=Casing.SNAKE)
@@ -66,7 +67,7 @@ class MaitaiCompletion(ChatCompletionResponse):
66
67
  self.from_pydict(chat_completion_response.to_pydict())
67
68
 
68
69
  def model_dump_json(self):
69
- return self.to_pydict(casing=Casing.SNAKE)
70
+ return json.dumps(self.to_pydict(casing=Casing.SNAKE))
70
71
 
71
72
  def openai_dump_json(self):
72
73
  data = self.to_pydict(casing=Casing.SNAKE)
@@ -41,7 +41,7 @@ class WebsocketListenerThread(IOThread):
41
41
  print(f'Received message: {message}')
42
42
  self.messages.append(message)
43
43
 
44
- def on_close(self, ws):
44
+ def on_close(self, ws, _, __):
45
45
  print("WebSocket connection closed. Reconnecting...")
46
46
  self.connect_to_websocket()
47
47
 
@@ -1,3 +1,3 @@
1
- version = "1.0.38b1"
1
+ version = "1.0.39b0"
2
2
  if __name__ == "__main__":
3
3
  print(version)
@@ -71,6 +71,18 @@ class ChatCompletionRequest(betterproto.Message):
71
71
  fallback_model: str = betterproto.string_field(21)
72
72
  user_id: str = betterproto.string_field(22)
73
73
  assistant: bool = betterproto.bool_field(23)
74
+ client_params: "ClientParams" = betterproto.message_field(24)
75
+
76
+
77
+ @dataclass(eq=False, repr=False)
78
+ class ClientParams(betterproto.Message):
79
+ base_url: str = betterproto.string_field(1)
80
+ default_headers: Dict[str, str] = betterproto.map_field(
81
+ 2, betterproto.TYPE_STRING, betterproto.TYPE_STRING
82
+ )
83
+ default_query: Dict[str, str] = betterproto.map_field(
84
+ 3, betterproto.TYPE_STRING, betterproto.TYPE_STRING
85
+ )
74
86
 
75
87
 
76
88
  @dataclass(eq=False, repr=False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maitai-python
3
- Version: 1.0.38b1
3
+ Version: 1.0.39b0
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai