diff --git a/extensions/chatgpt/CHANGELOG.md b/extensions/chatgpt/CHANGELOG.md index 352996903ad..fa033ae6b97 100644 --- a/extensions/chatgpt/CHANGELOG.md +++ b/extensions/chatgpt/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Fix & Feature] - May, 18 2023 + +- Feature: Custom API Endpoint +- Fix: 404 error code while Use Azure is enabled + ## [Fix & Feature] - May, 2023 - Feature: Azure OpenAI ([@sykuang](https://github.com/abielzulio/chatgpt-raycast/pull/36)) diff --git a/extensions/chatgpt/README.md b/extensions/chatgpt/README.md index 4ca9912813b..83778aad0bf 100644 --- a/extensions/chatgpt/README.md +++ b/extensions/chatgpt/README.md @@ -65,23 +65,24 @@ This extension requires a valid `Secret Key` as your API Key from [OpenAI](https All preferences properties list that can be customize through `Raycast Settings > Extensions > ChatGPT` -| Properties | Label | Value | Required | Default | Description | -| ------------------------ | ---------------------- | ----------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------- | -| `apiKey` | API Key | `string` | `true` | `empty` | Your personal OpenAI API key | -| `useStream` | Stream Completion | `boolean` | `true` | `true` | Stream the completions of the generated answer | -| `isAutoSaveConversation` | Auto-save Conversation | `boolean` | `true` | `true` | Auto-save every conversation that you had with the model | -| `isHistoryPaused` | Pause History | `boolean` | `false` | `false` | Pause the history of the conversation | -| `isAutoLoadText` | Auto-load | `boolean` | `false` | `false` | Load selected text from your frontmost application to the `question bar` or `full text input form` automatically | -| `isAutoFullInput` | Use Full Text Input | `boolean` | `false` | `false` | Switch to `full text input form` from `question bar` automatically whenever you want to ask or type a question | -| `isAutoTTS` | Text-to-Speech | `boolean` | `false` | `false` | Enable auto text-to-speech everytime you get a generated answer | -| `useProxy` | Use Proxy | `boolean` | `false` | `false` | Each question request will be passed through the proxy | -| `proxyProtocol` | Proxy Protocol | `http`, `https`, `socks4`, `socks5` | `false` | `http` | Proxy protocol option | -| `proxyHost` | Proxy Host | `string` | `false` | `empty` | Proxy host value | -| `proxyUsername` | Proxy Username | `string` | `false` | `empty` | Proxy username value | -| `proxyPassword` | Proxy Password | `string` | `false` | `empty` | Proxy password value | -| `useAzure` | Use Azure OpenAI | `boolean` | `true` | `false` | Use Azure OPENAI rather than OPENAI | -| `azureEndpoint` | Azure Endpoint | `string` | `false` | `empty` | Azure OpenAI resource endpoint | -| `azureDeploymentName` | Azure Deployment | `string` | `false` | `empty` | Azure OpenAI resource deployment | +| Properties | Label | Value | Required | Default | Description | +| ------------------------ | ---------------------- | ----------------------------------- | -------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| `apiKey` | API Key | `string` | `true` | `empty` | Your personal OpenAI API key | +| `useStream` | Stream Completion | `boolean` | `true` | `true` | Stream the completions of the generated answer | +| `isAutoSaveConversation` | Auto-save Conversation | `boolean` | `true` | `true` | Auto-save every conversation that you had with the model | +| `isHistoryPaused` | Pause History | `boolean` | `false` | `false` | Pause the history of the conversation | +| `isAutoLoadText` | Auto-load | `boolean` | `false` | `false` | Load selected text from your frontmost application to the `question bar` or `full text input form` automatically | +| `isAutoFullInput` | Use Full Text Input | `boolean` | `false` | `false` | Switch to `full text input form` from `question bar` automatically whenever you want to ask or type a question | +| `isAutoTTS` | Text-to-Speech | `boolean` | `false` | `false` | Enable auto text-to-speech everytime you get a generated answer | +| `apiEndpoint` | API Endpoint | `string` | `false` | `https://api.openai.com/v1` | Change the OpenAI's default API endpoint to custom endpoint | +| `useProxy` | Use Proxy | `boolean` | `false` | `false` | Each question request will be passed through the proxy | +| `proxyProtocol` | Proxy Protocol | `http`, `https`, `socks4`, `socks5` | `false` | `http` | Proxy protocol option | +| `proxyHost` | Proxy Host | `string` | `false` | `empty` | Proxy host value | +| `proxyUsername` | Proxy Username | `string` | `false` | `empty` | Proxy username value | +| `proxyPassword` | Proxy Password | `string` | `false` | `empty` | Proxy password value | +| `useAzure` | Use Azure OpenAI | `boolean` | `true` | `false` | Use Azure OPENAI rather than OPENAI | +| `azureEndpoint` | Azure Endpoint | `string` | `false` | `empty` | Azure OpenAI resource endpoint | +| `azureDeploymentName` | Azure Deployment | `string` | `false` | `empty` | Azure OpenAI resource deployment | ### How to use Azure OpenAI diff --git a/extensions/chatgpt/package.json b/extensions/chatgpt/package.json index 077e0bf56af..de03acd422e 100644 --- a/extensions/chatgpt/package.json +++ b/extensions/chatgpt/package.json @@ -95,7 +95,7 @@ "description": "Pause the history of the conversation", "type": "checkbox", "title": "Pause History", - "default": true, + "default": false, "required": false }, { @@ -125,6 +125,15 @@ "required": false, "default": false }, + { + "name": "apiEndpoint", + "label": "Change API Endpoint", + "description": "Change the OpenAI's default API endpoint to custom endpoint", + "type": "checkbox", + "title": "API Endpoint", + "placeholder": "https://api.openai.com/v1", + "required": false + }, { "name": "useProxy", "label": "Enable proxy for each request", @@ -162,7 +171,7 @@ }, { "name": "proxyHost", - "description": "Sever address of the proxy", + "description": "Server address of the proxy", "type": "textfield", "title": "Proxy Host", "required": false diff --git a/extensions/chatgpt/src/hooks/useChatGPT.tsx b/extensions/chatgpt/src/hooks/useChatGPT.tsx index d9925af3d45..872db4bc216 100644 --- a/extensions/chatgpt/src/hooks/useChatGPT.tsx +++ b/extensions/chatgpt/src/hooks/useChatGPT.tsx @@ -5,20 +5,18 @@ import { ConfigurationPreferences } from "../type"; export function useChatGPT(): OpenAIApi { const [chatGPT] = useState(() => { - const preferences = getPreferenceValues<{ - apiKey: string; - useAzure: boolean; - azureEndpoint: string; - azureDeployment: string; - }>(); - const getConfig = function ({ useAzure, apiKey, azureEndpoint, azureDeployment }: ConfigurationPreferences) { - if (useAzure) { + const preferences = getPreferenceValues(); + const getConfig = function (params: ConfigurationPreferences) { + if (params.useAzure) { return new Configuration({ - apiKey, - basePath: azureEndpoint + "/openai/deployments/" + azureDeployment, + apiKey: params.apiKey, + basePath: params.azureEndpoint + "/openai/deployments/" + params.azureDeployment, }); } else { - return new Configuration({ apiKey }); + return new Configuration({ + apiKey: params.apiKey, + basePath: params.apiEndpoint ?? "https://api.openai.com/v1", + }); } }; const config = getConfig(preferences); @@ -28,10 +26,5 @@ export function useChatGPT(): OpenAIApi { } export function getConfiguration(): ConfigurationPreferences { - return getPreferenceValues<{ - apiKey: string; - useAzure: boolean; - azureEndpoint: string; - azureDeployment: string; - }>(); + return getPreferenceValues(); } diff --git a/extensions/chatgpt/src/hooks/useModel.tsx b/extensions/chatgpt/src/hooks/useModel.tsx index c2810d7f67c..f86ffd5345d 100644 --- a/extensions/chatgpt/src/hooks/useModel.tsx +++ b/extensions/chatgpt/src/hooks/useModel.tsx @@ -1,7 +1,7 @@ import { LocalStorage, showToast, Toast } from "@raycast/api"; import { useCallback, useEffect, useMemo, useState } from "react"; import { Model, ModelHook } from "../type"; -import { useChatGPT } from "./useChatGPT"; +import { getConfiguration, useChatGPT } from "./useChatGPT"; export const DEFAULT_MODEL: Model = { id: "default", @@ -17,16 +17,17 @@ export const DEFAULT_MODEL: Model = { export function useModel(): ModelHook { const [data, setData] = useState([]); const [isLoading, setLoading] = useState(true); - const gpt = useChatGPT(); - + const { useAzure, azureDeployment } = getConfiguration(); const [option, setOption] = useState(["gpt-3.5-turbo", "gpt-3.5-turbo-0301"]); useEffect(() => { - gpt.listModels().then((res) => { - const models = res.data.data; - setOption(models.filter((m) => m.id.startsWith("gpt")).map((x) => x.id)); - }); + if (!useAzure) { + gpt.listModels().then((res) => { + const models = res.data.data; + setOption(models.filter((m) => m.id.startsWith("gpt")).map((x) => x.id)); + }); + } }, [gpt]); useEffect(() => { diff --git a/extensions/chatgpt/src/hooks/useQuestion.tsx b/extensions/chatgpt/src/hooks/useQuestion.tsx index 9dd56a0cd74..4aa07e74f56 100644 --- a/extensions/chatgpt/src/hooks/useQuestion.tsx +++ b/extensions/chatgpt/src/hooks/useQuestion.tsx @@ -24,6 +24,11 @@ export function useQuestion(props: { initialQuestion: string; disableAutoLoad?: style: Toast.Style.Success, title: "Selected text loaded!", }); + } else { + await showToast({ + style: Toast.Style.Success, + title: "No text selected!", + }); } } catch (error) { await showToast({ diff --git a/extensions/chatgpt/src/type.ts b/extensions/chatgpt/src/type.ts index 0a52dcaad51..502bc1d9a9c 100644 --- a/extensions/chatgpt/src/type.ts +++ b/extensions/chatgpt/src/type.ts @@ -122,4 +122,5 @@ export interface ConfigurationPreferences { useAzure: boolean; azureEndpoint: string; azureDeployment: string; + apiEndpoint: string; }