Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make providers map callable #15

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/cli/src/commands/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import type { PromptOptions, UpdateResult } from "../types.js";
import type { Config, Provider } from "../types.js";
import { getApiKey, getConfig } from "../utils.js";

const providersMap: Record<Provider, OpenAIProvider | OllamaProvider> = {
openai: createOpenAI({
apiKey: await getApiKey("OpenAI", "OPENAI_API_KEY"),
}),
ollama: createOllama(),
const providersMap: Record<
Provider,
() => Promise<OpenAIProvider | OllamaProvider>
> = {
openai: async () =>
createOpenAI({
apiKey: await getApiKey("OpenAI", "OPENAI_API_KEY"),
}),
ollama: async () => createOllama(),
};

function getModel(config: Config) {
const provider = providersMap[config.llm.provider];
async function getModel(config: Config) {
const provider = await providersMap[config.llm.provider]();

return provider(config.llm.model);
}
Expand All @@ -43,7 +47,7 @@ export async function translate(targetLocale?: string, force = false) {

const git = simpleGit();

const model = getModel(config);
const model = await getModel(config);

const s = spinner();
s.start("Checking for changes and translating to target locales...");
Expand Down