ommlds 0.0.0.dev331__py3-none-any.whl → 0.0.0.dev332__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.
- ommlds/.manifests.json +3 -3
- ommlds/backends/openai/__init__.py +0 -0
- ommlds/backends/openai/protocol/__init__.py +110 -0
- ommlds/backends/openai/protocol/chatcompletion/__init__.py +0 -0
- ommlds/backends/openai/protocol/chatcompletion/chunk.py +71 -0
- ommlds/backends/openai/protocol/chatcompletion/contentpart.py +77 -0
- ommlds/backends/openai/protocol/chatcompletion/message.py +91 -0
- ommlds/backends/openai/protocol/chatcompletion/request.py +140 -0
- ommlds/backends/openai/protocol/chatcompletion/response.py +90 -0
- ommlds/backends/openai/protocol/chatcompletion/responseformat.py +41 -0
- ommlds/backends/openai/protocol/chatcompletion/tokenlogprob.py +17 -0
- ommlds/backends/openai/protocol/completionusage.py +24 -0
- ommlds/cli/sessions/chat.py +57 -54
- ommlds/minichain/__init__.py +19 -2
- ommlds/minichain/backends/llamacpp/streaming.py +18 -14
- ommlds/minichain/backends/openai/format.py +15 -14
- ommlds/minichain/backends/openai/streaming.py +12 -12
- ommlds/minichain/chat/streaming.py +9 -3
- ommlds/minichain/resources.py +9 -2
- ommlds/minichain/services/facades.py +17 -19
- ommlds/minichain/services/requests.py +4 -0
- ommlds/minichain/services/responses.py +4 -0
- ommlds/minichain/streaming.py +63 -0
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/METADATA +3 -3
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/RECORD +29 -17
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev331.dist-info → ommlds-0.0.0.dev332.dist-info}/top_level.txt +0 -0
ommlds/.manifests.json
CHANGED
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"module": ".minichain.backends.llamacpp.streaming",
|
|
96
96
|
"attr": null,
|
|
97
97
|
"file": "ommlds/minichain/backends/llamacpp/streaming.py",
|
|
98
|
-
"line":
|
|
98
|
+
"line": 28,
|
|
99
99
|
"value": {
|
|
100
100
|
"$.minichain.registry.RegistryManifest": {
|
|
101
101
|
"mod_name": "ommlds.minichain.backends.llamacpp.streaming",
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"module": ".minichain.backends.openai.streaming",
|
|
186
186
|
"attr": null,
|
|
187
187
|
"file": "ommlds/minichain/backends/openai/streaming.py",
|
|
188
|
-
"line":
|
|
188
|
+
"line": 28,
|
|
189
189
|
"value": {
|
|
190
190
|
"$.minichain.registry.RegistryManifest": {
|
|
191
191
|
"mod_name": "ommlds.minichain.backends.openai.streaming",
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
"module": ".minichain.chat.streaming",
|
|
279
279
|
"attr": null,
|
|
280
280
|
"file": "ommlds/minichain/chat/streaming.py",
|
|
281
|
-
"line":
|
|
281
|
+
"line": 27,
|
|
282
282
|
"value": {
|
|
283
283
|
"$.minichain.registry.RegistryTypeManifest": {
|
|
284
284
|
"mod_name": "ommlds.minichain.chat.streaming",
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""
|
|
2
|
+
https://platform.openai.com/docs/api-reference/introduction
|
|
3
|
+
https://github.com/openai/openai-openapi/blob/master/openapi.yaml
|
|
4
|
+
"""
|
|
5
|
+
# ruff: noqa: I001
|
|
6
|
+
|
|
7
|
+
from .chatcompletion.chunk import ( # noqa
|
|
8
|
+
ChatCompletionChunkChoiceDeltaToolCallFunction,
|
|
9
|
+
ChatCompletionChunkChoiceDeltaToolCall,
|
|
10
|
+
ChatCompletionChunkChoiceDelta,
|
|
11
|
+
|
|
12
|
+
ChatCompletionChunkChoiceLogprobs,
|
|
13
|
+
ChatCompletionChunkChoice,
|
|
14
|
+
|
|
15
|
+
ChatCompletionChunk,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from .chatcompletion.contentpart import ( # noqa
|
|
19
|
+
TextChatCompletionContentPart,
|
|
20
|
+
|
|
21
|
+
ImageChatCompletionContentPartImageUrl,
|
|
22
|
+
ImageChatCompletionContentPart,
|
|
23
|
+
|
|
24
|
+
FileChatCompletionContentPartFileInfo,
|
|
25
|
+
FileChatCompletionContentPart,
|
|
26
|
+
|
|
27
|
+
InputAudioChatCompletionContentPartInputAudio,
|
|
28
|
+
InputAudioChatCompletionContentPart,
|
|
29
|
+
|
|
30
|
+
RefusalChatCompletionContentPart,
|
|
31
|
+
|
|
32
|
+
ChatCompletionContentPart,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from .chatcompletion.message import ( # noqa
|
|
36
|
+
DeveloperChatCompletionMessage,
|
|
37
|
+
|
|
38
|
+
SystemChatCompletionMessage,
|
|
39
|
+
|
|
40
|
+
UserChatCompletionMessage,
|
|
41
|
+
|
|
42
|
+
AssistantChatCompletionMessageAudio,
|
|
43
|
+
AssistantChatCompletionMessageToolCallFunction,
|
|
44
|
+
AssistantChatCompletionMessageToolCall,
|
|
45
|
+
AssistantChatCompletionMessage,
|
|
46
|
+
|
|
47
|
+
ToolChatCompletionMessage,
|
|
48
|
+
|
|
49
|
+
FunctionChatCompletionMessage,
|
|
50
|
+
|
|
51
|
+
ChatCompletionMessage,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
from .chatcompletion.request import ( # noqa
|
|
55
|
+
ChatCompletionRequestWebSearchOptionsUserLocationApproximate,
|
|
56
|
+
ChatCompletionRequestWebSearchOptionsUserLocation,
|
|
57
|
+
ChatCompletionRequestWebSearchOptions,
|
|
58
|
+
|
|
59
|
+
ChatCompletionRequestPrediction,
|
|
60
|
+
|
|
61
|
+
ChatCompletionRequestToolFunction,
|
|
62
|
+
ChatCompletionRequestTool,
|
|
63
|
+
|
|
64
|
+
ChatCompletionRequestStreamOptions,
|
|
65
|
+
|
|
66
|
+
ChatCompletionRequestNamedToolChoiceFunction,
|
|
67
|
+
ChatCompletionRequestNamedToolChoice,
|
|
68
|
+
|
|
69
|
+
ChatCompletionRequestAudio,
|
|
70
|
+
|
|
71
|
+
ChatCompletionRequest,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
from .chatcompletion.response import ( # noqa
|
|
75
|
+
ChatCompletionResponseAnnotationUrlCitation,
|
|
76
|
+
ChatCompletionResponseAnnotation,
|
|
77
|
+
|
|
78
|
+
ChatCompletionResponseAudio,
|
|
79
|
+
|
|
80
|
+
ChatCompletionResponseMessageToolCallFunction,
|
|
81
|
+
ChatCompletionResponseMessageToolCall,
|
|
82
|
+
ChatCompletionResponseMessage,
|
|
83
|
+
|
|
84
|
+
ChatCompletionResponseChoiceLogprobs,
|
|
85
|
+
ChatCompletionResponseChoice,
|
|
86
|
+
|
|
87
|
+
ChatCompletionResponse,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
from .chatcompletion.responseformat import ( # noqa
|
|
91
|
+
TextChatCompletionResponseFormat,
|
|
92
|
+
|
|
93
|
+
JsonSchemaChatCompletionResponseFormatJsonSchema,
|
|
94
|
+
JsonSchemaChatCompletionResponseFormat,
|
|
95
|
+
|
|
96
|
+
JsonObjectChatCompletionResponseFormat,
|
|
97
|
+
|
|
98
|
+
ChatCompletionResponseFormat,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
from .chatcompletion.tokenlogprob import ( # noqa
|
|
102
|
+
ChatCompletionTokenLogprobTopLogprob,
|
|
103
|
+
ChatCompletionTokenLogprob,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
from .completionusage import ( # noqa
|
|
107
|
+
CompletionUsageCompletionTokensDetails,
|
|
108
|
+
CompletionUsagePromptTokensDetails,
|
|
109
|
+
CompletionUsage,
|
|
110
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from .tokenlogprob import ChatCompletionTokenLogprob
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
|
|
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
|
+
#
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ChatCompletionChunkChoiceDelta(ta.TypedDict, total=False):
|
|
25
|
+
content: str
|
|
26
|
+
refusal: str
|
|
27
|
+
role: ta.Literal[
|
|
28
|
+
'developer',
|
|
29
|
+
'system',
|
|
30
|
+
'user',
|
|
31
|
+
'assistant',
|
|
32
|
+
'tool',
|
|
33
|
+
]
|
|
34
|
+
tool_calls: ta.Sequence[ChatCompletionChunkChoiceDeltaToolCall]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ChatCompletionChunkChoiceLogprobs(ta.TypedDict, total=False):
|
|
41
|
+
content: ta.Sequence[ChatCompletionTokenLogprob]
|
|
42
|
+
refusal: ta.Sequence[ChatCompletionTokenLogprob]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ChatCompletionChunkChoice(ta.TypedDict):
|
|
46
|
+
delta: ChatCompletionChunkChoiceDelta
|
|
47
|
+
finish_reason: ta.NotRequired[ta.Literal[
|
|
48
|
+
'stop',
|
|
49
|
+
'length',
|
|
50
|
+
'tool_calls',
|
|
51
|
+
'content_filter',
|
|
52
|
+
]]
|
|
53
|
+
index: int
|
|
54
|
+
logprobs: ta.NotRequired[ChatCompletionChunkChoiceLogprobs]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ChatCompletionChunk(ta.TypedDict):
|
|
61
|
+
id: str
|
|
62
|
+
choices: ta.Sequence[ChatCompletionChunkChoice]
|
|
63
|
+
created: int
|
|
64
|
+
model: str
|
|
65
|
+
object: ta.Literal['chat.completion.chunk']
|
|
66
|
+
service_tier: ta.NotRequired[ta.Literal[
|
|
67
|
+
'auto',
|
|
68
|
+
'default',
|
|
69
|
+
'flex',
|
|
70
|
+
]]
|
|
71
|
+
system_fingerprint: ta.NotRequired[str]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# ruff: noqa: UP007
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TextChatCompletionContentPart(ta.TypedDict):
|
|
9
|
+
text: str
|
|
10
|
+
type: ta.Literal['text']
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
|
|
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']
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class FileChatCompletionContentPartFileInfo(ta.TypedDict, total=False):
|
|
34
|
+
file_data: str
|
|
35
|
+
file_id: str
|
|
36
|
+
filename: str
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class FileChatCompletionContentPart(ta.TypedDict):
|
|
40
|
+
file: FileChatCompletionContentPartFileInfo
|
|
41
|
+
type: ta.Literal['file']
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class InputAudioChatCompletionContentPartInputAudio(ta.TypedDict):
|
|
48
|
+
data: str
|
|
49
|
+
format: ta.Literal[
|
|
50
|
+
'wav',
|
|
51
|
+
'mp3',
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class InputAudioChatCompletionContentPart(ta.TypedDict):
|
|
56
|
+
input_audio: InputAudioChatCompletionContentPartInputAudio
|
|
57
|
+
type: ta.Literal['input_audio']
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class RefusalChatCompletionContentPart(ta.TypedDict):
|
|
64
|
+
refusal: str
|
|
65
|
+
type: ta.Literal['refusal']
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
#
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
ChatCompletionContentPart: ta.TypeAlias = ta.Union[
|
|
72
|
+
TextChatCompletionContentPart,
|
|
73
|
+
ImageChatCompletionContentPart,
|
|
74
|
+
FileChatCompletionContentPart,
|
|
75
|
+
InputAudioChatCompletionContentPart,
|
|
76
|
+
RefusalChatCompletionContentPart,
|
|
77
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# ruff: noqa: UP007
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
from .contentpart import ChatCompletionContentPart
|
|
5
|
+
from .contentpart import RefusalChatCompletionContentPart
|
|
6
|
+
from .contentpart import TextChatCompletionContentPart
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DeveloperChatCompletionMessage(ta.TypedDict):
|
|
13
|
+
content: str | ta.Iterable[TextChatCompletionContentPart]
|
|
14
|
+
role: ta.Literal['developer']
|
|
15
|
+
name: ta.NotRequired[str]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SystemChatCompletionMessage(ta.TypedDict):
|
|
22
|
+
content: str | ta.Iterable[TextChatCompletionContentPart]
|
|
23
|
+
role: ta.Literal['system']
|
|
24
|
+
name: ta.NotRequired[str]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class UserChatCompletionMessage(ta.TypedDict):
|
|
31
|
+
content: str | ta.Iterable[ChatCompletionContentPart]
|
|
32
|
+
role: ta.Literal['user']
|
|
33
|
+
name: ta.NotRequired[str]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AssistantChatCompletionMessageAudio(ta.TypedDict):
|
|
40
|
+
id: str
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AssistantChatCompletionMessageToolCallFunction(ta.TypedDict):
|
|
44
|
+
arguments: str
|
|
45
|
+
name: str
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AssistantChatCompletionMessageToolCall(ta.TypedDict):
|
|
49
|
+
id: str
|
|
50
|
+
function: AssistantChatCompletionMessageToolCallFunction
|
|
51
|
+
type: ta.Literal['function']
|
|
52
|
+
|
|
53
|
+
|
|
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]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class ToolChatCompletionMessage(ta.TypedDict):
|
|
67
|
+
content: str | ta.Iterable[TextChatCompletionContentPart]
|
|
68
|
+
role: ta.Literal['tool']
|
|
69
|
+
tool_call_id: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class FunctionChatCompletionMessage(ta.TypedDict):
|
|
76
|
+
content: str | None
|
|
77
|
+
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
|
+
]
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# ruff: noqa: UP007
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
from .contentpart import TextChatCompletionContentPart
|
|
5
|
+
from .message import ChatCompletionMessage
|
|
6
|
+
from .responseformat import ChatCompletionResponseFormat
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChatCompletionRequestWebSearchOptionsUserLocationApproximate(ta.TypedDict, total=False):
|
|
13
|
+
city: str
|
|
14
|
+
country: str
|
|
15
|
+
region: str
|
|
16
|
+
timezone: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ChatCompletionRequestWebSearchOptionsUserLocation(ta.TypedDict):
|
|
20
|
+
approximate: ChatCompletionRequestWebSearchOptionsUserLocationApproximate
|
|
21
|
+
type: ta.Literal['approximate']
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ChatCompletionRequestWebSearchOptions(ta.TypedDict, total=False):
|
|
25
|
+
search_context_size: ta.Literal[
|
|
26
|
+
'low',
|
|
27
|
+
'medium',
|
|
28
|
+
'high',
|
|
29
|
+
]
|
|
30
|
+
user_location: ChatCompletionRequestWebSearchOptionsUserLocation
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ChatCompletionRequestPrediction(ta.TypedDict):
|
|
37
|
+
content: str | ta.Iterable[TextChatCompletionContentPart]
|
|
38
|
+
type: ta.Literal['content']
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ChatCompletionRequestToolFunction(ta.TypedDict, total=False):
|
|
45
|
+
name: ta.Required[str]
|
|
46
|
+
description: str
|
|
47
|
+
parameters: ta.Mapping[str, ta.Any]
|
|
48
|
+
strict: bool
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ChatCompletionRequestTool(ta.TypedDict):
|
|
52
|
+
function: ChatCompletionRequestToolFunction
|
|
53
|
+
type: ta.Literal['function']
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ChatCompletionRequestStreamOptions(ta.TypedDict, total=False):
|
|
60
|
+
include_usage: bool
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class ChatCompletionRequestNamedToolChoiceFunction(ta.TypedDict):
|
|
67
|
+
name: str
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ChatCompletionRequestNamedToolChoice(ta.TypedDict):
|
|
71
|
+
function: ChatCompletionRequestNamedToolChoiceFunction
|
|
72
|
+
type: ta.Literal['function']
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class ChatCompletionRequestAudio(ta.TypedDict):
|
|
79
|
+
format: ta.Literal[
|
|
80
|
+
'wav',
|
|
81
|
+
'aac',
|
|
82
|
+
'mp3',
|
|
83
|
+
'flac',
|
|
84
|
+
'opus',
|
|
85
|
+
'pcm16',
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
voice: str
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
#
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ChatCompletionRequest(ta.TypedDict, total=False):
|
|
95
|
+
messages: ta.Required[ta.Iterable[ChatCompletionMessage]]
|
|
96
|
+
model: ta.Required[str]
|
|
97
|
+
audio: ChatCompletionRequestAudio
|
|
98
|
+
frequency_penalty: float
|
|
99
|
+
logit_bias: ta.Mapping[str, int]
|
|
100
|
+
logprobs: bool
|
|
101
|
+
max_completion_tokens: int
|
|
102
|
+
max_tokens: int
|
|
103
|
+
metadata: ta.Mapping[str, str]
|
|
104
|
+
modalities: ta.Sequence[ta.Literal[
|
|
105
|
+
'text',
|
|
106
|
+
'audio',
|
|
107
|
+
]]
|
|
108
|
+
n: int
|
|
109
|
+
parallel_tool_calls: bool
|
|
110
|
+
prediction: ChatCompletionRequestPrediction
|
|
111
|
+
presence_penalty: float
|
|
112
|
+
reasoning_effort: ta.Literal[
|
|
113
|
+
'low',
|
|
114
|
+
'medium',
|
|
115
|
+
'high',
|
|
116
|
+
]
|
|
117
|
+
response_format: ChatCompletionResponseFormat
|
|
118
|
+
seed: int
|
|
119
|
+
service_tier: ta.Literal[
|
|
120
|
+
'auto',
|
|
121
|
+
'default',
|
|
122
|
+
'flex',
|
|
123
|
+
]
|
|
124
|
+
stop: ta.Union[str, ta.Sequence[str], None]
|
|
125
|
+
store: bool
|
|
126
|
+
stream_options: ChatCompletionRequestStreamOptions
|
|
127
|
+
temperature: float
|
|
128
|
+
tool_choice: ta.Union[
|
|
129
|
+
ta.Literal[
|
|
130
|
+
'none',
|
|
131
|
+
'auto',
|
|
132
|
+
'required',
|
|
133
|
+
],
|
|
134
|
+
ChatCompletionRequestNamedToolChoice,
|
|
135
|
+
]
|
|
136
|
+
tools: ta.Iterable[ChatCompletionRequestTool]
|
|
137
|
+
top_logprobs: int
|
|
138
|
+
top_p: float
|
|
139
|
+
user: str
|
|
140
|
+
web_search_options: ChatCompletionRequestWebSearchOptions
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from ..completionusage import CompletionUsage
|
|
4
|
+
from .tokenlogprob import ChatCompletionTokenLogprob
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ChatCompletionResponseAnnotationUrlCitation(ta.TypedDict):
|
|
11
|
+
end_index: int
|
|
12
|
+
start_index: int
|
|
13
|
+
title: str
|
|
14
|
+
url: str
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ChatCompletionResponseAnnotation(ta.TypedDict):
|
|
18
|
+
type: ta.Literal['url_citation']
|
|
19
|
+
url_citation: ChatCompletionResponseAnnotationUrlCitation
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ChatCompletionResponseAudio(ta.TypedDict):
|
|
26
|
+
id: str
|
|
27
|
+
data: str
|
|
28
|
+
expires_at: int
|
|
29
|
+
transcript: str
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ChatCompletionResponseMessageToolCallFunction(ta.TypedDict):
|
|
36
|
+
arguments: str
|
|
37
|
+
name: str
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ChatCompletionResponseMessageToolCall(ta.TypedDict):
|
|
41
|
+
id: str
|
|
42
|
+
function: ChatCompletionResponseMessageToolCallFunction
|
|
43
|
+
type: ta.Literal['function']
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ChatCompletionResponseMessage(ta.TypedDict, total=False):
|
|
47
|
+
content: str
|
|
48
|
+
refusal: str
|
|
49
|
+
role: ta.Required[ta.Literal['assistant']]
|
|
50
|
+
annotations: ta.Sequence[ChatCompletionResponseAnnotation]
|
|
51
|
+
audio: ChatCompletionResponseAudio
|
|
52
|
+
tool_calls: ta.Sequence[ChatCompletionResponseMessageToolCall]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class ChatCompletionResponseChoiceLogprobs(ta.TypedDict, total=False):
|
|
59
|
+
content: ta.Sequence[ChatCompletionTokenLogprob]
|
|
60
|
+
refusal: ta.Sequence[ChatCompletionTokenLogprob]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ChatCompletionResponseChoice(ta.TypedDict):
|
|
64
|
+
finish_reason: ta.Literal[
|
|
65
|
+
'stop',
|
|
66
|
+
'length',
|
|
67
|
+
'tool_calls',
|
|
68
|
+
'content_filter',
|
|
69
|
+
]
|
|
70
|
+
index: int
|
|
71
|
+
logprobs: ta.NotRequired[ChatCompletionResponseChoiceLogprobs]
|
|
72
|
+
message: ChatCompletionResponseMessage
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class ChatCompletionResponse(ta.TypedDict):
|
|
79
|
+
id: str
|
|
80
|
+
choices: ta.Sequence[ChatCompletionResponseChoice]
|
|
81
|
+
created: int
|
|
82
|
+
model: str
|
|
83
|
+
object: ta.Literal['chat.completion']
|
|
84
|
+
service_tier: ta.NotRequired[ta.Literal[
|
|
85
|
+
'auto',
|
|
86
|
+
'default',
|
|
87
|
+
'flex',
|
|
88
|
+
]]
|
|
89
|
+
system_fingerprint: ta.NotRequired[str]
|
|
90
|
+
usage: ta.NotRequired[CompletionUsage]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# ruff: noqa: UP007
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TextChatCompletionResponseFormat(ta.TypedDict):
|
|
9
|
+
type: ta.Literal['text']
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class JsonSchemaChatCompletionResponseFormatJsonSchema(ta.TypedDict, total=False):
|
|
16
|
+
name: ta.Required[str]
|
|
17
|
+
description: str
|
|
18
|
+
schema: ta.Mapping[str, ta.Any]
|
|
19
|
+
strict: bool
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class JsonSchemaChatCompletionResponseFormat(ta.TypedDict):
|
|
23
|
+
json_schema: JsonSchemaChatCompletionResponseFormatJsonSchema
|
|
24
|
+
type: ta.Literal['json_schema']
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class JsonObjectChatCompletionResponseFormat(ta.TypedDict):
|
|
31
|
+
type: ta.Literal['json_object']
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
ChatCompletionResponseFormat: ta.TypeAlias = ta.Union[
|
|
38
|
+
TextChatCompletionResponseFormat,
|
|
39
|
+
JsonSchemaChatCompletionResponseFormat,
|
|
40
|
+
JsonObjectChatCompletionResponseFormat,
|
|
41
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ChatCompletionTokenLogprobTopLogprob(ta.TypedDict):
|
|
8
|
+
token: str
|
|
9
|
+
bytes: ta.NotRequired[ta.Sequence[int]]
|
|
10
|
+
logprob: float
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ChatCompletionTokenLogprob(ta.TypedDict):
|
|
14
|
+
token: str
|
|
15
|
+
bytes: ta.NotRequired[ta.Sequence[int]]
|
|
16
|
+
logprob: float
|
|
17
|
+
top_logprobs: ta.Sequence[ChatCompletionTokenLogprobTopLogprob]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CompletionUsageCompletionTokensDetails(ta.TypedDict, total=False):
|
|
8
|
+
accepted_prediction_tokens: int
|
|
9
|
+
audio_tokens: int
|
|
10
|
+
reasoning_tokens: int
|
|
11
|
+
rejected_prediction_tokens: int
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CompletionUsagePromptTokensDetails(ta.TypedDict, total=False):
|
|
15
|
+
audio_tokens: int
|
|
16
|
+
cached_tokens: int
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CompletionUsage(ta.TypedDict):
|
|
20
|
+
completion_tokens: int
|
|
21
|
+
prompt_tokens: int
|
|
22
|
+
total_tokens: int
|
|
23
|
+
completion_tokens_details: ta.NotRequired[CompletionUsageCompletionTokensDetails]
|
|
24
|
+
prompt_tokens_details: ta.NotRequired[CompletionUsagePromptTokensDetails]
|