Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Check the OpenAI-compatible key again when its base URL changes, and find it by "venice"

AdityaUmale78af50906707
diff --git a/docs/custom-engines.md b/docs/custom-engines.md
index ab3d435542..1daab47701 100644
--- a/docs/custom-engines.md
+++ b/docs/custom-engines.md
@@ -217,6 +217,16 @@ Both services document this general API setup and their current model IDs
in their OpenAI compatibility guides. See the [Z.ai guide](https://docs.z.ai/guides/develop/openai/python)
and the [Zhipu BigModel guide](https://docs.bigmodel.cn/cn/guide/develop/openai/introduction).
+### Example: Venice AI
+
+Venice serves an OpenAI-compatible API, so it needs no custom instance. Open
+**Keys**, find the **Other (OpenAI-compatible)** row (searching "venice" finds
+it), set the base URL to `https://api.venice.ai/api/v1` and paste your Venice
+API key. The key is checked against the base URL saved with it, and changing
+the URL checks the saved key again. To give Venice its own bot next to another
+OpenAI-compatible server, use the `openai-compat` instance above with that base
+URL instead.
+
## Notes
- `config.json` is written with mode 0600; values in `environment` are stored
diff --git a/src/components/keys/KeyRow.tsx b/src/components/keys/KeyRow.tsx
index cff3f97a56..e345f6144a 100644
--- a/src/components/keys/KeyRow.tsx
+++ b/src/components/keys/KeyRow.tsx
@@ -174,12 +174,17 @@ export function KeyRow({
: saved.included ? { tone: "ok", text: t("keys.includedWithCloudPro") }
: null;
+ const testAt = state.config && target.testAt ? target.testAt(state.config) ?? "" : null;
+ const checkedAt = useRef(testAt);
+
const runCheck = async (): Promise<KeyResult> => {
if (!target.test) return "unverified";
const mine = ++generation.current;
+ const at = checkedAt.current;
setBusy("checking");
try {
const check = await checkKey(target.test);
+ if (mine === generation.current && checkedAt.current !== at) return await runCheck();
if (mine === generation.current) {
setWorks(check.ok);
setVerdict(check.ok ? check.text : null);
@@ -257,6 +262,12 @@ export function KeyRow({
}
};
+ useEffect(() => {
+ const before = checkedAt.current;
+ checkedAt.current = testAt;
+ if (before !== null && testAt !== null && before !== testAt && saved.configured) void recheck();
+ }, [testAt]);
+
const remove = async () => {
if (busyRef.current) return;
busyRef.current = true;
diff --git a/src/components/keys/KeysPage.dom.test.ts b/src/components/keys/KeysPage.dom.test.ts
index a55a014fd2..7b72bfe6c7 100644
--- a/src/components/keys/KeysPage.dom.test.ts
+++ b/src/components/keys/KeysPage.dom.test.ts
@@ -312,6 +312,79 @@ describe("the OpenAI-compatible server row", () => {
});
});
+describe("the OpenAI-compatible key check", () => {
+ it("checks the saved key again at the base URL typed after it, such as Venice", async () => {
+ fx.config = { ...fx.config, openaiCompat: { configured: true, last4: "1234" } };
+ const tested: Array<string | undefined> = [];
+ fx.api.mockImplementation(async (path: string, init: { body: string }) => {
+ if (path === "/api/config") return { ...fx.config, openaiCompat: { ...(fx.config.openaiCompat as object), ...JSON.parse(init.body).openaiCompat } };
+ if (path !== "/api/keys/test") return {};
+ const url = (fx.config.openaiCompat as { url?: string }).url;
+ tested.push(url);
+ return url === "https://api.venice.ai/api/v1" ? { ok: true, check: "models", models: ["venice-uncensored"] } : { ok: false, reason: "rejected" };
+ });
+ page();
+ flushSync(() => section("servers").querySelector<HTMLButtonElement>("button[aria-expanded]")!.click());
+ const url = row("openaiCompat")!.querySelector<HTMLInputElement>('input[aria-label="OpenAI-compatible base URL"]')!;
+ type(url, "https://api.venice.ai/api/v1");
+ flushSync(() => url.dispatchEvent(new FocusEvent("focusout", { bubbles: true })));
+ await vi.waitFor(() => expect(row("openaiCompat")!.textContent).toContain("venice-uncensored"));
+ expect(tested).toEqual(["https://api.venice.ai/api/v1"]);
+ expect(row("openaiCompat")!.textContent).not.toContain("Didn't work");
+ });
+
+ it("checks again when the base URL changes while a check is still running", async () => {
+ fx.config = { ...fx.config, openaiCompat: { configured: true, last4: "1234" } };
+ const tested: Array<string | undefined> = [];
+ let answerFirst: (result: unknown) => void = () => {};
+ fx.api.mockImplementation((path: string) => {
+ if (path !== "/api/keys/test") return Promise.resolve({});
+ const url = (fx.config.openaiCompat as { url?: string }).url;
+ tested.push(url);
+ if (tested.length === 1) return new Promise((resolve) => { answerFirst = resolve; });
+ return Promise.resolve({ ok: true, check: "models", models: ["venice-uncensored"] });
+ });
+ page();
+ flushSync(() => section("servers").querySelector<HTMLButtonElement>("button[aria-expanded]")!.click());
+ flushSync(() => setConfig({ ...fx.config, openaiCompat: { configured: true, last4: "1234", url: "https://api.example.test/v1" } }));
+ await vi.waitFor(() => expect(tested).toEqual(["https://api.example.test/v1"]));
+ flushSync(() => setConfig({ ...fx.config, openaiCompat: { configured: true, last4: "1234", url: "https://api.venice.ai/api/v1" } }));
+ answerFirst({ ok: false, reason: "rejected" });
+ await vi.waitFor(() => expect(row("openaiCompat")!.textContent).toContain("venice-uncensored"));
+ expect(tested).toEqual(["https://api.example.test/v1", "https://api.venice.ai/api/v1"]);
+ expect(row("openaiCompat")!.textContent).not.toContain("Didn't work");
+ });
+
+ it("does not check the key when the page opens or nothing about the address changed", async () => {
+ fx.config = { ...fx.config, openaiCompat: { configured: true, last4: "1234", url: "https://api.venice.ai/api/v1" } };
+ fx.api.mockResolvedValue({});
+ page();
+ flushSync(() => section("servers").querySelector<HTMLButtonElement>("button[aria-expanded]")!.click());
+ flushSync(() => setConfig({ ...fx.config, openaiCompat: { configured: true, last4: "1234", url: "https://api.venice.ai/api/v1" } }));
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(fx.api.mock.calls.map(([path]) => path)).not.toContain("/api/keys/test");
+ });
+
+ it("does not check when no key is saved yet", async () => {
+ fx.api.mockImplementation(async (path: string, init: { body: string }) => (path === "/api/config" ? { ...fx.config, openaiCompat: JSON.parse(init.body).openaiCompat } : {}));
+ page();
+ flushSync(() => section("servers").querySelector<HTMLButtonElement>("button[aria-expanded]")!.click());
+ const url = row("openaiCompat")!.querySelector<HTMLInputElement>('input[aria-label="OpenAI-compatible base URL"]')!;
+ type(url, "https://api.venice.ai/api/v1");
+ flushSync(() => url.dispatchEvent(new FocusEvent("focusout", { bubbles: true })));
+ await vi.waitFor(() => expect(fx.api.mock.calls.map(([path]) => path)).toContain("/api/config"));
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(fx.api.mock.calls.map(([path]) => path)).not.toContain("/api/keys/test");
+ });
+
+ it("is found by searching for Venice", () => {
+ page();
+ const search = host.querySelector<HTMLInputElement>("[data-keys-search]")!;
+ type(search, "venice");
+ expect(rowsShown()).toContain("openaiCompat");
+ });
+});
+
describe("the Ollama row", () => {
const openServers = () => flushSync(() => section("servers").querySelector<HTMLButtonElement>("button[aria-expanded]")!.click());
const button = (text: string) => [...row("ollama")!.querySelectorAll("button")].find((candidate) => candidate.textContent === text)!;
diff --git a/src/components/keys/key-catalog.ts b/src/components/keys/key-catalog.ts
index ae8968f0bf..f13d66f58a 100644
--- a/src/components/keys/key-catalog.ts
+++ b/src/components/keys/key-catalog.ts
@@ -35,6 +35,8 @@ export interface KeyTarget {
placeholderKey?: LocaleKey;
href?: string;
test?: TestableProvider;
+ /** The address the check sends the key to, when it is set beside the key: a new address checks the saved key again. */
+ testAt?: (config: ConfigStatus) => string | undefined;
verifiedOnSave?: boolean;
analytics: KeyProvider;
shape?: RegExp;
@@ -130,9 +132,9 @@ export const KEY_CATALOG: readonly KeyEntry[] = [
{ id: "lmStudio", section: "servers", labelKey: "lmStudio.title", purposeKey: "keys.purpose.lmStudio", name: "LM Studio", env: [],
words: ["lm studio", "lmstudio", "llm studio", "local", "bionic"], mark: { icon: Server }, kind: "panel" },
{ id: "openaiCompat", section: "servers", labelKey: "keys.openaiCompat.label", purposeKey: "keys.purpose.openaiCompat", name: "OpenAI-compatible", env: ["OPENAI_COMPAT_API_KEY", "OPENAI_COMPAT_URL"],
- words: ["openai-compatible", "openai compatible", "together", "gemini", "google ai studio", "base url", "server", "endpoint"], mark: { icon: Server }, kind: "key",
+ words: ["openai-compatible", "openai compatible", "together", "venice", "gemini", "google ai studio", "base url", "server", "endpoint"], mark: { icon: Server }, kind: "key",
target: { patch: (value) => ({ openaiCompat: { key: value } }), slot: "openaiCompatApiKey", saved: (config) => flag(config.openaiCompat), placeholder: "…", placeholderKey: "keys.openaiCompat.placeholder",
- href: "https://platform.openai.com/docs/api-reference", test: "openaiCompat", analytics: "openai_compat" } },
+ href: "https://platform.openai.com/docs/api-reference", test: "openaiCompat", testAt: (config) => config.openaiCompat?.url, analytics: "openai_compat" } },
{ id: "liveCalls", section: "voice", labelKey: "call.live.key", purposeKey: "keys.purpose.liveCalls", name: "OpenAI", env: [],
words: ["openai", "live calls", "calls", "voice", "talk", "gpt-live", "read aloud", "speech", "tts"], mark: { icon: Phone }, kind: "uses", uses: "openai" },
{ id: "liveKey", section: "voice", labelKey: "keys.label.liveKey", purposeKey: "keys.purpose.liveKey", name: "OpenAI", env: ["OMB_OPENAI_LIVE_KEY"],