Skip to content

Commit

Permalink
fix: patch api key not persisting when setting LLM/Embedder (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat authored Dec 16, 2023
1 parent ecfd146 commit 65c7c0a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function LocalAIModelSelection({ settings, apiKey = null, basePath = null }) {
return;
}
setLoading(true);
const { models } = await System.customModels("localai", apiKey, basePath);
const { models } = await System.customModels(
"localai",
typeof apiKey === "boolean" ? null : apiKey,
basePath
);
setCustomModels(models || []);
setLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ function LocalAIModelSelection({ settings, basePath = null, apiKey = null }) {
return;
}
setLoading(true);
const { models } = await System.customModels("localai", apiKey, basePath);
const { models } = await System.customModels(
"localai",
typeof apiKey === "boolean" ? null : apiKey,
basePath
);
setCustomModels(models || []);
setLoading(false);
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/LLMSelection/OpenAiOptions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import System from "@/models/system";
export default function OpenAiOptions({ settings }) {
const [inputValue, setInputValue] = useState(settings?.OpenAiKey);
const [openAIKey, setOpenAIKey] = useState(settings?.OpenAiKey);
function updateOpenAiKey() {
setOpenAIKey(inputValue);
}

return (
<>
Expand All @@ -24,7 +21,7 @@ export default function OpenAiOptions({ settings }) {
autoComplete="off"
spellCheck={false}
onChange={(e) => setInputValue(e.target.value)}
onBlur={updateOpenAiKey}
onBlur={() => setOpenAIKey(inputValue)}
/>
</div>
<OpenAIModelSelection settings={settings} apiKey={openAIKey} />
Expand Down
6 changes: 5 additions & 1 deletion server/utils/helpers/customModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ async function openAiModels(apiKey = null) {
(model) => !model.owned_by.includes("openai") && model.owned_by !== "system"
);

// Api Key was successful so lets save it for future uses
if (models.length > 0 && !!apiKey) process.env.OPEN_AI_KEY = apiKey;
return { models, error: null };
}

async function localAIModels(basePath = null, apiKey = null) {
const { Configuration, OpenAIApi } = require("openai");
const config = new Configuration({
basePath,
...(!!apiKey ? { apiKey } : {}),
apiKey: apiKey || process.env.LOCAL_AI_API_KEY,
});
const openai = new OpenAIApi(config);
const models = await openai
Expand All @@ -52,6 +54,8 @@ async function localAIModels(basePath = null, apiKey = null) {
return [];
});

// Api Key was successful so lets save it for future uses
if (models.length > 0 && !!apiKey) process.env.LOCAL_AI_API_KEY = apiKey;
return { models, error: null };
}

Expand Down

0 comments on commit 65c7c0a

Please sign in to comment.