| 1 | import { CommandLineIcon } from "@heroicons/react/24/outline"; |
| 2 | import { useContext } from "react"; |
| 3 | import { StyledActionButton } from "../.."; |
| 4 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | import { ToolTip } from "../../gui/Tooltip"; |
| 6 | import OllamaCompletedStep from "./OllamaCompletedStep"; |
| 7 | |
| 8 | interface OllamaModelDownloadProps { |
| 9 | title: string; |
| 10 | modelName: string; |
| 11 | hasDownloaded: boolean; |
| 12 | } |
| 13 | |
| 14 | function OllamaModelDownload({ |
| 15 | title, |
| 16 | modelName, |
| 17 | hasDownloaded, |
| 18 | }: OllamaModelDownloadProps) { |
| 19 | const ideMessenger = useContext(IdeMessengerContext); |
| 20 | const command = `ollama pull ${modelName}`; |
| 21 | |
| 22 | function onClick() { |
| 23 | void ideMessenger.ide.runCommand(command); |
| 24 | ideMessenger.post("copyText", { text: command }); |
| 25 | } |
| 26 | |
| 27 | return ( |
| 28 | <div className="flex flex-col"> |
| 29 | <p className="mb-0 mt-4 text-base font-semibold">{title}</p> |
| 30 | {hasDownloaded ? ( |
| 31 | <OllamaCompletedStep text={command} /> |
| 32 | ) : ( |
| 33 | <ToolTip place="top" content="Copy into terminal"> |
| 34 | <StyledActionButton onClick={onClick} className="gap-2"> |
| 35 | <p className="lines m-0 px-0 py-2 font-mono text-xs">{command}</p> |
| 36 | <CommandLineIcon width={16} height={16} /> |
| 37 | </StyledActionButton> |
| 38 | </ToolTip> |
| 39 | )} |
| 40 | </div> |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | export default OllamaModelDownload; |