openapiopenai 1.0.0__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 (73) hide show
  1. openapiopenai/__init__.py +93 -0
  2. openapiopenai/api/__init__.py +5 -0
  3. openapiopenai/api/open_ai_api.py +6334 -0
  4. openapiopenai/api_client.py +759 -0
  5. openapiopenai/api_response.py +21 -0
  6. openapiopenai/configuration.py +437 -0
  7. openapiopenai/exceptions.py +200 -0
  8. openapiopenai/models/__init__.py +76 -0
  9. openapiopenai/models/chat_completion_functions.py +92 -0
  10. openapiopenai/models/chat_completion_request_message.py +105 -0
  11. openapiopenai/models/chat_completion_request_message_function_call.py +90 -0
  12. openapiopenai/models/chat_completion_response_message.py +108 -0
  13. openapiopenai/models/chat_completion_stream_response_delta.py +111 -0
  14. openapiopenai/models/create_chat_completion_request.py +178 -0
  15. openapiopenai/models/create_chat_completion_request_function_call.py +141 -0
  16. openapiopenai/models/create_chat_completion_request_function_call_one_of.py +88 -0
  17. openapiopenai/models/create_chat_completion_request_model.py +144 -0
  18. openapiopenai/models/create_chat_completion_request_stop.py +145 -0
  19. openapiopenai/models/create_chat_completion_response.py +110 -0
  20. openapiopenai/models/create_chat_completion_response_choices_inner.py +106 -0
  21. openapiopenai/models/create_chat_completion_stream_response.py +104 -0
  22. openapiopenai/models/create_chat_completion_stream_response_choices_inner.py +106 -0
  23. openapiopenai/models/create_completion_request.py +201 -0
  24. openapiopenai/models/create_completion_request_model.py +144 -0
  25. openapiopenai/models/create_completion_request_prompt.py +185 -0
  26. openapiopenai/models/create_completion_request_stop.py +151 -0
  27. openapiopenai/models/create_completion_response.py +110 -0
  28. openapiopenai/models/create_completion_response_choices_inner.py +110 -0
  29. openapiopenai/models/create_completion_response_choices_inner_logprobs.py +94 -0
  30. openapiopenai/models/create_completion_response_usage.py +92 -0
  31. openapiopenai/models/create_edit_request.py +123 -0
  32. openapiopenai/models/create_edit_request_model.py +144 -0
  33. openapiopenai/models/create_edit_response.py +106 -0
  34. openapiopenai/models/create_edit_response_choices_inner.py +113 -0
  35. openapiopenai/models/create_embedding_request.py +100 -0
  36. openapiopenai/models/create_embedding_request_input.py +179 -0
  37. openapiopenai/models/create_embedding_request_model.py +144 -0
  38. openapiopenai/models/create_embedding_response.py +106 -0
  39. openapiopenai/models/create_embedding_response_data_inner.py +92 -0
  40. openapiopenai/models/create_embedding_response_usage.py +90 -0
  41. openapiopenai/models/create_fine_tune_request.py +170 -0
  42. openapiopenai/models/create_fine_tune_request_model.py +150 -0
  43. openapiopenai/models/create_image_request.py +132 -0
  44. openapiopenai/models/create_moderation_request.py +98 -0
  45. openapiopenai/models/create_moderation_request_input.py +144 -0
  46. openapiopenai/models/create_moderation_request_model.py +144 -0
  47. openapiopenai/models/create_moderation_response.py +100 -0
  48. openapiopenai/models/create_moderation_response_results_inner.py +100 -0
  49. openapiopenai/models/create_moderation_response_results_inner_categories.py +100 -0
  50. openapiopenai/models/create_moderation_response_results_inner_category_scores.py +100 -0
  51. openapiopenai/models/create_transcription_request_model.py +144 -0
  52. openapiopenai/models/create_transcription_response.py +88 -0
  53. openapiopenai/models/create_translation_response.py +88 -0
  54. openapiopenai/models/delete_file_response.py +92 -0
  55. openapiopenai/models/delete_model_response.py +92 -0
  56. openapiopenai/models/error.py +104 -0
  57. openapiopenai/models/error_response.py +92 -0
  58. openapiopenai/models/fine_tune.py +147 -0
  59. openapiopenai/models/fine_tune_event.py +94 -0
  60. openapiopenai/models/images_response.py +98 -0
  61. openapiopenai/models/images_response_data_inner.py +90 -0
  62. openapiopenai/models/list_files_response.py +98 -0
  63. openapiopenai/models/list_fine_tune_events_response.py +98 -0
  64. openapiopenai/models/list_fine_tunes_response.py +98 -0
  65. openapiopenai/models/list_models_response.py +98 -0
  66. openapiopenai/models/model.py +94 -0
  67. openapiopenai/models/open_ai_file.py +107 -0
  68. openapiopenai/py.typed +0 -0
  69. openapiopenai/rest.py +256 -0
  70. openapiopenai-1.0.0.dist-info/METADATA +19 -0
  71. openapiopenai-1.0.0.dist-info/RECORD +73 -0
  72. openapiopenai-1.0.0.dist-info/WHEEL +5 -0
  73. openapiopenai-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,76 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ OpenAI API
6
+
7
+ APIs for sampling from and fine-tuning language models
8
+
9
+ The version of the OpenAPI document: 2.0.0
10
+ Contact: blah+oapicf@cliffano.com
11
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
12
+
13
+ Do not edit the class manually.
14
+ """ # noqa: E501
15
+
16
+
17
+ # import models into model package
18
+ from openapiopenai.models.chat_completion_functions import ChatCompletionFunctions
19
+ from openapiopenai.models.chat_completion_request_message import ChatCompletionRequestMessage
20
+ from openapiopenai.models.chat_completion_request_message_function_call import ChatCompletionRequestMessageFunctionCall
21
+ from openapiopenai.models.chat_completion_response_message import ChatCompletionResponseMessage
22
+ from openapiopenai.models.chat_completion_stream_response_delta import ChatCompletionStreamResponseDelta
23
+ from openapiopenai.models.create_chat_completion_request import CreateChatCompletionRequest
24
+ from openapiopenai.models.create_chat_completion_request_function_call import CreateChatCompletionRequestFunctionCall
25
+ from openapiopenai.models.create_chat_completion_request_function_call_one_of import CreateChatCompletionRequestFunctionCallOneOf
26
+ from openapiopenai.models.create_chat_completion_request_model import CreateChatCompletionRequestModel
27
+ from openapiopenai.models.create_chat_completion_request_stop import CreateChatCompletionRequestStop
28
+ from openapiopenai.models.create_chat_completion_response import CreateChatCompletionResponse
29
+ from openapiopenai.models.create_chat_completion_response_choices_inner import CreateChatCompletionResponseChoicesInner
30
+ from openapiopenai.models.create_chat_completion_stream_response import CreateChatCompletionStreamResponse
31
+ from openapiopenai.models.create_chat_completion_stream_response_choices_inner import CreateChatCompletionStreamResponseChoicesInner
32
+ from openapiopenai.models.create_completion_request import CreateCompletionRequest
33
+ from openapiopenai.models.create_completion_request_model import CreateCompletionRequestModel
34
+ from openapiopenai.models.create_completion_request_prompt import CreateCompletionRequestPrompt
35
+ from openapiopenai.models.create_completion_request_stop import CreateCompletionRequestStop
36
+ from openapiopenai.models.create_completion_response import CreateCompletionResponse
37
+ from openapiopenai.models.create_completion_response_choices_inner import CreateCompletionResponseChoicesInner
38
+ from openapiopenai.models.create_completion_response_choices_inner_logprobs import CreateCompletionResponseChoicesInnerLogprobs
39
+ from openapiopenai.models.create_completion_response_usage import CreateCompletionResponseUsage
40
+ from openapiopenai.models.create_edit_request import CreateEditRequest
41
+ from openapiopenai.models.create_edit_request_model import CreateEditRequestModel
42
+ from openapiopenai.models.create_edit_response import CreateEditResponse
43
+ from openapiopenai.models.create_edit_response_choices_inner import CreateEditResponseChoicesInner
44
+ from openapiopenai.models.create_embedding_request import CreateEmbeddingRequest
45
+ from openapiopenai.models.create_embedding_request_input import CreateEmbeddingRequestInput
46
+ from openapiopenai.models.create_embedding_request_model import CreateEmbeddingRequestModel
47
+ from openapiopenai.models.create_embedding_response import CreateEmbeddingResponse
48
+ from openapiopenai.models.create_embedding_response_data_inner import CreateEmbeddingResponseDataInner
49
+ from openapiopenai.models.create_embedding_response_usage import CreateEmbeddingResponseUsage
50
+ from openapiopenai.models.create_fine_tune_request import CreateFineTuneRequest
51
+ from openapiopenai.models.create_fine_tune_request_model import CreateFineTuneRequestModel
52
+ from openapiopenai.models.create_image_request import CreateImageRequest
53
+ from openapiopenai.models.create_moderation_request import CreateModerationRequest
54
+ from openapiopenai.models.create_moderation_request_input import CreateModerationRequestInput
55
+ from openapiopenai.models.create_moderation_request_model import CreateModerationRequestModel
56
+ from openapiopenai.models.create_moderation_response import CreateModerationResponse
57
+ from openapiopenai.models.create_moderation_response_results_inner import CreateModerationResponseResultsInner
58
+ from openapiopenai.models.create_moderation_response_results_inner_categories import CreateModerationResponseResultsInnerCategories
59
+ from openapiopenai.models.create_moderation_response_results_inner_category_scores import CreateModerationResponseResultsInnerCategoryScores
60
+ from openapiopenai.models.create_transcription_request_model import CreateTranscriptionRequestModel
61
+ from openapiopenai.models.create_transcription_response import CreateTranscriptionResponse
62
+ from openapiopenai.models.create_translation_response import CreateTranslationResponse
63
+ from openapiopenai.models.delete_file_response import DeleteFileResponse
64
+ from openapiopenai.models.delete_model_response import DeleteModelResponse
65
+ from openapiopenai.models.error import Error
66
+ from openapiopenai.models.error_response import ErrorResponse
67
+ from openapiopenai.models.fine_tune import FineTune
68
+ from openapiopenai.models.fine_tune_event import FineTuneEvent
69
+ from openapiopenai.models.images_response import ImagesResponse
70
+ from openapiopenai.models.images_response_data_inner import ImagesResponseDataInner
71
+ from openapiopenai.models.list_files_response import ListFilesResponse
72
+ from openapiopenai.models.list_fine_tune_events_response import ListFineTuneEventsResponse
73
+ from openapiopenai.models.list_fine_tunes_response import ListFineTunesResponse
74
+ from openapiopenai.models.list_models_response import ListModelsResponse
75
+ from openapiopenai.models.model import Model
76
+ from openapiopenai.models.open_ai_file import OpenAIFile
@@ -0,0 +1,92 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ OpenAI API
5
+
6
+ APIs for sampling from and fine-tuning language models
7
+
8
+ The version of the OpenAPI document: 2.0.0
9
+ Contact: blah+oapicf@cliffano.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class ChatCompletionFunctions(BaseModel):
27
+ """
28
+ ChatCompletionFunctions
29
+ """ # noqa: E501
30
+ name: StrictStr = Field(description="The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.")
31
+ description: Optional[StrictStr] = Field(default=None, description="The description of what the function does.")
32
+ parameters: Optional[Dict[str, Any]] = Field(default=None, description="The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.")
33
+ __properties: ClassVar[List[str]] = ["name", "description", "parameters"]
34
+
35
+ model_config = ConfigDict(
36
+ populate_by_name=True,
37
+ validate_assignment=True,
38
+ protected_namespaces=(),
39
+ )
40
+
41
+
42
+ def to_str(self) -> str:
43
+ """Returns the string representation of the model using alias"""
44
+ return pprint.pformat(self.model_dump(by_alias=True))
45
+
46
+ def to_json(self) -> str:
47
+ """Returns the JSON representation of the model using alias"""
48
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49
+ return json.dumps(self.to_dict())
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Optional[Self]:
53
+ """Create an instance of ChatCompletionFunctions from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> Dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: Set[str] = set([
67
+ ])
68
+
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude=excluded_fields,
72
+ exclude_none=True,
73
+ )
74
+ return _dict
75
+
76
+ @classmethod
77
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
78
+ """Create an instance of ChatCompletionFunctions from a dict"""
79
+ if obj is None:
80
+ return None
81
+
82
+ if not isinstance(obj, dict):
83
+ return cls.model_validate(obj)
84
+
85
+ _obj = cls.model_validate({
86
+ "name": obj.get("name"),
87
+ "description": obj.get("description"),
88
+ "parameters": obj.get("parameters")
89
+ })
90
+ return _obj
91
+
92
+
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ OpenAI API
5
+
6
+ APIs for sampling from and fine-tuning language models
7
+
8
+ The version of the OpenAPI document: 2.0.0
9
+ Contact: blah+oapicf@cliffano.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from openapiopenai.models.chat_completion_request_message_function_call import ChatCompletionRequestMessageFunctionCall
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+
27
+ class ChatCompletionRequestMessage(BaseModel):
28
+ """
29
+ ChatCompletionRequestMessage
30
+ """ # noqa: E501
31
+ role: StrictStr = Field(description="The role of the messages author. One of `system`, `user`, `assistant`, or `function`.")
32
+ content: Optional[StrictStr] = Field(default=None, description="The contents of the message. `content` is required for all messages except assistant messages with function calls.")
33
+ name: Optional[StrictStr] = Field(default=None, description="The name of the author of this message. `name` is required if role is `function`, and it should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.")
34
+ function_call: Optional[ChatCompletionRequestMessageFunctionCall] = None
35
+ __properties: ClassVar[List[str]] = ["role", "content", "name", "function_call"]
36
+
37
+ @field_validator('role')
38
+ def role_validate_enum(cls, value):
39
+ """Validates the enum"""
40
+ if value not in set(['system', 'user', 'assistant', 'function']):
41
+ raise ValueError("must be one of enum values ('system', 'user', 'assistant', 'function')")
42
+ return value
43
+
44
+ model_config = ConfigDict(
45
+ populate_by_name=True,
46
+ validate_assignment=True,
47
+ protected_namespaces=(),
48
+ )
49
+
50
+
51
+ def to_str(self) -> str:
52
+ """Returns the string representation of the model using alias"""
53
+ return pprint.pformat(self.model_dump(by_alias=True))
54
+
55
+ def to_json(self) -> str:
56
+ """Returns the JSON representation of the model using alias"""
57
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
58
+ return json.dumps(self.to_dict())
59
+
60
+ @classmethod
61
+ def from_json(cls, json_str: str) -> Optional[Self]:
62
+ """Create an instance of ChatCompletionRequestMessage from a JSON string"""
63
+ return cls.from_dict(json.loads(json_str))
64
+
65
+ def to_dict(self) -> Dict[str, Any]:
66
+ """Return the dictionary representation of the model using alias.
67
+
68
+ This has the following differences from calling pydantic's
69
+ `self.model_dump(by_alias=True)`:
70
+
71
+ * `None` is only added to the output dict for nullable fields that
72
+ were set at model initialization. Other fields with value `None`
73
+ are ignored.
74
+ """
75
+ excluded_fields: Set[str] = set([
76
+ ])
77
+
78
+ _dict = self.model_dump(
79
+ by_alias=True,
80
+ exclude=excluded_fields,
81
+ exclude_none=True,
82
+ )
83
+ # override the default output from pydantic by calling `to_dict()` of function_call
84
+ if self.function_call:
85
+ _dict['function_call'] = self.function_call.to_dict()
86
+ return _dict
87
+
88
+ @classmethod
89
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
90
+ """Create an instance of ChatCompletionRequestMessage from a dict"""
91
+ if obj is None:
92
+ return None
93
+
94
+ if not isinstance(obj, dict):
95
+ return cls.model_validate(obj)
96
+
97
+ _obj = cls.model_validate({
98
+ "role": obj.get("role"),
99
+ "content": obj.get("content"),
100
+ "name": obj.get("name"),
101
+ "function_call": ChatCompletionRequestMessageFunctionCall.from_dict(obj["function_call"]) if obj.get("function_call") is not None else None
102
+ })
103
+ return _obj
104
+
105
+
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ OpenAI API
5
+
6
+ APIs for sampling from and fine-tuning language models
7
+
8
+ The version of the OpenAPI document: 2.0.0
9
+ Contact: blah+oapicf@cliffano.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class ChatCompletionRequestMessageFunctionCall(BaseModel):
27
+ """
28
+ The name and arguments of a function that should be called, as generated by the model.
29
+ """ # noqa: E501
30
+ name: Optional[StrictStr] = Field(default=None, description="The name of the function to call.")
31
+ arguments: Optional[StrictStr] = Field(default=None, description="The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.")
32
+ __properties: ClassVar[List[str]] = ["name", "arguments"]
33
+
34
+ model_config = ConfigDict(
35
+ populate_by_name=True,
36
+ validate_assignment=True,
37
+ protected_namespaces=(),
38
+ )
39
+
40
+
41
+ def to_str(self) -> str:
42
+ """Returns the string representation of the model using alias"""
43
+ return pprint.pformat(self.model_dump(by_alias=True))
44
+
45
+ def to_json(self) -> str:
46
+ """Returns the JSON representation of the model using alias"""
47
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48
+ return json.dumps(self.to_dict())
49
+
50
+ @classmethod
51
+ def from_json(cls, json_str: str) -> Optional[Self]:
52
+ """Create an instance of ChatCompletionRequestMessageFunctionCall from a JSON string"""
53
+ return cls.from_dict(json.loads(json_str))
54
+
55
+ def to_dict(self) -> Dict[str, Any]:
56
+ """Return the dictionary representation of the model using alias.
57
+
58
+ This has the following differences from calling pydantic's
59
+ `self.model_dump(by_alias=True)`:
60
+
61
+ * `None` is only added to the output dict for nullable fields that
62
+ were set at model initialization. Other fields with value `None`
63
+ are ignored.
64
+ """
65
+ excluded_fields: Set[str] = set([
66
+ ])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
77
+ """Create an instance of ChatCompletionRequestMessageFunctionCall from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate({
85
+ "name": obj.get("name"),
86
+ "arguments": obj.get("arguments")
87
+ })
88
+ return _obj
89
+
90
+
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ OpenAI API
5
+
6
+ APIs for sampling from and fine-tuning language models
7
+
8
+ The version of the OpenAPI document: 2.0.0
9
+ Contact: blah+oapicf@cliffano.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from openapiopenai.models.chat_completion_request_message_function_call import ChatCompletionRequestMessageFunctionCall
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+
27
+ class ChatCompletionResponseMessage(BaseModel):
28
+ """
29
+ ChatCompletionResponseMessage
30
+ """ # noqa: E501
31
+ role: StrictStr = Field(description="The role of the author of this message.")
32
+ content: Optional[StrictStr] = Field(default=None, description="The contents of the message.")
33
+ function_call: Optional[ChatCompletionRequestMessageFunctionCall] = None
34
+ __properties: ClassVar[List[str]] = ["role", "content", "function_call"]
35
+
36
+ @field_validator('role')
37
+ def role_validate_enum(cls, value):
38
+ """Validates the enum"""
39
+ if value not in set(['system', 'user', 'assistant', 'function']):
40
+ raise ValueError("must be one of enum values ('system', 'user', 'assistant', 'function')")
41
+ return value
42
+
43
+ model_config = ConfigDict(
44
+ populate_by_name=True,
45
+ validate_assignment=True,
46
+ protected_namespaces=(),
47
+ )
48
+
49
+
50
+ def to_str(self) -> str:
51
+ """Returns the string representation of the model using alias"""
52
+ return pprint.pformat(self.model_dump(by_alias=True))
53
+
54
+ def to_json(self) -> str:
55
+ """Returns the JSON representation of the model using alias"""
56
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
57
+ return json.dumps(self.to_dict())
58
+
59
+ @classmethod
60
+ def from_json(cls, json_str: str) -> Optional[Self]:
61
+ """Create an instance of ChatCompletionResponseMessage from a JSON string"""
62
+ return cls.from_dict(json.loads(json_str))
63
+
64
+ def to_dict(self) -> Dict[str, Any]:
65
+ """Return the dictionary representation of the model using alias.
66
+
67
+ This has the following differences from calling pydantic's
68
+ `self.model_dump(by_alias=True)`:
69
+
70
+ * `None` is only added to the output dict for nullable fields that
71
+ were set at model initialization. Other fields with value `None`
72
+ are ignored.
73
+ """
74
+ excluded_fields: Set[str] = set([
75
+ ])
76
+
77
+ _dict = self.model_dump(
78
+ by_alias=True,
79
+ exclude=excluded_fields,
80
+ exclude_none=True,
81
+ )
82
+ # override the default output from pydantic by calling `to_dict()` of function_call
83
+ if self.function_call:
84
+ _dict['function_call'] = self.function_call.to_dict()
85
+ # set to None if content (nullable) is None
86
+ # and model_fields_set contains the field
87
+ if self.content is None and "content" in self.model_fields_set:
88
+ _dict['content'] = None
89
+
90
+ return _dict
91
+
92
+ @classmethod
93
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
94
+ """Create an instance of ChatCompletionResponseMessage from a dict"""
95
+ if obj is None:
96
+ return None
97
+
98
+ if not isinstance(obj, dict):
99
+ return cls.model_validate(obj)
100
+
101
+ _obj = cls.model_validate({
102
+ "role": obj.get("role"),
103
+ "content": obj.get("content"),
104
+ "function_call": ChatCompletionRequestMessageFunctionCall.from_dict(obj["function_call"]) if obj.get("function_call") is not None else None
105
+ })
106
+ return _obj
107
+
108
+
@@ -0,0 +1,111 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ OpenAI API
5
+
6
+ APIs for sampling from and fine-tuning language models
7
+
8
+ The version of the OpenAPI document: 2.0.0
9
+ Contact: blah+oapicf@cliffano.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from openapiopenai.models.chat_completion_request_message_function_call import ChatCompletionRequestMessageFunctionCall
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+
27
+ class ChatCompletionStreamResponseDelta(BaseModel):
28
+ """
29
+ ChatCompletionStreamResponseDelta
30
+ """ # noqa: E501
31
+ role: Optional[StrictStr] = Field(default=None, description="The role of the author of this message.")
32
+ content: Optional[StrictStr] = Field(default=None, description="The contents of the chunk message.")
33
+ function_call: Optional[ChatCompletionRequestMessageFunctionCall] = None
34
+ __properties: ClassVar[List[str]] = ["role", "content", "function_call"]
35
+
36
+ @field_validator('role')
37
+ def role_validate_enum(cls, value):
38
+ """Validates the enum"""
39
+ if value is None:
40
+ return value
41
+
42
+ if value not in set(['system', 'user', 'assistant', 'function']):
43
+ raise ValueError("must be one of enum values ('system', 'user', 'assistant', 'function')")
44
+ return value
45
+
46
+ model_config = ConfigDict(
47
+ populate_by_name=True,
48
+ validate_assignment=True,
49
+ protected_namespaces=(),
50
+ )
51
+
52
+
53
+ def to_str(self) -> str:
54
+ """Returns the string representation of the model using alias"""
55
+ return pprint.pformat(self.model_dump(by_alias=True))
56
+
57
+ def to_json(self) -> str:
58
+ """Returns the JSON representation of the model using alias"""
59
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
60
+ return json.dumps(self.to_dict())
61
+
62
+ @classmethod
63
+ def from_json(cls, json_str: str) -> Optional[Self]:
64
+ """Create an instance of ChatCompletionStreamResponseDelta from a JSON string"""
65
+ return cls.from_dict(json.loads(json_str))
66
+
67
+ def to_dict(self) -> Dict[str, Any]:
68
+ """Return the dictionary representation of the model using alias.
69
+
70
+ This has the following differences from calling pydantic's
71
+ `self.model_dump(by_alias=True)`:
72
+
73
+ * `None` is only added to the output dict for nullable fields that
74
+ were set at model initialization. Other fields with value `None`
75
+ are ignored.
76
+ """
77
+ excluded_fields: Set[str] = set([
78
+ ])
79
+
80
+ _dict = self.model_dump(
81
+ by_alias=True,
82
+ exclude=excluded_fields,
83
+ exclude_none=True,
84
+ )
85
+ # override the default output from pydantic by calling `to_dict()` of function_call
86
+ if self.function_call:
87
+ _dict['function_call'] = self.function_call.to_dict()
88
+ # set to None if content (nullable) is None
89
+ # and model_fields_set contains the field
90
+ if self.content is None and "content" in self.model_fields_set:
91
+ _dict['content'] = None
92
+
93
+ return _dict
94
+
95
+ @classmethod
96
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
97
+ """Create an instance of ChatCompletionStreamResponseDelta from a dict"""
98
+ if obj is None:
99
+ return None
100
+
101
+ if not isinstance(obj, dict):
102
+ return cls.model_validate(obj)
103
+
104
+ _obj = cls.model_validate({
105
+ "role": obj.get("role"),
106
+ "content": obj.get("content"),
107
+ "function_call": ChatCompletionRequestMessageFunctionCall.from_dict(obj["function_call"]) if obj.get("function_call") is not None else None
108
+ })
109
+ return _obj
110
+
111
+