create static method
Returns the OpenAIService instance.
The apiToken parameter is mandatory for every requests.
The customUri parameter is used to switch the base path of
the requests.
The enableLogging parameter should be set to true, when you
need logs.
Implementation
static OpenAIService create({
required String apiToken,
Uri? customUri,
bool enableLogging = false,
}) {
assert(apiToken.isNotEmpty, 'Api token must have at least one character');
const openAiBaseUrlDefault = 'https://api.openai.com';
final client = ChopperClient(
baseUrl: customUri ?? Uri.parse(openAiBaseUrlDefault),
services: [_$OpenAIService()],
converter: const OpenAITypeConverter(factories),
interceptors: [
HeadersInterceptor({
headerKeyAuthentication: 'Bearer $apiToken',
}),
if (enableLogging) HttpLoggingInterceptor(),
if (enableLogging) CurlInterceptor(),
],
);
return _$OpenAIService(client);
}