buildOpenAIProfileEnv function
ProfileEnv?
buildOpenAIProfileEnv({
- required RecommendationGoal goal,
- String? model,
- String? baseUrl,
- String? apiKey,
- Map<
String, String> ? processEnv, - ProviderRequestResolver? resolveProviderRequest,
Build an OpenAI profile environment. Returns null if no API key found.
Implementation
ProfileEnv? buildOpenAIProfileEnv({
required RecommendationGoal goal,
String? model,
String? baseUrl,
String? apiKey,
Map<String, String>? processEnv,
ProviderRequestResolver? resolveProviderRequest,
}) {
final env = processEnv ?? const {};
final key = sanitizeApiKey(apiKey ?? env['OPENAI_API_KEY']);
if (key == null) return null;
final defaultModel = getGoalDefaultOpenAIModel(goal);
final resolvedTransport = resolveProviderRequest != null
? resolveProviderRequest(
model: env['OPENAI_MODEL'],
baseUrl: env['OPENAI_BASE_URL'],
fallbackModel: defaultModel,
)
: 'chat_completions';
final useShellOpenAIConfig = resolvedTransport == 'chat_completions';
return ProfileEnv(
openaiBaseUrl:
_firstNonEmpty([
baseUrl,
useShellOpenAIConfig ? env['OPENAI_BASE_URL'] : null,
]) ??
_defaultOpenaiBaseUrl,
openaiModel:
_firstNonEmpty([
model,
useShellOpenAIConfig ? env['OPENAI_MODEL'] : null,
]) ??
defaultModel,
openaiApiKey: key,
);
}