Skip to content

Commit 2d8c127

Browse files
committed
Add custom endpoint option for OpenAI-like APIs
Fixes #5 Add support for custom endpoint for OpenAI-like APIs. * **Config Interface**: Add `customEndpoint` field to `Config` interface in `src/config.ts`. * **getModels Function**: Update `getModels` function in `src/config.ts` to support custom endpoints. * **showConfigUI Function**: Update `showConfigUI` function in `src/config.ts` to allow users to set a custom endpoint. * **createOpenAI Function**: Modify `createOpenAI` function in `src/run.ts` to use the custom endpoint if provided. * **Documentation**: Add documentation for custom endpoint option in `README.md`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/m7medVision/lazycommit/issues/5?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 5cf464a commit 2d8c127

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ customCommands:
7272
check out these other projects that inspired this one:
7373
7474
- https://github.com/BuilderIO/ai-shell
75+
76+
## Custom Endpoint
77+
78+
You can now specify a custom endpoint for using OpenAI-like APIs. To set a custom endpoint, use the `bunx @m7medvision/lazycommit@latest config` command and select the "Custom Endpoint" option. This allows you to use different API endpoints that are compatible with OpenAI.

src/config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ function hasOwn<T extends object, K extends PropertyKey>(
6262
export const configPath = path.join(os.homedir(), ".lazycommit");
6363

6464
export interface Config {
65-
provider: "openai" | "google";
65+
provider: "openai" | "google" | "custom";
6666
API_KEY: string;
6767
model: string;
6868
templates: Record<string, string>;
69+
customEndpoint?: string;
6970
}
7071

7172
const DEFAULT_CONFIG: Config = {
@@ -157,6 +158,11 @@ export async function showConfigUI() {
157158
value: "template",
158159
hint: "edit the prompt template",
159160
},
161+
{
162+
label: "Custom Endpoint",
163+
value: "customEndpoint",
164+
hint: config.customEndpoint || "not set",
165+
},
160166
{
161167
label: "Done", // Changed from "Cancel" to "Done"
162168
value: "done",
@@ -235,11 +241,19 @@ export async function showConfigUI() {
235241
options: [
236242
{ label: "OpenAI", value: "openai" },
237243
{ label: "Google", value: "google" },
244+
{ label: "Custom", value: "custom" },
238245
],
239246
initialValue: config.provider,
240247
});
241248

242249
await setConfigs([["provider", provider as string]]);
250+
} else if (choice === "customEndpoint") {
251+
const customEndpoint = await p.text({
252+
message: "Custom Endpoint",
253+
initialValue: config.customEndpoint,
254+
});
255+
256+
await setConfigs([["customEndpoint", customEndpoint as string]]);
243257
}
244258

245259
if (p.isCancel(choice)) {
@@ -263,6 +277,7 @@ async function getModels() {
263277
if (provider === "openai") {
264278
const oai = new OpenAI({
265279
apiKey,
280+
baseURL: config.customEndpoint,
266281
});
267282
const models = await oai.models.list();
268283
return models.data.map((model) => model.id);

src/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export async function run(options: RunOptions, templateName?: string) {
104104
aiProvider = createOpenAI({
105105
compatibility: 'strict',
106106
apiKey: config.API_KEY,
107+
baseURL: config.customEndpoint,
107108
});
108109
} else if (config.provider === "google") {
109110
aiProvider = createGoogleGenerativeAI({
@@ -133,4 +134,4 @@ export async function run(options: RunOptions, templateName?: string) {
133134
console.error(`Failed to fetch from AI service: ${error}`);
134135
process.exit(1);
135136
}
136-
}
137+
}

0 commit comments

Comments
 (0)