chat.py 3.3 KB

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