main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from ..._compat import cached_property
6from ..._resource import SyncAPIResource, AsyncAPIResource
7from .completions.completions import (
8 Completions,
9 AsyncCompletions,
10 CompletionsWithRawResponse,
11 AsyncCompletionsWithRawResponse,
12 CompletionsWithStreamingResponse,
13 AsyncCompletionsWithStreamingResponse,
14)
15
16__all__ = ["Chat", "AsyncChat"]
17
18
19class Chat(SyncAPIResource):
20 @cached_property
21 def completions(self) -> Completions:
22 return Completions(self._client)
23
24 @cached_property
25 def with_raw_response(self) -> ChatWithRawResponse:
26 """
27 This property can be used as a prefix for any HTTP method call to return
28 the raw response object instead of the parsed content.
29
30 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
31 """
32 return ChatWithRawResponse(self)
33
34 @cached_property
35 def with_streaming_response(self) -> ChatWithStreamingResponse:
36 """
37 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
38
39 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
40 """
41 return ChatWithStreamingResponse(self)
42
43
44class AsyncChat(AsyncAPIResource):
45 @cached_property
46 def completions(self) -> AsyncCompletions:
47 return AsyncCompletions(self._client)
48
49 @cached_property
50 def with_raw_response(self) -> AsyncChatWithRawResponse:
51 """
52 This property can be used as a prefix for any HTTP method call to return
53 the raw response object instead of the parsed content.
54
55 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
56 """
57 return AsyncChatWithRawResponse(self)
58
59 @cached_property
60 def with_streaming_response(self) -> AsyncChatWithStreamingResponse:
61 """
62 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
63
64 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
65 """
66 return AsyncChatWithStreamingResponse(self)
67
68
69class ChatWithRawResponse:
70 def __init__(self, chat: Chat) -> None:
71 self._chat = chat
72
73 @cached_property
74 def completions(self) -> CompletionsWithRawResponse:
75 return CompletionsWithRawResponse(self._chat.completions)
76
77
78class AsyncChatWithRawResponse:
79 def __init__(self, chat: AsyncChat) -> None:
80 self._chat = chat
81
82 @cached_property
83 def completions(self) -> AsyncCompletionsWithRawResponse:
84 return AsyncCompletionsWithRawResponse(self._chat.completions)
85
86
87class ChatWithStreamingResponse:
88 def __init__(self, chat: Chat) -> None:
89 self._chat = chat
90
91 @cached_property
92 def completions(self) -> CompletionsWithStreamingResponse:
93 return CompletionsWithStreamingResponse(self._chat.completions)
94
95
96class AsyncChatWithStreamingResponse:
97 def __init__(self, chat: AsyncChat) -> None:
98 self._chat = chat
99
100 @cached_property
101 def completions(self) -> AsyncCompletionsWithStreamingResponse:
102 return AsyncCompletionsWithStreamingResponse(self._chat.completions)