Skip to content

Commit d3ca5d7

Browse files
committed
feat(config): add support for custom API endpoints
1 parent 28fdf9c commit d3ca5d7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export interface Config {
8080
const DEFAULT_CONFIG: Config = {
8181
provider: "openai",
8282
API_KEY: "",
83-
model: "gpt-4",
83+
customEndpoint: "",
84+
model: "gpt-4o",
8485
templates: {
8586
default: path.join(os.homedir(), ".lazycommit-template"),
8687
},
@@ -283,6 +284,15 @@ async function getModels() {
283284
throw new Error("API_KEY is not set");
284285
}
285286
if (provider === "openai") {
287+
const oai = new OpenAI({
288+
apiKey,
289+
});
290+
const models = await oai.models.list();
291+
return models.data.map((model) => model.id);
292+
} else if (provider === "custom") {
293+
if (!config.customEndpoint) {
294+
throw new Error("Custom endpoint is not set");
295+
}
286296
const oai = new OpenAI({
287297
apiKey,
288298
baseURL: config.customEndpoint,

src/run.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ export async function run(options: RunOptions, templateName?: string) {
104104
aiProvider = createOpenAI({
105105
compatibility: 'strict',
106106
apiKey: config.API_KEY,
107-
baseURL: config.customEndpoint,
108107
});
109108
} else if (config.provider === "google") {
110109
aiProvider = createGoogleGenerativeAI({
111110
apiKey: config.API_KEY,
112111
});
112+
} else if (config.provider === "custom") {
113+
aiProvider = createOpenAI({
114+
compatibility: 'strict',
115+
apiKey: config.API_KEY,
116+
baseURL: config.customEndpoint
117+
})
113118
} else {
114119
throw new Error("Invalid provider");
115120
}

0 commit comments

Comments
 (0)