Skip to content

Commit 1021667

Browse files
feat: inference: expose chat completions and models under /ai/openai
1 parent 8494e4c commit 1021667

17 files changed

Lines changed: 1462 additions & 221 deletions

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 1035
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/telnyx/telnyx-24dfaca2643301f6b6aeb1862d80ddb8ea02ba1e97636b85a7da9728ad289522.yml
3-
openapi_spec_hash: 88c62e3c78a46393e22cd7259925b6c5
4-
config_hash: cfdc548410473bb526a8fc846ec89e39
1+
configured_endpoints: 1037
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/telnyx/telnyx-7b1e3a7121542084b48908b0f883f893cd8c6d641d637c613e009fb79c8aafc4.yml
3+
openapi_spec_hash: 70a95e0804087a3dd65087eee654465b
4+
config_hash: d3b972f90f1bbecf92ef9592fae471fa

api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,16 @@ Methods:
11361136

11371137
## OpenAI
11381138

1139+
Types:
1140+
1141+
```python
1142+
from telnyx.types.ai import OpenAIListModelsResponse
1143+
```
1144+
1145+
Methods:
1146+
1147+
- <code title="get /ai/openai/models">client.ai.openai.<a href="./src/telnyx/resources/ai/openai/openai.py">list_models</a>() -> <a href="./src/telnyx/types/ai/openai_list_models_response.py">OpenAIListModelsResponse</a></code>
1148+
11391149
### Embeddings
11401150

11411151
Types:
@@ -1152,6 +1162,18 @@ Methods:
11521162
- <code title="post /ai/openai/embeddings">client.ai.openai.embeddings.<a href="./src/telnyx/resources/ai/openai/embeddings.py">create_embeddings</a>(\*\*<a href="src/telnyx/types/ai/openai/embedding_create_embeddings_params.py">params</a>) -> <a href="./src/telnyx/types/ai/openai/embedding_create_embeddings_response.py">EmbeddingCreateEmbeddingsResponse</a></code>
11531163
- <code title="get /ai/openai/embeddings/models">client.ai.openai.embeddings.<a href="./src/telnyx/resources/ai/openai/embeddings.py">list_embedding_models</a>() -> <a href="./src/telnyx/types/ai/openai/embedding_list_embedding_models_response.py">EmbeddingListEmbeddingModelsResponse</a></code>
11541164

1165+
### Chat
1166+
1167+
Types:
1168+
1169+
```python
1170+
from telnyx.types.ai.openai import ChatCreateCompletionResponse
1171+
```
1172+
1173+
Methods:
1174+
1175+
- <code title="post /ai/openai/chat/completions">client.ai.openai.chat.<a href="./src/telnyx/resources/ai/openai/chat.py">create_completion</a>(\*\*<a href="src/telnyx/types/ai/openai/chat_create_completion_params.py">params</a>) -> <a href="./src/telnyx/types/ai/openai/chat_create_completion_response.py">ChatCreateCompletionResponse</a></code>
1176+
11551177
## Tools
11561178

11571179
Types:

src/telnyx/resources/ai/ai.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import typing_extensions
6+
57
import httpx
68

79
from .chat import (
@@ -194,6 +196,7 @@ def with_streaming_response(self) -> AIResourceWithStreamingResponse:
194196
"""
195197
return AIResourceWithStreamingResponse(self)
196198

199+
@typing_extensions.deprecated("deprecated")
197200
def retrieve_models(
198201
self,
199202
*,
@@ -204,12 +207,13 @@ def retrieve_models(
204207
extra_body: Body | None = None,
205208
timeout: float | httpx.Timeout | None | NotGiven = not_given,
206209
) -> AIRetrieveModelsResponse:
207-
"""
208-
This endpoint returns a list of Open Source and OpenAI models that are available
209-
for use. <br /><br /> **Note**: Model `id`'s will be in the form
210-
`{source}/{model_name}`. For example `openai/gpt-4` or
211-
`mistralai/Mistral-7B-Instruct-v0.1` consistent with HuggingFace naming
212-
conventions.
210+
"""**Deprecated**: Use `GET /v2/ai/openai/models` instead.
211+
212+
This endpoint returns a
213+
list of Open Source and OpenAI models that are available for use. <br /><br />
214+
**Note**: Model `id`'s will be in the form `{source}/{model_name}`. For example
215+
`openai/gpt-4` or `mistralai/Mistral-7B-Instruct-v0.1` consistent with
216+
HuggingFace naming conventions.
213217
"""
214218
return self._get(
215219
"/ai/models",
@@ -353,6 +357,7 @@ def with_streaming_response(self) -> AsyncAIResourceWithStreamingResponse:
353357
"""
354358
return AsyncAIResourceWithStreamingResponse(self)
355359

360+
@typing_extensions.deprecated("deprecated")
356361
async def retrieve_models(
357362
self,
358363
*,
@@ -363,12 +368,13 @@ async def retrieve_models(
363368
extra_body: Body | None = None,
364369
timeout: float | httpx.Timeout | None | NotGiven = not_given,
365370
) -> AIRetrieveModelsResponse:
366-
"""
367-
This endpoint returns a list of Open Source and OpenAI models that are available
368-
for use. <br /><br /> **Note**: Model `id`'s will be in the form
369-
`{source}/{model_name}`. For example `openai/gpt-4` or
370-
`mistralai/Mistral-7B-Instruct-v0.1` consistent with HuggingFace naming
371-
conventions.
371+
"""**Deprecated**: Use `GET /v2/ai/openai/models` instead.
372+
373+
This endpoint returns a
374+
list of Open Source and OpenAI models that are available for use. <br /><br />
375+
**Note**: Model `id`'s will be in the form `{source}/{model_name}`. For example
376+
`openai/gpt-4` or `mistralai/Mistral-7B-Instruct-v0.1` consistent with
377+
HuggingFace naming conventions.
372378
"""
373379
return await self._get(
374380
"/ai/models",
@@ -440,8 +446,10 @@ class AIResourceWithRawResponse:
440446
def __init__(self, ai: AIResource) -> None:
441447
self._ai = ai
442448

443-
self.retrieve_models = to_raw_response_wrapper(
444-
ai.retrieve_models,
449+
self.retrieve_models = ( # pyright: ignore[reportDeprecated]
450+
to_raw_response_wrapper(
451+
ai.retrieve_models, # pyright: ignore[reportDeprecated],
452+
)
445453
)
446454
self.summarize = to_raw_response_wrapper(
447455
ai.summarize,
@@ -506,8 +514,10 @@ class AsyncAIResourceWithRawResponse:
506514
def __init__(self, ai: AsyncAIResource) -> None:
507515
self._ai = ai
508516

509-
self.retrieve_models = async_to_raw_response_wrapper(
510-
ai.retrieve_models,
517+
self.retrieve_models = ( # pyright: ignore[reportDeprecated]
518+
async_to_raw_response_wrapper(
519+
ai.retrieve_models, # pyright: ignore[reportDeprecated],
520+
)
511521
)
512522
self.summarize = async_to_raw_response_wrapper(
513523
ai.summarize,
@@ -572,8 +582,10 @@ class AIResourceWithStreamingResponse:
572582
def __init__(self, ai: AIResource) -> None:
573583
self._ai = ai
574584

575-
self.retrieve_models = to_streamed_response_wrapper(
576-
ai.retrieve_models,
585+
self.retrieve_models = ( # pyright: ignore[reportDeprecated]
586+
to_streamed_response_wrapper(
587+
ai.retrieve_models, # pyright: ignore[reportDeprecated],
588+
)
577589
)
578590
self.summarize = to_streamed_response_wrapper(
579591
ai.summarize,
@@ -638,8 +650,10 @@ class AsyncAIResourceWithStreamingResponse:
638650
def __init__(self, ai: AsyncAIResource) -> None:
639651
self._ai = ai
640652

641-
self.retrieve_models = async_to_streamed_response_wrapper(
642-
ai.retrieve_models,
653+
self.retrieve_models = ( # pyright: ignore[reportDeprecated]
654+
async_to_streamed_response_wrapper(
655+
ai.retrieve_models, # pyright: ignore[reportDeprecated],
656+
)
643657
)
644658
self.summarize = async_to_streamed_response_wrapper(
645659
ai.summarize,

src/telnyx/resources/ai/chat.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Iterable
5+
import typing_extensions
6+
from typing import Dict, Union, Iterable
67
from typing_extensions import Literal
78

89
import httpx
@@ -46,6 +47,7 @@ def with_streaming_response(self) -> ChatResourceWithStreamingResponse:
4647
"""
4748
return ChatResourceWithStreamingResponse(self)
4849

50+
@typing_extensions.deprecated("deprecated")
4951
def create_completion(
5052
self,
5153
*,
@@ -66,6 +68,8 @@ def create_completion(
6668
n: float | Omit = omit,
6769
presence_penalty: float | Omit = omit,
6870
response_format: chat_create_completion_params.ResponseFormat | Omit = omit,
71+
seed: int | Omit = omit,
72+
stop: Union[str, SequenceNotStr[str]] | Omit = omit,
6973
stream: bool | Omit = omit,
7074
temperature: float | Omit = omit,
7175
tool_choice: Literal["none", "auto", "required"] | Omit = omit,
@@ -80,9 +84,10 @@ def create_completion(
8084
extra_body: Body | None = None,
8185
timeout: float | httpx.Timeout | None | NotGiven = not_given,
8286
) -> ChatCreateCompletionResponse:
83-
"""Chat with a language model.
87+
"""**Deprecated**: Use `POST /v2/ai/openai/chat/completions` instead.
8488
85-
This endpoint is consistent with the
89+
Chat with a
90+
language model. This endpoint is consistent with the
8691
[OpenAI Chat Completions API](https://platform.openai.com/docs/api-reference/chat)
8792
and may be used with the OpenAI JS or Python SDK.
8893
@@ -135,6 +140,13 @@ def create_completion(
135140
response_format: Use this is you want to guarantee a JSON output without defining a schema. For
136141
control over the schema, use `guided_json`.
137142
143+
seed: If specified, the system will make a best effort to sample deterministically,
144+
such that repeated requests with the same `seed` and parameters should return
145+
the same result.
146+
147+
stop: Up to 4 sequences where the API will stop generating further tokens. The
148+
returned text will not contain the stop sequence.
149+
138150
stream: Whether or not to stream data-only server-sent events as they become available.
139151
140152
temperature: Adjusts the "creativity" of the model. Lower values make the model more
@@ -187,6 +199,8 @@ def create_completion(
187199
"n": n,
188200
"presence_penalty": presence_penalty,
189201
"response_format": response_format,
202+
"seed": seed,
203+
"stop": stop,
190204
"stream": stream,
191205
"temperature": temperature,
192206
"tool_choice": tool_choice,
@@ -226,6 +240,7 @@ def with_streaming_response(self) -> AsyncChatResourceWithStreamingResponse:
226240
"""
227241
return AsyncChatResourceWithStreamingResponse(self)
228242

243+
@typing_extensions.deprecated("deprecated")
229244
async def create_completion(
230245
self,
231246
*,
@@ -246,6 +261,8 @@ async def create_completion(
246261
n: float | Omit = omit,
247262
presence_penalty: float | Omit = omit,
248263
response_format: chat_create_completion_params.ResponseFormat | Omit = omit,
264+
seed: int | Omit = omit,
265+
stop: Union[str, SequenceNotStr[str]] | Omit = omit,
249266
stream: bool | Omit = omit,
250267
temperature: float | Omit = omit,
251268
tool_choice: Literal["none", "auto", "required"] | Omit = omit,
@@ -260,9 +277,10 @@ async def create_completion(
260277
extra_body: Body | None = None,
261278
timeout: float | httpx.Timeout | None | NotGiven = not_given,
262279
) -> ChatCreateCompletionResponse:
263-
"""Chat with a language model.
280+
"""**Deprecated**: Use `POST /v2/ai/openai/chat/completions` instead.
264281
265-
This endpoint is consistent with the
282+
Chat with a
283+
language model. This endpoint is consistent with the
266284
[OpenAI Chat Completions API](https://platform.openai.com/docs/api-reference/chat)
267285
and may be used with the OpenAI JS or Python SDK.
268286
@@ -315,6 +333,13 @@ async def create_completion(
315333
response_format: Use this is you want to guarantee a JSON output without defining a schema. For
316334
control over the schema, use `guided_json`.
317335
336+
seed: If specified, the system will make a best effort to sample deterministically,
337+
such that repeated requests with the same `seed` and parameters should return
338+
the same result.
339+
340+
stop: Up to 4 sequences where the API will stop generating further tokens. The
341+
returned text will not contain the stop sequence.
342+
318343
stream: Whether or not to stream data-only server-sent events as they become available.
319344
320345
temperature: Adjusts the "creativity" of the model. Lower values make the model more
@@ -367,6 +392,8 @@ async def create_completion(
367392
"n": n,
368393
"presence_penalty": presence_penalty,
369394
"response_format": response_format,
395+
"seed": seed,
396+
"stop": stop,
370397
"stream": stream,
371398
"temperature": temperature,
372399
"tool_choice": tool_choice,
@@ -388,33 +415,41 @@ class ChatResourceWithRawResponse:
388415
def __init__(self, chat: ChatResource) -> None:
389416
self._chat = chat
390417

391-
self.create_completion = to_raw_response_wrapper(
392-
chat.create_completion,
418+
self.create_completion = ( # pyright: ignore[reportDeprecated]
419+
to_raw_response_wrapper(
420+
chat.create_completion, # pyright: ignore[reportDeprecated],
421+
)
393422
)
394423

395424

396425
class AsyncChatResourceWithRawResponse:
397426
def __init__(self, chat: AsyncChatResource) -> None:
398427
self._chat = chat
399428

400-
self.create_completion = async_to_raw_response_wrapper(
401-
chat.create_completion,
429+
self.create_completion = ( # pyright: ignore[reportDeprecated]
430+
async_to_raw_response_wrapper(
431+
chat.create_completion, # pyright: ignore[reportDeprecated],
432+
)
402433
)
403434

404435

405436
class ChatResourceWithStreamingResponse:
406437
def __init__(self, chat: ChatResource) -> None:
407438
self._chat = chat
408439

409-
self.create_completion = to_streamed_response_wrapper(
410-
chat.create_completion,
440+
self.create_completion = ( # pyright: ignore[reportDeprecated]
441+
to_streamed_response_wrapper(
442+
chat.create_completion, # pyright: ignore[reportDeprecated],
443+
)
411444
)
412445

413446

414447
class AsyncChatResourceWithStreamingResponse:
415448
def __init__(self, chat: AsyncChatResource) -> None:
416449
self._chat = chat
417450

418-
self.create_completion = async_to_streamed_response_wrapper(
419-
chat.create_completion,
451+
self.create_completion = ( # pyright: ignore[reportDeprecated]
452+
async_to_streamed_response_wrapper(
453+
chat.create_completion, # pyright: ignore[reportDeprecated],
454+
)
420455
)

src/telnyx/resources/ai/openai/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
from .chat import (
4+
ChatResource,
5+
AsyncChatResource,
6+
ChatResourceWithRawResponse,
7+
AsyncChatResourceWithRawResponse,
8+
ChatResourceWithStreamingResponse,
9+
AsyncChatResourceWithStreamingResponse,
10+
)
311
from .openai import (
412
OpenAIResource,
513
AsyncOpenAIResource,
@@ -24,6 +32,12 @@
2432
"AsyncEmbeddingsResourceWithRawResponse",
2533
"EmbeddingsResourceWithStreamingResponse",
2634
"AsyncEmbeddingsResourceWithStreamingResponse",
35+
"ChatResource",
36+
"AsyncChatResource",
37+
"ChatResourceWithRawResponse",
38+
"AsyncChatResourceWithRawResponse",
39+
"ChatResourceWithStreamingResponse",
40+
"AsyncChatResourceWithStreamingResponse",
2741
"OpenAIResource",
2842
"AsyncOpenAIResource",
2943
"OpenAIResourceWithRawResponse",

0 commit comments

Comments
 (0)