// TODO: better import syntax? import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi'; import {Configuration} from '../configuration'; import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http'; import * as FormData from "form-data"; import { URLSearchParams } from 'url'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { ChatCompletionResponse } from '../models/ChatCompletionResponse'; import { ChatCompletionsPostRequest } from '../models/ChatCompletionsPostRequest'; import { ErrorResponse } from '../models/ErrorResponse'; /** * no description */ export class DefaultApiRequestFactory extends BaseAPIRequestFactory { /** * Generates a model\'s response for the given chat conversation * @param chatCompletionsPostRequest */ public async chatCompletionsPost(chatCompletionsPostRequest?: ChatCompletionsPostRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // Path Params const localVarPath = '/chat/completions'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(chatCompletionsPostRequest, "ChatCompletionsPostRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["BearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class DefaultApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to chatCompletionsPost * @throws ApiException if the response code was not in [200, 299] */ public async chatCompletionsPostWithHttpInfo(response: ResponseContext): Promise> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: ChatCompletionResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ChatCompletionResponse", "" ) as ChatCompletionResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Bad request", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden", body, response.headers); } if (isCodeInRange("404", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Not found", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Internal server error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: ChatCompletionResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ChatCompletionResponse", "" ) as ChatCompletionResponse; return new HttpInfo(response.httpStatusCode, response.headers, response.body, body); } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }