-
Notifications
You must be signed in to change notification settings - Fork 543
feat: simplify connection status check for Ollama and LM Studio #3804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fdaaad5
18b1f1e
85bfe9d
c13d287
589f3b1
fdaf00e
eeb5b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||
| import { useQuery } from "@tanstack/react-query"; | ||||||||||||||||||
| import { fetch as tauriFetch } from "@tauri-apps/plugin-http"; | ||||||||||||||||||
|
|
||||||||||||||||||
| import * as settings from "../../../../store/tinybase/store/settings"; | ||||||||||||||||||
|
|
||||||||||||||||||
| export type LocalProviderStatus = "connected" | "disconnected" | "checking"; | ||||||||||||||||||
|
|
||||||||||||||||||
| const LOCAL_PROVIDERS = new Set(["ollama", "lmstudio"]); | ||||||||||||||||||
|
|
||||||||||||||||||
| const DEFAULT_URLS: Record<string, string> = { | ||||||||||||||||||
| ollama: "http://127.0.0.1:11434/v1", | ||||||||||||||||||
| lmstudio: "http://127.0.0.1:1234/v1", | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| async function checkConnection(baseUrl: string): Promise<boolean> { | ||||||||||||||||||
| const controller = new AbortController(); | ||||||||||||||||||
| const timeout = setTimeout(() => controller.abort(), 2000); | ||||||||||||||||||
| try { | ||||||||||||||||||
| const res = await tauriFetch(`${baseUrl}/models`, { | ||||||||||||||||||
| signal: controller.signal, | ||||||||||||||||||
| }); | ||||||||||||||||||
| return res.ok; | ||||||||||||||||||
| } catch { | ||||||||||||||||||
| return false; | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| clearTimeout(timeout); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export function useLocalProviderStatus(providerId: string): { | ||||||||||||||||||
| status: LocalProviderStatus | null; | ||||||||||||||||||
| refetch: () => void; | ||||||||||||||||||
| } { | ||||||||||||||||||
| const isLocal = LOCAL_PROVIDERS.has(providerId); | ||||||||||||||||||
|
|
||||||||||||||||||
| const configuredProviders = settings.UI.useResultTable( | ||||||||||||||||||
| settings.QUERIES.llmProviders, | ||||||||||||||||||
| settings.STORE_ID, | ||||||||||||||||||
| ); | ||||||||||||||||||
| const baseUrl = String( | ||||||||||||||||||
| configuredProviders[providerId]?.base_url || DEFAULT_URLS[providerId] || "", | ||||||||||||||||||
| ).trim(); | ||||||||||||||||||
|
Comment on lines
+40
to
+42
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Wrong key used to look up provider config — user-customized base URL is never read The Root Cause and ImpactEvery other place in the codebase that accesses this result table uses Because Impact: If a user customizes the base URL for Ollama or LM Studio (e.g., changes the port or host), the connection status check will still ping the default URL (
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||
|
|
||||||||||||||||||
| const query = useQuery({ | ||||||||||||||||||
| enabled: isLocal && !!baseUrl, | ||||||||||||||||||
| queryKey: ["local-provider-status", providerId, baseUrl], | ||||||||||||||||||
| queryFn: () => checkConnection(baseUrl), | ||||||||||||||||||
| staleTime: 10_000, | ||||||||||||||||||
| refetchInterval: 15_000, | ||||||||||||||||||
| retry: false, | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!isLocal) { | ||||||||||||||||||
| return { status: null, refetch: () => {} }; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const status: LocalProviderStatus = | ||||||||||||||||||
| query.isLoading || (query.isFetching && !query.data) | ||||||||||||||||||
| ? "checking" | ||||||||||||||||||
| : query.data | ||||||||||||||||||
| ? "connected" | ||||||||||||||||||
| : "disconnected"; | ||||||||||||||||||
|
|
||||||||||||||||||
| return { status, refetch: () => void query.refetch() }; | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Removed local setup guide link from LLM configure page header
The old code had a prominent "Local setup guide" link in the
ConfigureProvidersheader (linking tohyprnote.com/docs/faq/local-llm-setup). This was removed entirely from the header, and also the inline setup guide links in the provider context strings for Ollama and LM Studio were stripped (configure.tsx:80,82). The replacement is the newlinks.setupentries inshared.tsx:59-62,78-81which render inside the accordion content viashared/index.tsx:248-258. However, these links are nested inside aconfig.links.modelsconditional block — the setup link only renders ifconfig.links.modelsis also defined. This coupling is a bit fragile; if someone adds a provider withsetupbut nomodelslink, the setup link won't appear.Was this helpful? React with 👍 or 👎 to provide feedback.