UNPKG

@earendil-works/pi-ai

Version:

Unified LLM API with automatic model discovery and provider configuration

33 lines • 1.45 kB
import { openAIDecisionsApi } from "../api/openai-decisions.lazy.js"; import { openAIResponsesApi } from "../api/openai-responses.lazy.js"; import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.js"; import { loadOpenAIChatGPTOAuth } from "../auth/oauth/load.js"; import { createProvider, isModelType } from "../models.js"; import { OPENAI_CLASSIFIER_MODELS, OPENAI_MODELS } from "./openai.models.js"; export function openaiProvider() { return createProvider({ id: "openai", name: "OpenAI", baseUrl: "https://api.openai.com/v1", auth: { apiKey: envApiKeyAuth("OpenAI API key", ["OPENAI_API_KEY"]), oauth: lazyOAuth({ name: "OpenAI (ChatGPT subscription)", isSubscription: true, loginLabel: "Sign in with ChatGPT", load: loadOpenAIChatGPTOAuth, }), }, models: [ ...Object.values(OPENAI_MODELS), ...Object.values(OPENAI_CLASSIFIER_MODELS), ], // Sign in with ChatGPT tokens only reach the Responses API; the Decisions API rejects them. filterAllModels: (models, credential) => credential?.type === "oauth" ? models.filter((model) => !isModelType(model, "classifier")) : models, api: openAIResponsesApi(), classifiers: { "openai-decisions": openAIDecisionsApi(), }, }); } //# sourceMappingURL=openai.js.map