ommlds 0.0.0.dev441__py3-none-any.whl → 0.0.0.dev442__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.
Files changed (54) hide show
  1. ommlds/.omlish-manifests.json +3 -3
  2. ommlds/__about__.py +1 -1
  3. ommlds/backends/google/__init__.py +0 -0
  4. ommlds/backends/google/protocol/__init__.py +0 -0
  5. ommlds/backends/google/protocol/types.py +75 -0
  6. ommlds/backends/openai/protocol/__init__.py +9 -28
  7. ommlds/backends/openai/protocol/_marshal.py +26 -0
  8. ommlds/backends/openai/protocol/chatcompletion/chunk.py +54 -31
  9. ommlds/backends/openai/protocol/chatcompletion/contentpart.py +41 -44
  10. ommlds/backends/openai/protocol/chatcompletion/message.py +45 -43
  11. ommlds/backends/openai/protocol/chatcompletion/request.py +99 -69
  12. ommlds/backends/openai/protocol/chatcompletion/response.py +61 -45
  13. ommlds/backends/openai/protocol/chatcompletion/responseformat.py +21 -20
  14. ommlds/backends/openai/protocol/chatcompletion/tokenlogprob.py +12 -7
  15. ommlds/backends/openai/protocol/completionusage.py +19 -15
  16. ommlds/cli/sessions/chat/interactive.py +1 -1
  17. ommlds/cli/sessions/chat/prompt.py +4 -4
  18. ommlds/cli/sessions/completion/completion.py +1 -1
  19. ommlds/cli/sessions/embedding/embedding.py +1 -1
  20. ommlds/minichain/backends/impls/anthropic/chat.py +1 -1
  21. ommlds/minichain/backends/impls/anthropic/stream.py +17 -15
  22. ommlds/minichain/backends/impls/duckduckgo/search.py +1 -1
  23. ommlds/minichain/backends/impls/google/chat.py +19 -14
  24. ommlds/minichain/backends/impls/google/search.py +1 -1
  25. ommlds/minichain/backends/impls/llamacpp/chat.py +1 -1
  26. ommlds/minichain/backends/impls/llamacpp/completion.py +1 -1
  27. ommlds/minichain/backends/impls/llamacpp/stream.py +1 -1
  28. ommlds/minichain/backends/impls/mistral.py +1 -1
  29. ommlds/minichain/backends/impls/mlx/chat.py +1 -1
  30. ommlds/minichain/backends/impls/openai/chat.py +1 -1
  31. ommlds/minichain/backends/impls/openai/completion.py +1 -1
  32. ommlds/minichain/backends/impls/openai/embedding.py +1 -1
  33. ommlds/minichain/backends/impls/openai/stream.py +9 -1
  34. ommlds/minichain/backends/impls/tinygrad/chat.py +2 -2
  35. ommlds/minichain/backends/impls/transformers/sentence.py +1 -1
  36. ommlds/minichain/backends/impls/transformers/transformers.py +2 -2
  37. ommlds/minichain/chat/choices/adapters.py +2 -2
  38. ommlds/minichain/chat/choices/services.py +1 -1
  39. ommlds/minichain/chat/history.py +2 -2
  40. ommlds/minichain/chat/services.py +1 -1
  41. ommlds/minichain/chat/stream/adapters.py +2 -2
  42. ommlds/minichain/chat/stream/services.py +1 -1
  43. ommlds/minichain/chat/transforms/services.py +4 -4
  44. ommlds/minichain/services/facades.py +3 -3
  45. ommlds/minichain/services/services.py +1 -1
  46. ommlds/minichain/stream/wrap.py +2 -2
  47. ommlds/server/server.py +2 -2
  48. ommlds/tools/git.py +4 -4
  49. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/METADATA +5 -5
  50. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/RECORD +54 -50
  51. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/WHEEL +0 -0
  52. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/entry_points.txt +0 -0
  53. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/licenses/LICENSE +0 -0
  54. {ommlds-0.0.0.dev441.dist-info → ommlds-0.0.0.dev442.dist-info}/top_level.txt +0 -0
@@ -63,7 +63,7 @@
63
63
  "module": ".minichain.backends.impls.anthropic.stream",
64
64
  "attr": null,
65
65
  "file": "ommlds/minichain/backends/impls/anthropic/stream.py",
66
- "line": 29,
66
+ "line": 34,
67
67
  "value": {
68
68
  "!.minichain.registries.manifests.RegistryManifest": {
69
69
  "module": "ommlds.minichain.backends.impls.anthropic.stream",
@@ -95,7 +95,7 @@
95
95
  "module": ".minichain.backends.impls.google.chat",
96
96
  "attr": null,
97
97
  "file": "ommlds/minichain/backends/impls/google/chat.py",
98
- "line": 27,
98
+ "line": 30,
99
99
  "value": {
100
100
  "!.minichain.registries.manifests.RegistryManifest": {
101
101
  "module": "ommlds.minichain.backends.impls.google.chat",
@@ -341,7 +341,7 @@
341
341
  "module": ".minichain.backends.impls.openai.stream",
342
342
  "attr": null,
343
343
  "file": "ommlds/minichain/backends/impls/openai/stream.py",
344
- "line": 31,
344
+ "line": 36,
345
345
  "value": {
346
346
  "!.minichain.registries.manifests.RegistryManifest": {
347
347
  "module": "ommlds.minichain.backends.impls.openai.stream",
ommlds/__about__.py CHANGED
@@ -56,7 +56,7 @@ class Project(ProjectBase):
56
56
  ],
57
57
 
58
58
  'search': [
59
- 'ddgs ~= 9.5',
59
+ 'ddgs ~= 9.6',
60
60
  ],
61
61
 
62
62
  'wiki': [
File without changes
File without changes
@@ -0,0 +1,75 @@
1
+ import typing as ta
2
+
3
+ from omlish import dataclasses as dc
4
+ from omlish import lang
5
+ from omlish import marshal as msh
6
+
7
+
8
+ ##
9
+
10
+
11
+ @dc.dataclass(frozen=True, kw_only=True)
12
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
13
+ class GenerateContentRequest:
14
+ """https://ai.google.dev/api/generate-content#request-body"""
15
+
16
+ @dc.dataclass(frozen=True, kw_only=True)
17
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
18
+ class Content(lang.Final):
19
+ @dc.dataclass(frozen=True, kw_only=True)
20
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
21
+ class Part(lang.Final):
22
+ text: str
23
+
24
+ parts: ta.Sequence[Part]
25
+ role: ta.Literal['user', 'model']
26
+
27
+ contents: ta.Sequence[Content]
28
+
29
+
30
+ @dc.dataclass(frozen=True, kw_only=True)
31
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
32
+ class GenerateContentResponse:
33
+ """https://ai.google.dev/api/generate-content#v1beta.GenerateContentResponse"""
34
+
35
+ @dc.dataclass(frozen=True, kw_only=True)
36
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
37
+ class Candidate(lang.Final):
38
+ @dc.dataclass(frozen=True, kw_only=True)
39
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
40
+ class Content(lang.Final):
41
+ @dc.dataclass(frozen=True, kw_only=True)
42
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
43
+ class Part(lang.Final):
44
+ text: str
45
+
46
+ parts: ta.Sequence[Part]
47
+ role: ta.Literal['user', 'model']
48
+
49
+ content: Content
50
+ finish_reason: ta.Literal['STOP'] | None
51
+ index: int
52
+
53
+ candidates: ta.Sequence[Candidate]
54
+
55
+ @dc.dataclass(frozen=True, kw_only=True)
56
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
57
+ class UsageMetadata(lang.Final):
58
+ prompt_token_count: int
59
+ candidates_token_count: int
60
+ total_token_count: int
61
+ thoughts_token_count: int
62
+
63
+ @dc.dataclass(frozen=True, kw_only=True)
64
+ @msh.update_object_metadata(field_naming=msh.Naming.LOW_CAMEL)
65
+ class ModalityTokenCount:
66
+ modality: str
67
+ token_count: int
68
+
69
+ prompt_tokens_details: ta.Sequence[ModalityTokenCount]
70
+
71
+ usage_metadata: UsageMetadata
72
+
73
+ model_version: str
74
+
75
+ response_id: str
@@ -5,11 +5,8 @@ https://github.com/openai/openai-openapi/blob/master/openapi.yaml
5
5
  # ruff: noqa: I001
6
6
 
7
7
  from .chatcompletion.chunk import ( # noqa
8
- ChatCompletionChunkChoiceDeltaToolCallFunction,
9
- ChatCompletionChunkChoiceDeltaToolCall,
10
8
  ChatCompletionChunkChoiceDelta,
11
9
 
12
- ChatCompletionChunkChoiceLogprobs,
13
10
  ChatCompletionChunkChoice,
14
11
 
15
12
  ChatCompletionChunk,
@@ -18,13 +15,10 @@ from .chatcompletion.chunk import ( # noqa
18
15
  from .chatcompletion.contentpart import ( # noqa
19
16
  TextChatCompletionContentPart,
20
17
 
21
- ImageChatCompletionContentPartImageUrl,
22
- ImageChatCompletionContentPart,
18
+ ImageUrlChatCompletionContentPart,
23
19
 
24
- FileChatCompletionContentPartFileInfo,
25
20
  FileChatCompletionContentPart,
26
21
 
27
- InputAudioChatCompletionContentPartInputAudio,
28
22
  InputAudioChatCompletionContentPart,
29
23
 
30
24
  RefusalChatCompletionContentPart,
@@ -39,9 +33,6 @@ from .chatcompletion.message import ( # noqa
39
33
 
40
34
  UserChatCompletionMessage,
41
35
 
42
- AssistantChatCompletionMessageAudio,
43
- AssistantChatCompletionMessageToolCallFunction,
44
- AssistantChatCompletionMessageToolCall,
45
36
  AssistantChatCompletionMessage,
46
37
 
47
38
  ToolChatCompletionMessage,
@@ -52,18 +43,12 @@ from .chatcompletion.message import ( # noqa
52
43
  )
53
44
 
54
45
  from .chatcompletion.request import ( # noqa
55
- ChatCompletionRequestWebSearchOptionsUserLocationApproximate,
56
- ChatCompletionRequestWebSearchOptionsUserLocation,
57
46
  ChatCompletionRequestWebSearchOptions,
58
47
 
59
48
  ChatCompletionRequestPrediction,
60
49
 
61
- ChatCompletionRequestToolFunction,
62
50
  ChatCompletionRequestTool,
63
51
 
64
- ChatCompletionRequestStreamOptions,
65
-
66
- ChatCompletionRequestNamedToolChoiceFunction,
67
52
  ChatCompletionRequestNamedToolChoice,
68
53
 
69
54
  ChatCompletionRequestAudio,
@@ -72,16 +57,8 @@ from .chatcompletion.request import ( # noqa
72
57
  )
73
58
 
74
59
  from .chatcompletion.response import ( # noqa
75
- ChatCompletionResponseAnnotationUrlCitation,
76
- ChatCompletionResponseAnnotation,
77
-
78
- ChatCompletionResponseAudio,
79
-
80
- ChatCompletionResponseMessageToolCallFunction,
81
- ChatCompletionResponseMessageToolCall,
82
60
  ChatCompletionResponseMessage,
83
61
 
84
- ChatCompletionResponseChoiceLogprobs,
85
62
  ChatCompletionResponseChoice,
86
63
 
87
64
  ChatCompletionResponse,
@@ -90,7 +67,6 @@ from .chatcompletion.response import ( # noqa
90
67
  from .chatcompletion.responseformat import ( # noqa
91
68
  TextChatCompletionResponseFormat,
92
69
 
93
- JsonSchemaChatCompletionResponseFormatJsonSchema,
94
70
  JsonSchemaChatCompletionResponseFormat,
95
71
 
96
72
  JsonObjectChatCompletionResponseFormat,
@@ -99,12 +75,17 @@ from .chatcompletion.responseformat import ( # noqa
99
75
  )
100
76
 
101
77
  from .chatcompletion.tokenlogprob import ( # noqa
102
- ChatCompletionTokenLogprobTopLogprob,
103
78
  ChatCompletionTokenLogprob,
104
79
  )
105
80
 
106
81
  from .completionusage import ( # noqa
107
- CompletionUsageCompletionTokensDetails,
108
- CompletionUsagePromptTokensDetails,
109
82
  CompletionUsage,
110
83
  )
84
+
85
+
86
+ ##
87
+
88
+
89
+ from omlish import marshal as _msh # noqa
90
+
91
+ _msh.register_global_module_import('._marshal', __package__)
@@ -0,0 +1,26 @@
1
+ from omlish import lang
2
+ from omlish import marshal as msh
3
+
4
+ from .chatcompletion.contentpart import ChatCompletionContentPart
5
+ from .chatcompletion.message import ChatCompletionMessage
6
+ from .chatcompletion.responseformat import ChatCompletionResponseFormat
7
+
8
+
9
+ ##
10
+
11
+
12
+ @lang.static_init
13
+ def _install_standard_marshalling() -> None:
14
+ for root_cls, tag_field in [
15
+ (ChatCompletionContentPart, 'type'),
16
+ (ChatCompletionMessage, 'role'),
17
+ (ChatCompletionResponseFormat, 'type'),
18
+ ]:
19
+ msh.install_standard_factories(*msh.standard_polymorphism_factories(
20
+ msh.polymorphism_from_subclasses(
21
+ root_cls,
22
+ naming=msh.Naming.SNAKE,
23
+ strip_suffix='auto',
24
+ ),
25
+ msh.FieldTypeTagging(tag_field),
26
+ ))
@@ -1,71 +1,94 @@
1
1
  import typing as ta
2
2
 
3
+ from omlish import dataclasses as dc
4
+ from omlish import lang
5
+
6
+ from ..completionusage import CompletionUsage
3
7
  from .tokenlogprob import ChatCompletionTokenLogprob
4
8
 
5
9
 
6
10
  ##
7
11
 
8
12
 
9
- class ChatCompletionChunkChoiceDeltaToolCallFunction(ta.TypedDict, total=False):
10
- arguments: str
11
- name: str
12
-
13
-
14
- class ChatCompletionChunkChoiceDeltaToolCall(ta.TypedDict):
15
- index: int
16
- id: ta.NotRequired[str]
17
- function: ta.NotRequired[ChatCompletionChunkChoiceDeltaToolCallFunction]
18
- type: ta.Literal['function']
19
-
20
-
21
- #
13
+ @dc.dataclass(frozen=True, kw_only=True)
14
+ class ChatCompletionChunkChoiceDelta(lang.Final):
15
+ content: str | None = None
22
16
 
17
+ refusal: str | None = None
23
18
 
24
- class ChatCompletionChunkChoiceDelta(ta.TypedDict, total=False):
25
- content: str
26
- refusal: str
27
19
  role: ta.Literal[
28
20
  'developer',
29
21
  'system',
30
22
  'user',
31
23
  'assistant',
32
24
  'tool',
33
- ]
34
- tool_calls: ta.Sequence[ChatCompletionChunkChoiceDeltaToolCall]
25
+ ] | None = None
35
26
 
27
+ @dc.dataclass(frozen=True, kw_only=True)
28
+ class ToolCall(lang.Final):
29
+ index: int
36
30
 
37
- #
31
+ id: str | None = None
32
+
33
+ @dc.dataclass(frozen=True, kw_only=True)
34
+ class Function(lang.Final):
35
+ arguments: str | None = None
36
+ name: str | None = None
37
+
38
+ function: Function | None = None
38
39
 
40
+ type: ta.Literal['function'] = dc.xfield('function', repr=False)
39
41
 
40
- class ChatCompletionChunkChoiceLogprobs(ta.TypedDict, total=False):
41
- content: ta.Sequence[ChatCompletionTokenLogprob]
42
- refusal: ta.Sequence[ChatCompletionTokenLogprob]
42
+ tool_calls: ta.Sequence[ToolCall] | None = None
43
+
44
+
45
+ #
43
46
 
44
47
 
45
- class ChatCompletionChunkChoice(ta.TypedDict):
48
+ @dc.dataclass(frozen=True, kw_only=True)
49
+ class ChatCompletionChunkChoice(lang.Final):
46
50
  delta: ChatCompletionChunkChoiceDelta
47
- finish_reason: ta.NotRequired[ta.Literal[
51
+
52
+ finish_reason: ta.Literal[
48
53
  'stop',
49
54
  'length',
50
55
  'tool_calls',
51
56
  'content_filter',
52
- ]]
57
+ ] | None = None
58
+
53
59
  index: int
54
- logprobs: ta.NotRequired[ChatCompletionChunkChoiceLogprobs]
60
+
61
+ @dc.dataclass(frozen=True, kw_only=True)
62
+ class Logprobs(lang.Final):
63
+ content: ta.Sequence[ChatCompletionTokenLogprob] | None = None
64
+ refusal: ta.Sequence[ChatCompletionTokenLogprob] | None = None
65
+
66
+ logprobs: Logprobs | None = None
55
67
 
56
68
 
57
69
  #
58
70
 
59
71
 
60
- class ChatCompletionChunk(ta.TypedDict):
72
+ @dc.dataclass(frozen=True, kw_only=True)
73
+ class ChatCompletionChunk(lang.Final):
61
74
  id: str
75
+
62
76
  choices: ta.Sequence[ChatCompletionChunkChoice]
77
+
63
78
  created: int
79
+
64
80
  model: str
65
- object: ta.Literal['chat.completion.chunk']
66
- service_tier: ta.NotRequired[ta.Literal[
81
+
82
+ object: ta.Literal['chat.completion.chunk'] = dc.xfield('chat.completion.chunk', repr=False)
83
+
84
+ service_tier: ta.Literal[
67
85
  'auto',
68
86
  'default',
69
87
  'flex',
70
- ]]
71
- system_fingerprint: ta.NotRequired[str]
88
+ ] | None = None
89
+
90
+ system_fingerprint: str | None = None
91
+
92
+ usage: CompletionUsage | None = None
93
+
94
+ obfuscation: str | None = None
@@ -1,77 +1,74 @@
1
- # ruff: noqa: UP007 UP045
2
1
  import typing as ta
3
2
 
3
+ from omlish import dataclasses as dc
4
+ from omlish import lang
5
+
4
6
 
5
7
  ##
6
8
 
7
9
 
8
- class TextChatCompletionContentPart(ta.TypedDict):
9
- text: str
10
- type: ta.Literal['text']
10
+ class ChatCompletionContentPart(lang.Abstract):
11
+ pass
11
12
 
12
13
 
13
14
  #
14
15
 
15
16
 
16
- class ImageChatCompletionContentPartImageUrl(ta.TypedDict):
17
- url: ta.Required[str]
18
- detail: ta.NotRequired[ta.Literal[
19
- 'auto',
20
- 'low',
21
- 'high',
22
- ]]
23
-
24
-
25
- class ImageChatCompletionContentPart(ta.TypedDict):
26
- image_url: ImageChatCompletionContentPartImageUrl
27
- type: ta.Literal['image_url']
17
+ @dc.dataclass(frozen=True, kw_only=True)
18
+ class TextChatCompletionContentPart(ChatCompletionContentPart, lang.Final):
19
+ text: str
28
20
 
29
21
 
30
22
  #
31
23
 
32
24
 
33
- class FileChatCompletionContentPartFileInfo(ta.TypedDict, total=False):
34
- file_data: str
35
- file_id: str
36
- filename: str
25
+ @dc.dataclass(frozen=True, kw_only=True)
26
+ class ImageUrlChatCompletionContentPart(ChatCompletionContentPart, lang.Final):
27
+ @dc.dataclass(frozen=True, kw_only=True)
28
+ class ImageUrl(lang.Final):
29
+ url: str
30
+ detail: ta.Literal[
31
+ 'auto',
32
+ 'low',
33
+ 'high',
34
+ ]
37
35
 
38
-
39
- class FileChatCompletionContentPart(ta.TypedDict):
40
- file: FileChatCompletionContentPartFileInfo
41
- type: ta.Literal['file']
36
+ image_url: ImageUrl
42
37
 
43
38
 
44
39
  #
45
40
 
46
41
 
47
- class InputAudioChatCompletionContentPartInputAudio(ta.TypedDict):
48
- data: str
49
- format: ta.Literal[
50
- 'wav',
51
- 'mp3',
52
- ]
53
-
42
+ @dc.dataclass(frozen=True, kw_only=True)
43
+ class FileChatCompletionContentPart(ChatCompletionContentPart, lang.Final):
44
+ @dc.dataclass(frozen=True, kw_only=True)
45
+ class File(lang.Final):
46
+ file_data: str | None = None
47
+ file_id: str | None = None
48
+ filename: str | None = None
54
49
 
55
- class InputAudioChatCompletionContentPart(ta.TypedDict):
56
- input_audio: InputAudioChatCompletionContentPartInputAudio
57
- type: ta.Literal['input_audio']
50
+ file: File
58
51
 
59
52
 
60
53
  #
61
54
 
62
55
 
63
- class RefusalChatCompletionContentPart(ta.TypedDict):
64
- refusal: str
65
- type: ta.Literal['refusal']
56
+ @dc.dataclass(frozen=True, kw_only=True)
57
+ class InputAudioChatCompletionContentPart(ChatCompletionContentPart, lang.Final):
58
+ @dc.dataclass(frozen=True, kw_only=True)
59
+ class InputAudio(lang.Final):
60
+ data: str
61
+ format: ta.Literal[
62
+ 'wav',
63
+ 'mp3',
64
+ ]
65
+
66
+ input_audio: InputAudio
66
67
 
67
68
 
68
69
  #
69
70
 
70
71
 
71
- ChatCompletionContentPart: ta.TypeAlias = ta.Union[
72
- TextChatCompletionContentPart,
73
- ImageChatCompletionContentPart,
74
- FileChatCompletionContentPart,
75
- InputAudioChatCompletionContentPart,
76
- RefusalChatCompletionContentPart,
77
- ]
72
+ @dc.dataclass(frozen=True, kw_only=True)
73
+ class RefusalChatCompletionContentPart(ChatCompletionContentPart, lang.Final):
74
+ refusal: str
@@ -1,6 +1,8 @@
1
- # ruff: noqa: UP007 UP045
2
1
  import typing as ta
3
2
 
3
+ from omlish import dataclasses as dc
4
+ from omlish import lang
5
+
4
6
  from .contentpart import ChatCompletionContentPart
5
7
  from .contentpart import RefusalChatCompletionContentPart
6
8
  from .contentpart import TextChatCompletionContentPart
@@ -9,83 +11,83 @@ from .contentpart import TextChatCompletionContentPart
9
11
  ##
10
12
 
11
13
 
12
- class DeveloperChatCompletionMessage(ta.TypedDict):
14
+ class ChatCompletionMessage(lang.Abstract, lang.Sealed):
15
+ pass
16
+
17
+
18
+ #
19
+
20
+
21
+ @dc.dataclass(frozen=True, kw_only=True)
22
+ class DeveloperChatCompletionMessage(ChatCompletionMessage, lang.Final):
13
23
  content: str | ta.Iterable[TextChatCompletionContentPart]
14
- role: ta.Literal['developer']
15
- name: ta.NotRequired[str]
24
+ name: str | None = None
16
25
 
17
26
 
18
27
  #
19
28
 
20
29
 
21
- class SystemChatCompletionMessage(ta.TypedDict):
30
+ @dc.dataclass(frozen=True, kw_only=True)
31
+ class SystemChatCompletionMessage(ChatCompletionMessage, lang.Final):
22
32
  content: str | ta.Iterable[TextChatCompletionContentPart]
23
- role: ta.Literal['system']
24
- name: ta.NotRequired[str]
33
+ name: str | None = None
25
34
 
26
35
 
27
36
  #
28
37
 
29
38
 
30
- class UserChatCompletionMessage(ta.TypedDict):
39
+ @dc.dataclass(frozen=True, kw_only=True)
40
+ class UserChatCompletionMessage(ChatCompletionMessage, lang.Final):
31
41
  content: str | ta.Iterable[ChatCompletionContentPart]
32
- role: ta.Literal['user']
33
- name: ta.NotRequired[str]
42
+ name: str | None = None
34
43
 
35
44
 
36
45
  #
37
46
 
38
47
 
39
- class AssistantChatCompletionMessageAudio(ta.TypedDict):
40
- id: str
48
+ @dc.dataclass(frozen=True, kw_only=True)
49
+ class AssistantChatCompletionMessage(ChatCompletionMessage, lang.Final):
50
+ @dc.dataclass(frozen=True, kw_only=True)
51
+ class Audio(lang.Final):
52
+ id: str
41
53
 
54
+ audio: Audio | None = None
42
55
 
43
- class AssistantChatCompletionMessageToolCallFunction(ta.TypedDict):
44
- arguments: str
45
- name: str
56
+ content: str | ta.Iterable[TextChatCompletionContentPart | RefusalChatCompletionContentPart] | None = None
46
57
 
58
+ name: str | None = None
47
59
 
48
- class AssistantChatCompletionMessageToolCall(ta.TypedDict):
49
- id: str
50
- function: AssistantChatCompletionMessageToolCallFunction
51
- type: ta.Literal['function']
60
+ refusal: str | None = None
52
61
 
62
+ @dc.dataclass(frozen=True, kw_only=True)
63
+ class ToolCall(lang.Final):
64
+ id: str
53
65
 
54
- class AssistantChatCompletionMessage(ta.TypedDict, total=False):
55
- role: ta.Required[ta.Literal['assistant']]
56
- audio: AssistantChatCompletionMessageAudio
57
- content: str | ta.Iterable[TextChatCompletionContentPart | RefusalChatCompletionContentPart]
58
- name: str
59
- refusal: str
60
- tool_calls: ta.Iterable[AssistantChatCompletionMessageToolCall]
66
+ @dc.dataclass(frozen=True, kw_only=True)
67
+ class Function(lang.Final):
68
+ arguments: str
69
+ name: str
70
+
71
+ function: Function
72
+
73
+ type: ta.Literal['function'] = dc.xfield('function', repr=False)
74
+
75
+ tool_calls: ta.Iterable[ToolCall] | None = None
61
76
 
62
77
 
63
78
  #
64
79
 
65
80
 
66
- class ToolChatCompletionMessage(ta.TypedDict):
81
+ @dc.dataclass(frozen=True, kw_only=True)
82
+ class ToolChatCompletionMessage(ChatCompletionMessage, lang.Final):
67
83
  content: str | ta.Iterable[TextChatCompletionContentPart]
68
- role: ta.Literal['tool']
69
84
  tool_call_id: str
70
85
 
71
86
 
72
87
  #
73
88
 
74
89
 
75
- class FunctionChatCompletionMessage(ta.TypedDict):
90
+ @dc.dataclass(frozen=True, kw_only=True)
91
+ class FunctionChatCompletionMessage(ChatCompletionMessage, lang.Final):
76
92
  content: str | None
77
93
  name: str
78
- role: ta.Literal['function']
79
-
80
-
81
- #
82
-
83
-
84
- ChatCompletionMessage: ta.TypeAlias = ta.Union[
85
- DeveloperChatCompletionMessage,
86
- SystemChatCompletionMessage,
87
- UserChatCompletionMessage,
88
- AssistantChatCompletionMessage,
89
- ToolChatCompletionMessage,
90
- FunctionChatCompletionMessage,
91
- ]