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

support custom api endpoint #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@
"default": false,
"required": false
},
{
"name": "useBaseAPI",
"label": "Use Base API",
"description": "Use base API instead of the default API",
"type": "checkbox",
"title": "Use Base API",
"default": false,
"required": false
},
{
"name": "baseAPI",
"label": "Base API Endpoint",
"description": "Enter your personal Open AI API Endpoint",
"type": "textfield",
"title": "Base API Endpoint",
"default": "https://api.f2gpt.com/v1",
"required": false
},
{
"name": "isAutoTTS",
"label": "Enable text-to-speech for every response",
Expand Down
12 changes: 12 additions & 0 deletions src/hooks/useChatGPT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ export function useChatGPT(): OpenAIApi {

const config = new Configuration({ apiKey });

const baseAPI = getPreferenceValues<{
baseAPI: string;
}>().baseAPI;

const useBaseAPI = getPreferenceValues<{
useBaseAPI: boolean;
}>().useBaseAPI;

if (useBaseAPI) {
config.basePath = baseAPI;
}

return new OpenAIApi(config);
});

Expand Down