c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python 0.1.0a6__py3-none-any.whl → 0.1.0a8__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 (26) hide show
  1. {c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a6.dist-info → c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a8.dist-info}/METADATA +5 -5
  2. {c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a6.dist-info → c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a8.dist-info}/RECORD +25 -17
  3. gradientai/_client.py +16 -0
  4. gradientai/_streaming.py +40 -3
  5. gradientai/_version.py +1 -1
  6. gradientai/resources/agents/__init__.py +14 -0
  7. gradientai/resources/agents/agents.py +32 -0
  8. gradientai/resources/agents/chat/__init__.py +33 -0
  9. gradientai/resources/agents/chat/chat.py +102 -0
  10. gradientai/resources/agents/chat/completions.py +910 -0
  11. gradientai/resources/models.py +105 -77
  12. gradientai/types/__init__.py +3 -2
  13. gradientai/types/agents/chat/__init__.py +7 -0
  14. gradientai/types/agents/chat/chat_completion_chunk.py +93 -0
  15. gradientai/types/agents/chat/completion_create_params.py +200 -0
  16. gradientai/types/agents/chat/completion_create_response.py +81 -0
  17. gradientai/types/api_model.py +32 -0
  18. gradientai/types/chat/__init__.py +0 -1
  19. gradientai/types/chat/completion_create_response.py +1 -1
  20. gradientai/types/model_list_params.py +42 -0
  21. gradientai/types/model_list_response.py +8 -5
  22. gradientai/types/shared/__init__.py +1 -0
  23. gradientai/types/model.py +0 -21
  24. {c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a6.dist-info → c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a8.dist-info}/WHEEL +0 -0
  25. {c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a6.dist-info → c63a5cfe_b235_4fbe_8bbb_82a9e02a482a_python-0.1.0a8.dist-info}/licenses/LICENSE +0 -0
  26. /gradientai/types/{chat → shared}/chat_completion_token_logprob.py +0 -0
@@ -2,9 +2,14 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from typing import List
6
+ from typing_extensions import Literal
7
+
5
8
  import httpx
6
9
 
10
+ from ..types import model_list_params
7
11
  from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
12
+ from .._utils import maybe_transform, async_maybe_transform
8
13
  from .._compat import cached_property
9
14
  from .._resource import SyncAPIResource, AsyncAPIResource
10
15
  from .._response import (
@@ -13,7 +18,6 @@ from .._response import (
13
18
  async_to_raw_response_wrapper,
14
19
  async_to_streamed_response_wrapper,
15
20
  )
16
- from ..types.model import Model
17
21
  from .._base_client import make_request_options
18
22
  from ..types.model_list_response import ModelListResponse
19
23
 
@@ -40,22 +44,52 @@ class ModelsResource(SyncAPIResource):
40
44
  """
41
45
  return ModelsResourceWithStreamingResponse(self)
42
46
 
43
- def retrieve(
47
+ def list(
44
48
  self,
45
- model: str,
46
49
  *,
50
+ page: int | NotGiven = NOT_GIVEN,
51
+ per_page: int | NotGiven = NOT_GIVEN,
52
+ public_only: bool | NotGiven = NOT_GIVEN,
53
+ usecases: List[
54
+ Literal[
55
+ "MODEL_USECASE_UNKNOWN",
56
+ "MODEL_USECASE_AGENT",
57
+ "MODEL_USECASE_FINETUNED",
58
+ "MODEL_USECASE_KNOWLEDGEBASE",
59
+ "MODEL_USECASE_GUARDRAIL",
60
+ "MODEL_USECASE_REASONING",
61
+ "MODEL_USECASE_SERVERLESS",
62
+ ]
63
+ ]
64
+ | NotGiven = NOT_GIVEN,
47
65
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
48
66
  # The extra values given here take precedence over values defined on the client or passed to this method.
49
67
  extra_headers: Headers | None = None,
50
68
  extra_query: Query | None = None,
51
69
  extra_body: Body | None = None,
52
70
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
53
- ) -> Model:
71
+ ) -> ModelListResponse:
54
72
  """
55
- Retrieves a model instance, providing basic information about the model such as
56
- the owner and permissioning.
73
+ To list all models, send a GET request to `/v2/gen-ai/models`.
57
74
 
58
75
  Args:
76
+ page: page number.
77
+
78
+ per_page: items per page.
79
+
80
+ public_only: only include models that are publicly available.
81
+
82
+ usecases: include only models defined for the listed usecases.
83
+
84
+ - MODEL_USECASE_UNKNOWN: The use case of the model is unknown
85
+ - MODEL_USECASE_AGENT: The model maybe used in an agent
86
+ - MODEL_USECASE_FINETUNED: The model maybe used for fine tuning
87
+ - MODEL_USECASE_KNOWLEDGEBASE: The model maybe used for knowledge bases
88
+ (embedding models)
89
+ - MODEL_USECASE_GUARDRAIL: The model maybe used for guardrails
90
+ - MODEL_USECASE_REASONING: The model usecase for reasoning
91
+ - MODEL_USECASE_SERVERLESS: The model usecase for serverless inference
92
+
59
93
  extra_headers: Send extra headers
60
94
 
61
95
  extra_query: Add additional query parameters to the request
@@ -64,36 +98,24 @@ class ModelsResource(SyncAPIResource):
64
98
 
65
99
  timeout: Override the client-level default timeout for this request, in seconds
66
100
  """
67
- if not model:
68
- raise ValueError(f"Expected a non-empty value for `model` but received {model!r}")
69
101
  return self._get(
70
- f"/models/{model}"
102
+ "/v2/gen-ai/models"
71
103
  if self._client._base_url_overridden
72
- else f"https://inference.do-ai.run/v1/models/{model}",
104
+ else "https://api.digitalocean.com/v2/gen-ai/models",
73
105
  options=make_request_options(
74
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
75
- ),
76
- cast_to=Model,
77
- )
78
-
79
- def list(
80
- self,
81
- *,
82
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
83
- # The extra values given here take precedence over values defined on the client or passed to this method.
84
- extra_headers: Headers | None = None,
85
- extra_query: Query | None = None,
86
- extra_body: Body | None = None,
87
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
88
- ) -> ModelListResponse:
89
- """
90
- Lists the currently available models, and provides basic information about each
91
- one such as the owner and availability.
92
- """
93
- return self._get(
94
- "/models" if self._client._base_url_overridden else "https://inference.do-ai.run/v1/models",
95
- options=make_request_options(
96
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
106
+ extra_headers=extra_headers,
107
+ extra_query=extra_query,
108
+ extra_body=extra_body,
109
+ timeout=timeout,
110
+ query=maybe_transform(
111
+ {
112
+ "page": page,
113
+ "per_page": per_page,
114
+ "public_only": public_only,
115
+ "usecases": usecases,
116
+ },
117
+ model_list_params.ModelListParams,
118
+ ),
97
119
  ),
98
120
  cast_to=ModelListResponse,
99
121
  )
@@ -119,22 +141,52 @@ class AsyncModelsResource(AsyncAPIResource):
119
141
  """
120
142
  return AsyncModelsResourceWithStreamingResponse(self)
121
143
 
122
- async def retrieve(
144
+ async def list(
123
145
  self,
124
- model: str,
125
146
  *,
147
+ page: int | NotGiven = NOT_GIVEN,
148
+ per_page: int | NotGiven = NOT_GIVEN,
149
+ public_only: bool | NotGiven = NOT_GIVEN,
150
+ usecases: List[
151
+ Literal[
152
+ "MODEL_USECASE_UNKNOWN",
153
+ "MODEL_USECASE_AGENT",
154
+ "MODEL_USECASE_FINETUNED",
155
+ "MODEL_USECASE_KNOWLEDGEBASE",
156
+ "MODEL_USECASE_GUARDRAIL",
157
+ "MODEL_USECASE_REASONING",
158
+ "MODEL_USECASE_SERVERLESS",
159
+ ]
160
+ ]
161
+ | NotGiven = NOT_GIVEN,
126
162
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
127
163
  # The extra values given here take precedence over values defined on the client or passed to this method.
128
164
  extra_headers: Headers | None = None,
129
165
  extra_query: Query | None = None,
130
166
  extra_body: Body | None = None,
131
167
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
132
- ) -> Model:
168
+ ) -> ModelListResponse:
133
169
  """
134
- Retrieves a model instance, providing basic information about the model such as
135
- the owner and permissioning.
170
+ To list all models, send a GET request to `/v2/gen-ai/models`.
136
171
 
137
172
  Args:
173
+ page: page number.
174
+
175
+ per_page: items per page.
176
+
177
+ public_only: only include models that are publicly available.
178
+
179
+ usecases: include only models defined for the listed usecases.
180
+
181
+ - MODEL_USECASE_UNKNOWN: The use case of the model is unknown
182
+ - MODEL_USECASE_AGENT: The model maybe used in an agent
183
+ - MODEL_USECASE_FINETUNED: The model maybe used for fine tuning
184
+ - MODEL_USECASE_KNOWLEDGEBASE: The model maybe used for knowledge bases
185
+ (embedding models)
186
+ - MODEL_USECASE_GUARDRAIL: The model maybe used for guardrails
187
+ - MODEL_USECASE_REASONING: The model usecase for reasoning
188
+ - MODEL_USECASE_SERVERLESS: The model usecase for serverless inference
189
+
138
190
  extra_headers: Send extra headers
139
191
 
140
192
  extra_query: Add additional query parameters to the request
@@ -143,36 +195,24 @@ class AsyncModelsResource(AsyncAPIResource):
143
195
 
144
196
  timeout: Override the client-level default timeout for this request, in seconds
145
197
  """
146
- if not model:
147
- raise ValueError(f"Expected a non-empty value for `model` but received {model!r}")
148
198
  return await self._get(
149
- f"/models/{model}"
199
+ "/v2/gen-ai/models"
150
200
  if self._client._base_url_overridden
151
- else f"https://inference.do-ai.run/v1/models/{model}",
152
- options=make_request_options(
153
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
154
- ),
155
- cast_to=Model,
156
- )
157
-
158
- async def list(
159
- self,
160
- *,
161
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
162
- # The extra values given here take precedence over values defined on the client or passed to this method.
163
- extra_headers: Headers | None = None,
164
- extra_query: Query | None = None,
165
- extra_body: Body | None = None,
166
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
167
- ) -> ModelListResponse:
168
- """
169
- Lists the currently available models, and provides basic information about each
170
- one such as the owner and availability.
171
- """
172
- return await self._get(
173
- "/models" if self._client._base_url_overridden else "https://inference.do-ai.run/v1/models",
201
+ else "https://api.digitalocean.com/v2/gen-ai/models",
174
202
  options=make_request_options(
175
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
203
+ extra_headers=extra_headers,
204
+ extra_query=extra_query,
205
+ extra_body=extra_body,
206
+ timeout=timeout,
207
+ query=await async_maybe_transform(
208
+ {
209
+ "page": page,
210
+ "per_page": per_page,
211
+ "public_only": public_only,
212
+ "usecases": usecases,
213
+ },
214
+ model_list_params.ModelListParams,
215
+ ),
176
216
  ),
177
217
  cast_to=ModelListResponse,
178
218
  )
@@ -182,9 +222,6 @@ class ModelsResourceWithRawResponse:
182
222
  def __init__(self, models: ModelsResource) -> None:
183
223
  self._models = models
184
224
 
185
- self.retrieve = to_raw_response_wrapper(
186
- models.retrieve,
187
- )
188
225
  self.list = to_raw_response_wrapper(
189
226
  models.list,
190
227
  )
@@ -194,9 +231,6 @@ class AsyncModelsResourceWithRawResponse:
194
231
  def __init__(self, models: AsyncModelsResource) -> None:
195
232
  self._models = models
196
233
 
197
- self.retrieve = async_to_raw_response_wrapper(
198
- models.retrieve,
199
- )
200
234
  self.list = async_to_raw_response_wrapper(
201
235
  models.list,
202
236
  )
@@ -206,9 +240,6 @@ class ModelsResourceWithStreamingResponse:
206
240
  def __init__(self, models: ModelsResource) -> None:
207
241
  self._models = models
208
242
 
209
- self.retrieve = to_streamed_response_wrapper(
210
- models.retrieve,
211
- )
212
243
  self.list = to_streamed_response_wrapper(
213
244
  models.list,
214
245
  )
@@ -218,9 +249,6 @@ class AsyncModelsResourceWithStreamingResponse:
218
249
  def __init__(self, models: AsyncModelsResource) -> None:
219
250
  self._models = models
220
251
 
221
- self.retrieve = async_to_streamed_response_wrapper(
222
- models.retrieve,
223
- )
224
252
  self.list = async_to_streamed_response_wrapper(
225
253
  models.list,
226
254
  )
@@ -2,14 +2,15 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from .model import Model as Model
6
- from .shared import APIMeta as APIMeta, APILinks as APILinks
5
+ from .shared import APIMeta as APIMeta, APILinks as APILinks, ChatCompletionTokenLogprob as ChatCompletionTokenLogprob
7
6
  from .api_agent import APIAgent as APIAgent
7
+ from .api_model import APIModel as APIModel
8
8
  from .api_agreement import APIAgreement as APIAgreement
9
9
  from .api_workspace import APIWorkspace as APIWorkspace
10
10
  from .api_agent_model import APIAgentModel as APIAgentModel
11
11
  from .agent_list_params import AgentListParams as AgentListParams
12
12
  from .api_model_version import APIModelVersion as APIModelVersion
13
+ from .model_list_params import ModelListParams as ModelListParams
13
14
  from .api_knowledge_base import APIKnowledgeBase as APIKnowledgeBase
14
15
  from .region_list_params import RegionListParams as RegionListParams
15
16
  from .agent_create_params import AgentCreateParams as AgentCreateParams
@@ -0,0 +1,7 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from .chat_completion_chunk import ChatCompletionChunk as ChatCompletionChunk
6
+ from .completion_create_params import CompletionCreateParams as CompletionCreateParams
7
+ from .completion_create_response import CompletionCreateResponse as CompletionCreateResponse
@@ -0,0 +1,93 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List, Optional
4
+ from typing_extensions import Literal
5
+
6
+ from ...._models import BaseModel
7
+ from ...shared.chat_completion_token_logprob import ChatCompletionTokenLogprob
8
+
9
+ __all__ = ["ChatCompletionChunk", "Choice", "ChoiceDelta", "ChoiceLogprobs", "Usage"]
10
+
11
+
12
+ class ChoiceDelta(BaseModel):
13
+ content: Optional[str] = None
14
+ """The contents of the chunk message."""
15
+
16
+ refusal: Optional[str] = None
17
+ """The refusal message generated by the model."""
18
+
19
+ role: Optional[Literal["developer", "user", "assistant"]] = None
20
+ """The role of the author of this message."""
21
+
22
+
23
+ class ChoiceLogprobs(BaseModel):
24
+ content: Optional[List[ChatCompletionTokenLogprob]] = None
25
+ """A list of message content tokens with log probability information."""
26
+
27
+ refusal: Optional[List[ChatCompletionTokenLogprob]] = None
28
+ """A list of message refusal tokens with log probability information."""
29
+
30
+
31
+ class Choice(BaseModel):
32
+ delta: ChoiceDelta
33
+ """A chat completion delta generated by streamed model responses."""
34
+
35
+ finish_reason: Optional[Literal["stop", "length"]] = None
36
+ """The reason the model stopped generating tokens.
37
+
38
+ This will be `stop` if the model hit a natural stop point or a provided stop
39
+ sequence, or `length` if the maximum number of tokens specified in the request
40
+ was reached
41
+ """
42
+
43
+ index: int
44
+ """The index of the choice in the list of choices."""
45
+
46
+ logprobs: Optional[ChoiceLogprobs] = None
47
+ """Log probability information for the choice."""
48
+
49
+
50
+ class Usage(BaseModel):
51
+ completion_tokens: int
52
+ """Number of tokens in the generated completion."""
53
+
54
+ prompt_tokens: int
55
+ """Number of tokens in the prompt."""
56
+
57
+ total_tokens: int
58
+ """Total number of tokens used in the request (prompt + completion)."""
59
+
60
+
61
+ class ChatCompletionChunk(BaseModel):
62
+ id: str
63
+ """A unique identifier for the chat completion. Each chunk has the same ID."""
64
+
65
+ choices: List[Choice]
66
+ """A list of chat completion choices.
67
+
68
+ Can contain more than one elements if `n` is greater than 1. Can also be empty
69
+ for the last chunk if you set `stream_options: {"include_usage": true}`.
70
+ """
71
+
72
+ created: int
73
+ """The Unix timestamp (in seconds) of when the chat completion was created.
74
+
75
+ Each chunk has the same timestamp.
76
+ """
77
+
78
+ model: str
79
+ """The model to generate the completion."""
80
+
81
+ object: Literal["chat.completion.chunk"]
82
+ """The object type, which is always `chat.completion.chunk`."""
83
+
84
+ usage: Optional[Usage] = None
85
+ """
86
+ An optional field that will only be present when you set
87
+ `stream_options: {"include_usage": true}` in your request. When present, it
88
+ contains a null value **except for the last chunk** which contains the token
89
+ usage statistics for the entire request.
90
+
91
+ **NOTE:** If the stream is interrupted or cancelled, you may not receive the
92
+ final usage chunk which contains the total token usage for the request.
93
+ """
@@ -0,0 +1,200 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Dict, List, Union, Iterable, Optional
6
+ from typing_extensions import Literal, Required, TypeAlias, TypedDict
7
+
8
+ __all__ = [
9
+ "CompletionCreateParamsBase",
10
+ "Message",
11
+ "MessageChatCompletionRequestSystemMessage",
12
+ "MessageChatCompletionRequestDeveloperMessage",
13
+ "MessageChatCompletionRequestUserMessage",
14
+ "MessageChatCompletionRequestAssistantMessage",
15
+ "StreamOptions",
16
+ "CompletionCreateParamsNonStreaming",
17
+ "CompletionCreateParamsStreaming",
18
+ ]
19
+
20
+
21
+ class CompletionCreateParamsBase(TypedDict, total=False):
22
+ messages: Required[Iterable[Message]]
23
+ """A list of messages comprising the conversation so far."""
24
+
25
+ model: Required[str]
26
+ """Model ID used to generate the response."""
27
+
28
+ frequency_penalty: Optional[float]
29
+ """Number between -2.0 and 2.0.
30
+
31
+ Positive values penalize new tokens based on their existing frequency in the
32
+ text so far, decreasing the model's likelihood to repeat the same line verbatim.
33
+ """
34
+
35
+ logit_bias: Optional[Dict[str, int]]
36
+ """Modify the likelihood of specified tokens appearing in the completion.
37
+
38
+ Accepts a JSON object that maps tokens (specified by their token ID in the
39
+ tokenizer) to an associated bias value from -100 to 100. Mathematically, the
40
+ bias is added to the logits generated by the model prior to sampling. The exact
41
+ effect will vary per model, but values between -1 and 1 should decrease or
42
+ increase likelihood of selection; values like -100 or 100 should result in a ban
43
+ or exclusive selection of the relevant token.
44
+ """
45
+
46
+ logprobs: Optional[bool]
47
+ """Whether to return log probabilities of the output tokens or not.
48
+
49
+ If true, returns the log probabilities of each output token returned in the
50
+ `content` of `message`.
51
+ """
52
+
53
+ max_completion_tokens: Optional[int]
54
+ """
55
+ The maximum number of completion tokens that may be used over the course of the
56
+ run. The run will make a best effort to use only the number of completion tokens
57
+ specified, across multiple turns of the run.
58
+ """
59
+
60
+ max_tokens: Optional[int]
61
+ """The maximum number of tokens that can be generated in the completion.
62
+
63
+ The token count of your prompt plus `max_tokens` cannot exceed the model's
64
+ context length.
65
+ """
66
+
67
+ metadata: Optional[Dict[str, str]]
68
+ """Set of 16 key-value pairs that can be attached to an object.
69
+
70
+ This can be useful for storing additional information about the object in a
71
+ structured format, and querying for objects via API or the dashboard.
72
+
73
+ Keys are strings with a maximum length of 64 characters. Values are strings with
74
+ a maximum length of 512 characters.
75
+ """
76
+
77
+ n: Optional[int]
78
+ """How many chat completion choices to generate for each input message.
79
+
80
+ Note that you will be charged based on the number of generated tokens across all
81
+ of the choices. Keep `n` as `1` to minimize costs.
82
+ """
83
+
84
+ presence_penalty: Optional[float]
85
+ """Number between -2.0 and 2.0.
86
+
87
+ Positive values penalize new tokens based on whether they appear in the text so
88
+ far, increasing the model's likelihood to talk about new topics.
89
+ """
90
+
91
+ stop: Union[Optional[str], List[str], None]
92
+ """Up to 4 sequences where the API will stop generating further tokens.
93
+
94
+ The returned text will not contain the stop sequence.
95
+ """
96
+
97
+ stream_options: Optional[StreamOptions]
98
+ """Options for streaming response. Only set this when you set `stream: true`."""
99
+
100
+ temperature: Optional[float]
101
+ """What sampling temperature to use, between 0 and 2.
102
+
103
+ Higher values like 0.8 will make the output more random, while lower values like
104
+ 0.2 will make it more focused and deterministic. We generally recommend altering
105
+ this or `top_p` but not both.
106
+ """
107
+
108
+ top_logprobs: Optional[int]
109
+ """
110
+ An integer between 0 and 20 specifying the number of most likely tokens to
111
+ return at each token position, each with an associated log probability.
112
+ `logprobs` must be set to `true` if this parameter is used.
113
+ """
114
+
115
+ top_p: Optional[float]
116
+ """
117
+ An alternative to sampling with temperature, called nucleus sampling, where the
118
+ model considers the results of the tokens with top_p probability mass. So 0.1
119
+ means only the tokens comprising the top 10% probability mass are considered.
120
+
121
+ We generally recommend altering this or `temperature` but not both.
122
+ """
123
+
124
+ user: str
125
+ """
126
+ A unique identifier representing your end-user, which can help DigitalOcean to
127
+ monitor and detect abuse.
128
+ """
129
+
130
+
131
+ class MessageChatCompletionRequestSystemMessage(TypedDict, total=False):
132
+ content: Required[Union[str, List[str]]]
133
+ """The contents of the system message."""
134
+
135
+ role: Required[Literal["system"]]
136
+ """The role of the messages author, in this case `system`."""
137
+
138
+
139
+ class MessageChatCompletionRequestDeveloperMessage(TypedDict, total=False):
140
+ content: Required[Union[str, List[str]]]
141
+ """The contents of the developer message."""
142
+
143
+ role: Required[Literal["developer"]]
144
+ """The role of the messages author, in this case `developer`."""
145
+
146
+
147
+ class MessageChatCompletionRequestUserMessage(TypedDict, total=False):
148
+ content: Required[Union[str, List[str]]]
149
+ """The contents of the user message."""
150
+
151
+ role: Required[Literal["user"]]
152
+ """The role of the messages author, in this case `user`."""
153
+
154
+
155
+ class MessageChatCompletionRequestAssistantMessage(TypedDict, total=False):
156
+ role: Required[Literal["assistant"]]
157
+ """The role of the messages author, in this case `assistant`."""
158
+
159
+ content: Union[str, List[str], None]
160
+ """The contents of the assistant message."""
161
+
162
+
163
+ Message: TypeAlias = Union[
164
+ MessageChatCompletionRequestSystemMessage,
165
+ MessageChatCompletionRequestDeveloperMessage,
166
+ MessageChatCompletionRequestUserMessage,
167
+ MessageChatCompletionRequestAssistantMessage,
168
+ ]
169
+
170
+
171
+ class StreamOptions(TypedDict, total=False):
172
+ include_usage: bool
173
+ """If set, an additional chunk will be streamed before the `data: [DONE]` message.
174
+
175
+ The `usage` field on this chunk shows the token usage statistics for the entire
176
+ request, and the `choices` field will always be an empty array.
177
+
178
+ All other chunks will also include a `usage` field, but with a null value.
179
+ **NOTE:** If the stream is interrupted, you may not receive the final usage
180
+ chunk which contains the total token usage for the request.
181
+ """
182
+
183
+
184
+ class CompletionCreateParamsNonStreaming(CompletionCreateParamsBase, total=False):
185
+ stream: Optional[Literal[False]]
186
+ """
187
+ If set to true, the model response data will be streamed to the client as it is
188
+ generated using server-sent events.
189
+ """
190
+
191
+
192
+ class CompletionCreateParamsStreaming(CompletionCreateParamsBase):
193
+ stream: Required[Literal[True]]
194
+ """
195
+ If set to true, the model response data will be streamed to the client as it is
196
+ generated using server-sent events.
197
+ """
198
+
199
+
200
+ CompletionCreateParams = Union[CompletionCreateParamsNonStreaming, CompletionCreateParamsStreaming]
@@ -0,0 +1,81 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List, Optional
4
+ from typing_extensions import Literal
5
+
6
+ from ...._models import BaseModel
7
+ from ...shared.chat_completion_token_logprob import ChatCompletionTokenLogprob
8
+
9
+ __all__ = ["CompletionCreateResponse", "Choice", "ChoiceLogprobs", "ChoiceMessage", "Usage"]
10
+
11
+
12
+ class ChoiceLogprobs(BaseModel):
13
+ content: Optional[List[ChatCompletionTokenLogprob]] = None
14
+ """A list of message content tokens with log probability information."""
15
+
16
+ refusal: Optional[List[ChatCompletionTokenLogprob]] = None
17
+ """A list of message refusal tokens with log probability information."""
18
+
19
+
20
+ class ChoiceMessage(BaseModel):
21
+ content: Optional[str] = None
22
+ """The contents of the message."""
23
+
24
+ refusal: Optional[str] = None
25
+ """The refusal message generated by the model."""
26
+
27
+ role: Literal["assistant"]
28
+ """The role of the author of this message."""
29
+
30
+
31
+ class Choice(BaseModel):
32
+ finish_reason: Literal["stop", "length"]
33
+ """The reason the model stopped generating tokens.
34
+
35
+ This will be `stop` if the model hit a natural stop point or a provided stop
36
+ sequence, or `length` if the maximum number of tokens specified in the request
37
+ was reached.
38
+ """
39
+
40
+ index: int
41
+ """The index of the choice in the list of choices."""
42
+
43
+ logprobs: Optional[ChoiceLogprobs] = None
44
+ """Log probability information for the choice."""
45
+
46
+ message: ChoiceMessage
47
+ """A chat completion message generated by the model."""
48
+
49
+
50
+ class Usage(BaseModel):
51
+ completion_tokens: int
52
+ """Number of tokens in the generated completion."""
53
+
54
+ prompt_tokens: int
55
+ """Number of tokens in the prompt."""
56
+
57
+ total_tokens: int
58
+ """Total number of tokens used in the request (prompt + completion)."""
59
+
60
+
61
+ class CompletionCreateResponse(BaseModel):
62
+ id: str
63
+ """A unique identifier for the chat completion."""
64
+
65
+ choices: List[Choice]
66
+ """A list of chat completion choices.
67
+
68
+ Can be more than one if `n` is greater than 1.
69
+ """
70
+
71
+ created: int
72
+ """The Unix timestamp (in seconds) of when the chat completion was created."""
73
+
74
+ model: str
75
+ """The model used for the chat completion."""
76
+
77
+ object: Literal["chat.completion"]
78
+ """The object type, which is always `chat.completion`."""
79
+
80
+ usage: Optional[Usage] = None
81
+ """Usage statistics for the completion request."""