|
| 1 | +from __future__ import annotations |
| 2 | +from kiota_abstractions.base_request_builder import BaseRequestBuilder |
| 3 | +from kiota_abstractions.base_request_configuration import RequestConfiguration |
| 4 | +from kiota_abstractions.get_path_parameters import get_path_parameters |
| 5 | +from kiota_abstractions.method import Method |
| 6 | +from kiota_abstractions.request_adapter import RequestAdapter |
| 7 | +from kiota_abstractions.request_information import RequestInformation |
| 8 | +from kiota_abstractions.request_option import RequestOption |
| 9 | +from kiota_abstractions.serialization import Parsable, ParsableFactory |
| 10 | +from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from ...models.chat_completion_request import ChatCompletionRequest |
| 14 | + from ...models.chat_completion_response import ChatCompletionResponse |
| 15 | + from ...models.h_t_t_p_validation_error import HTTPValidationError |
| 16 | + |
| 17 | +class Chat_completionsRequestBuilder(BaseRequestBuilder): |
| 18 | + """ |
| 19 | + Builds and executes requests for operations under /azure_openai/chat_completions |
| 20 | + """ |
| 21 | + def __init__(self,request_adapter: RequestAdapter, path_parameters: Union[str, Dict[str, Any]]) -> None: |
| 22 | + """ |
| 23 | + Instantiates a new Chat_completionsRequestBuilder and sets the default values. |
| 24 | + param path_parameters: The raw url or the url-template parameters for the request. |
| 25 | + param request_adapter: The request adapter to use to execute the requests. |
| 26 | + Returns: None |
| 27 | + """ |
| 28 | + super().__init__(request_adapter, "{+baseurl}/azure_openai/chat_completions", path_parameters) |
| 29 | + |
| 30 | + async def post(self,body: Optional[ChatCompletionRequest] = None, request_configuration: Optional[RequestConfiguration] = None) -> Optional[ChatCompletionResponse]: |
| 31 | + """ |
| 32 | + Create Chat Completions |
| 33 | + param body: The request body |
| 34 | + param request_configuration: Configuration for the request such as headers, query parameters, and middleware options. |
| 35 | + Returns: Optional[ChatCompletionResponse] |
| 36 | + """ |
| 37 | + if not body: |
| 38 | + raise TypeError("body cannot be null.") |
| 39 | + request_info = self.to_post_request_information( |
| 40 | + body, request_configuration |
| 41 | + ) |
| 42 | + from ...models.h_t_t_p_validation_error import HTTPValidationError |
| 43 | + |
| 44 | + error_mapping: Dict[str, ParsableFactory] = { |
| 45 | + "422": HTTPValidationError, |
| 46 | + } |
| 47 | + if not self.request_adapter: |
| 48 | + raise Exception("Http core is null") |
| 49 | + from ...models.chat_completion_response import ChatCompletionResponse |
| 50 | + |
| 51 | + return await self.request_adapter.send_async(request_info, ChatCompletionResponse, error_mapping) |
| 52 | + |
| 53 | + def to_post_request_information(self,body: Optional[ChatCompletionRequest] = None, request_configuration: Optional[RequestConfiguration] = None) -> RequestInformation: |
| 54 | + """ |
| 55 | + Create Chat Completions |
| 56 | + param body: The request body |
| 57 | + param request_configuration: Configuration for the request such as headers, query parameters, and middleware options. |
| 58 | + Returns: RequestInformation |
| 59 | + """ |
| 60 | + if not body: |
| 61 | + raise TypeError("body cannot be null.") |
| 62 | + request_info = RequestInformation(Method.POST, self.url_template, self.path_parameters) |
| 63 | + request_info.configure(request_configuration) |
| 64 | + request_info.headers.try_add("Accept", "application/json") |
| 65 | + request_info.set_content_from_parsable(self.request_adapter, "application/json", body) |
| 66 | + return request_info |
| 67 | + |
| 68 | + def with_url(self,raw_url: Optional[str] = None) -> Chat_completionsRequestBuilder: |
| 69 | + """ |
| 70 | + Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. |
| 71 | + param raw_url: The raw URL to use for the request builder. |
| 72 | + Returns: Chat_completionsRequestBuilder |
| 73 | + """ |
| 74 | + if not raw_url: |
| 75 | + raise TypeError("raw_url cannot be null.") |
| 76 | + return Chat_completionsRequestBuilder(self.request_adapter, raw_url) |
| 77 | + |
| 78 | + |
0 commit comments