From f553f07ec5d1f2019732cb5f5d543fd97f97f777 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Mon, 15 Jul 2024 11:39:48 -0700 Subject: [PATCH] [FEAT] Implement auto detect URL for KoboldCPP (#1860) * implement auto detect url for koboldcpp * remove unneeded import * border-none inputs and buttons --------- Co-authored-by: timothycarambat --- .../LLMSelection/KoboldCPPOptions/index.jsx | 179 +++++++++++++----- frontend/src/utils/constants.js | 7 + 2 files changed, 139 insertions(+), 47 deletions(-) diff --git a/frontend/src/components/LLMSelection/KoboldCPPOptions/index.jsx b/frontend/src/components/LLMSelection/KoboldCPPOptions/index.jsx index 98c70785..57fedc62 100644 --- a/frontend/src/components/LLMSelection/KoboldCPPOptions/index.jsx +++ b/frontend/src/components/LLMSelection/KoboldCPPOptions/index.jsx @@ -1,47 +1,116 @@ -import { useState, useEffect } from "react"; +import { useEffect, useState } from "react"; import System from "@/models/system"; +import PreLoader from "@/components/Preloader"; +import { KOBOLDCPP_COMMON_URLS } from "@/utils/constants"; +import { CaretDown, CaretUp } from "@phosphor-icons/react"; +import useProviderEndpointAutoDiscovery from "@/hooks/useProviderEndpointAutoDiscovery"; export default function KoboldCPPOptions({ settings }) { - const [basePathValue, setBasePathValue] = useState( - settings?.KoboldCPPBasePath + const { + autoDetecting: loading, + basePath, + basePathValue, + showAdvancedControls, + setShowAdvancedControls, + handleAutoDetectClick, + } = useProviderEndpointAutoDiscovery({ + provider: "koboldcpp", + initialBasePath: settings?.KoboldCPPBasePath, + ENDPOINTS: KOBOLDCPP_COMMON_URLS, + }); + + const [tokenLimit, setTokenLimit] = useState( + settings?.KoboldCPPTokenLimit || 4096 ); - const [basePath, setBasePath] = useState(settings?.KoboldCPPBasePath); + + const handleTokenLimitChange = (e) => { + setTokenLimit(Number(e.target.value)); + }; return ( -
-
- - setBasePathValue(e.target.value)} - onBlur={() => setBasePath(basePathValue)} +
+
+ +
+ + e.target.blur()} + required={true} + autoComplete="off" + /> +

+ Maximum number of tokens for context and response. +

+
- -
- - e.target.blur()} - defaultValue={settings?.KoboldCPPTokenLimit} - required={true} - autoComplete="off" - /> +
+ +
+ +
); @@ -59,8 +128,17 @@ function KoboldCPPModelSelection({ settings, basePath = null }) { return; } setLoading(true); - const { models } = await System.customModels("koboldcpp", null, basePath); - setCustomModels(models || []); + try { + const { models } = await System.customModels( + "koboldcpp", + null, + basePath + ); + setCustomModels(models || []); + } catch (error) { + console.error("Failed to fetch custom models:", error); + setCustomModels([]); + } setLoading(false); } findCustomModels(); @@ -69,44 +147,51 @@ function KoboldCPPModelSelection({ settings, basePath = null }) { if (loading || customModels.length === 0) { return (
-
); } return (
-
); } diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index a08439d0..334079ce 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -23,6 +23,13 @@ export const LMSTUDIO_COMMON_URLS = [ "http://172.17.0.1:1234/v1", ]; +export const KOBOLDCPP_COMMON_URLS = [ + "http://127.0.0.1:5000/v1", + "http://localhost:5000/v1", + "http://host.docker.internal:5000/v1", + "http://172.17.0.1:5000/v1", +]; + export function fullApiUrl() { if (API_BASE !== "/api") return API_BASE; return `${window.location.origin}/api`;