Skip to content

Commit

Permalink
[FEAT] Add API key support for Oobabooga Web UI (#1354)
Browse files Browse the repository at this point in the history
* add api key support for oobabooga web ui

* dont expose API Key for TextWebGenUi

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
  • Loading branch information
shatfield4 and timothycarambat committed May 13, 2024
1 parent f0365d4 commit 9ed2309
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GID='1000'
# LLM_PROVIDER='textgenwebui'
# TEXT_GEN_WEB_UI_BASE_PATH='http://127.0.0.1:5000/v1'
# TEXT_GEN_WEB_UI_TOKEN_LIMIT=4096
# TEXT_GEN_WEB_UI_API_KEY='sk-123abc'

# LLM_PROVIDER='generic-openai'
# GENERIC_OPEN_AI_BASE_PATH='http://proxy.url.openai.com/v1'
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/components/LLMSelection/TextGenWebUIOptions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default function TextGenWebUIOptions({ settings }) {
autoComplete="off"
/>
</div>
<div className="flex flex-col w-60">
<label className="text-white text-sm font-semibold block mb-4">
API Key (Optional)
</label>
<input
type="password"
name="TextGenWebUIAPIKey"
className="bg-zinc-900 text-white placeholder:text-white/20 text-sm rounded-lg focus:border-white block w-full p-2.5"
placeholder="TextGen Web UI API Key"
defaultValue={settings?.TextGenWebUIAPIKey ? "*".repeat(20) : ""}
autoComplete="off"
spellCheck={false}
/>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ JWT_SECRET="my-random-string-for-seeding" # Please generate random string at lea
# LLM_PROVIDER='textgenwebui'
# TEXT_GEN_WEB_UI_BASE_PATH='http://127.0.0.1:5000/v1'
# TEXT_GEN_WEB_UI_TOKEN_LIMIT=4096
# TEXT_GEN_WEB_UI_API_KEY='sk-123abc'

# LLM_PROVIDER='generic-openai'
# GENERIC_OPEN_AI_BASE_PATH='http://proxy.url.openai.com/v1'
Expand Down
1 change: 1 addition & 0 deletions server/models/systemSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ const SystemSettings = {
// Text Generation Web UI Keys
TextGenWebUIBasePath: process.env.TEXT_GEN_WEB_UI_BASE_PATH,
TextGenWebUITokenLimit: process.env.TEXT_GEN_WEB_UI_MODEL_TOKEN_LIMIT,
TextGenWebUIAPIKey: !!process.env.TEXT_GEN_WEB_UI_API_KEY,

// Generic OpenAI Keys
GenericOpenAiBasePath: process.env.GENERIC_OPEN_AI_BASE_PATH,
Expand Down
2 changes: 1 addition & 1 deletion server/utils/AiProviders/textGenWebUI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TextGenWebUILLM {
this.basePath = process.env.TEXT_GEN_WEB_UI_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
apiKey: null,
apiKey: process.env.TEXT_GEN_WEB_UI_API_KEY ?? null,
});
this.model = null;
this.limits = {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/agents/aibitat/providers/textgenwebui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TextWebGenUiProvider extends InheritMultiple([Provider, UnTooled]) {
super();
const client = new OpenAI({
baseURL: process.env.TEXT_GEN_WEB_UI_BASE_PATH,
apiKey: null,
apiKey: process.env.TEXT_GEN_WEB_UI_API_KEY ?? null,
maxRetries: 3,
});

Expand Down
4 changes: 4 additions & 0 deletions server/utils/helpers/updateENV.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ const KEY_MAPPING = {
envKey: "TEXT_GEN_WEB_UI_MODEL_TOKEN_LIMIT",
checks: [nonZero],
},
TextGenWebUIAPIKey: {
envKey: "TEXT_GEN_WEB_UI_API_KEY",
checks: [],
},

// Generic OpenAI InferenceSettings
GenericOpenAiBasePath: {
Expand Down

0 comments on commit 9ed2309

Please sign in to comment.