Merge pull request #2339 from continuedev/pe/ollama-connect-exp-backoff
fix: only check ollama status every 3s
This commit is contained in:
commit
7761ea806a
7 changed files with 44 additions and 62 deletions
|
|
@ -7,7 +7,7 @@ sidebar_position: 1
|
|||
|
||||
An "autocomplete model" is an LLM that is trained on a special format called fill-in-the-middle (FIM). This format is designed to be given the prefix and suffix of a code file and predict what goes between. This task is very specific, which on one hand means that the models can be smaller (even a 3B parameter model can perform well). On the other hand, this means that Chat models, though larger, will perform poorly.
|
||||
|
||||
In Continue, these models are used to display inline [Autocomplete](../../chat/how-to-use-it.md) suggestions as you type.
|
||||
In Continue, these models are used to display inline [Autocomplete](../../autocomplete/how-to-use-it.md) suggestions as you type.
|
||||
|
||||
## Recommended Autocomplete models
|
||||
|
||||
|
|
|
|||
|
|
@ -5,31 +5,27 @@ import {
|
|||
import { useState, useContext } from "react";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { providers } from "../../../pages/AddNewModel/configs/providers";
|
||||
import { useCheckOllamaModels } from "../hooks/useCheckOllamaModels";
|
||||
import { StyledActionButton } from "../..";
|
||||
import OllamaCompletedStep from "./OllamaCompletedStep";
|
||||
import { OllamaConnectionStatuses } from "../utils";
|
||||
|
||||
interface OllamaStatusProps {
|
||||
onConnectionVerified: () => void;
|
||||
isOllamaConnected: boolean;
|
||||
}
|
||||
|
||||
const {
|
||||
ollama: { downloadUrl },
|
||||
} = providers;
|
||||
|
||||
export function OllamaStatus({ onConnectionVerified }: OllamaStatusProps) {
|
||||
export function OllamaStatus({ isOllamaConnected }: OllamaStatusProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const [status, setStatus] = useState<OllamaConnectionStatuses>(
|
||||
OllamaConnectionStatuses.WaitingToDownload,
|
||||
isOllamaConnected
|
||||
? OllamaConnectionStatuses.Connected
|
||||
: OllamaConnectionStatuses.WaitingToDownload,
|
||||
);
|
||||
|
||||
useCheckOllamaModels((models) => {
|
||||
setStatus(OllamaConnectionStatuses.Verified);
|
||||
onConnectionVerified();
|
||||
});
|
||||
|
||||
function onClickDownload() {
|
||||
ideMessenger.post("openUrl", downloadUrl);
|
||||
setStatus(OllamaConnectionStatuses.Downloading);
|
||||
|
|
@ -52,7 +48,7 @@ export function OllamaStatus({ onConnectionVerified }: OllamaStatusProps) {
|
|||
<ArrowPathIcon className="h-4 w-4 animate-spin-slow mr-1" />
|
||||
</div>
|
||||
);
|
||||
case OllamaConnectionStatuses.Verified:
|
||||
case OllamaConnectionStatuses.Connected:
|
||||
return (
|
||||
<OllamaCompletedStep text="Ollama is running at http://localhost:11434" />
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
export * from "./useCheckOllamaModels";
|
||||
export * from "./useSubmitOnboarding";
|
||||
export * from "./useOnboardingCard";
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
import { useContext, useEffect } from "react";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { ONBOARDING_LOCAL_MODEL_TITLE } from "core/config/onboarding";
|
||||
|
||||
const CHECK_OLLAMA_CONNECTION_INTERVAL = 1000;
|
||||
|
||||
export const useCheckOllamaModels = (
|
||||
onDownloadedModels: (models: string[]) => void,
|
||||
) => {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDownloadedModels = async () => {
|
||||
const result = (await ideMessenger.request("llm/listModels", {
|
||||
title: ONBOARDING_LOCAL_MODEL_TITLE,
|
||||
})) as any;
|
||||
|
||||
if (result.status === "success") {
|
||||
const models = result.content;
|
||||
|
||||
if (Array.isArray(models)) {
|
||||
onDownloadedModels(models);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fetchDownloadedModels();
|
||||
|
||||
const interval = setInterval(
|
||||
fetchDownloadedModels,
|
||||
CHECK_OLLAMA_CONNECTION_INTERVAL,
|
||||
);
|
||||
|
||||
return () => {
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
};
|
||||
}, [ideMessenger, onDownloadedModels]);
|
||||
};
|
||||
|
|
@ -13,7 +13,9 @@ import { hasPassedFTL } from "../../../util/freeTrial";
|
|||
import AddModelButtonSubtext from "../../AddModelButtonSubtext";
|
||||
import OllamaModelDownload from "../components/OllamaModelDownload";
|
||||
import { OllamaStatus } from "../components/OllamaStatus";
|
||||
import { useCheckOllamaModels, useSubmitOnboarding } from "../hooks";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
|
||||
const OLLAMA_CHECK_INTERVAL_MS = 3000;
|
||||
|
||||
function OnboardingLocalTab() {
|
||||
const dispatch = useDispatch();
|
||||
|
|
@ -52,19 +54,40 @@ function OnboardingLocalTab() {
|
|||
}
|
||||
}, [downloadedOllamaModels, isOllamaConnected]);
|
||||
|
||||
useCheckOllamaModels((models) => {
|
||||
setDownloadedOllamaModels(models);
|
||||
});
|
||||
useEffect(() => {
|
||||
const fetchDownloadedModels = async () => {
|
||||
try {
|
||||
const result = (await ideMessenger.request("llm/listModels", {
|
||||
title: ONBOARDING_LOCAL_MODEL_TITLE,
|
||||
})) as any;
|
||||
|
||||
function onConnectionVerified() {
|
||||
setIsOllamaConnected(true);
|
||||
}
|
||||
if (result.status === "success" && Array.isArray(result.content)) {
|
||||
setDownloadedOllamaModels(result.content);
|
||||
setIsOllamaConnected(true);
|
||||
} else {
|
||||
throw new Error("Failed to fetch models");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching models:", error);
|
||||
setIsOllamaConnected(false);
|
||||
}
|
||||
};
|
||||
|
||||
const intervalId = setInterval(
|
||||
fetchDownloadedModels,
|
||||
OLLAMA_CHECK_INTERVAL_MS,
|
||||
);
|
||||
|
||||
fetchDownloadedModels();
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex flex-col">
|
||||
<p className="text-lg font-bold leading-tight mb-2">Install Ollama</p>
|
||||
<OllamaStatus onConnectionVerified={onConnectionVerified} />
|
||||
<OllamaStatus isOllamaConnected={isOllamaConnected} />
|
||||
</div>
|
||||
|
||||
<OllamaModelDownload
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ export const defaultOnboardingCardState: OnboardingCardState = {
|
|||
export enum OllamaConnectionStatuses {
|
||||
WaitingToDownload = "WaitingToDownload",
|
||||
Downloading = "Downloading",
|
||||
Verified = "Verified",
|
||||
Connected = "Connected",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,6 +389,10 @@ export const StyledActionButton = styled.div`
|
|||
padding: 2px 12px;
|
||||
background-color: ${lightGray}33;
|
||||
background-opacity: 0.1;
|
||||
|
||||
&:hover {
|
||||
background-color: ${lightGray}55;
|
||||
}
|
||||
`;
|
||||
|
||||
export const CloseButton = styled.button`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue