Skip to content

Commit

Permalink
Merge pull request trypear#140 from Madhav160804/ollama-model-selection
Browse files Browse the repository at this point in the history
Added Ollama Model Check for installed models
  • Loading branch information
andrewpareles authored Nov 4, 2024
2 parents fe413cb + 1c739e5 commit 791f6b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
45 changes: 31 additions & 14 deletions extensions/void/src/common/sendLLMMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,39 +237,56 @@ export const sendOllamaMsg: SendLLMMessageFnTypeInternal = ({ messages, onText,
let didAbort = false
let fullText = ""

// if abort is called, onFinalMessage is NOT called, and no later onTexts are called either
abortRef.current = () => {
didAbort = true;
};

const ollama = new Ollama({ host: voidConfig.ollama.endpoint })

ollama.chat({
model: voidConfig.ollama.model,
messages: messages,
stream: true,
options: { num_predict: parseMaxTokensStr(voidConfig.default.maxTokens) } // this is max_tokens
})
// First check if model exists
ollama.list()
.then(async models => {
const installedModels = models.models.map(m => m.name.replace(/:latest$/, ''))
const modelExists = installedModels.some(m => m.startsWith(voidConfig.ollama.model));
if (!modelExists) {
const errorMessage = `The model "${voidConfig.ollama.model}" is not available locally. Please run 'ollama pull ${voidConfig.ollama.model}' to download it first or
try selecting one from the Installed models: ${installedModels.join(', ')}`;
onText(errorMessage, errorMessage);
onFinalMessage(errorMessage);
return Promise.reject();
}

return ollama.chat({
model: voidConfig.ollama.model,
messages: messages,
stream: true,
options: { num_predict: parseMaxTokensStr(voidConfig.default.maxTokens) }
});
})
.then(async stream => {
if (!stream) return;

abortRef.current = () => {
// stream.abort()
didAbort = true
}
// iterate through the stream
for await (const chunk of stream) {
if (didAbort) return;
const newText = chunk.message.content;
fullText += newText;
onText(newText, fullText);
}
onFinalMessage(fullText);

})
// when error/fail
.catch(error => {
onError(error)
})

// Check if the error is a connection error
if (error instanceof Error && error.message.includes('Failed to fetch')) {
const errorMessage = 'Ollama service is not running. Please start the Ollama service and try again.';
onText(errorMessage, errorMessage);
onFinalMessage(errorMessage);
} else if (error) {
onError(error);
}
});
};

// Greptile
Expand Down
10 changes: 5 additions & 5 deletions extensions/void/src/webviews/common/contextForConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ const voidConfigInfo: Record<
'http://127.0.0.1:11434'
),
// TODO we should allow user to select model inside Void, but for now we'll just let them handle the Ollama setup on their own
// model: configEnum(
// 'Ollama model to use.',
// 'llama3.1',
// ["codegemma", "codegemma:2b", "codegemma:7b", "codellama", "codellama:7b", "codellama:13b", "codellama:34b", "codellama:70b", "codellama:code", "codellama:python", "command-r", "command-r:35b", "command-r-plus", "command-r-plus:104b", "deepseek-coder-v2", "deepseek-coder-v2:16b", "deepseek-coder-v2:236b", "falcon2", "falcon2:11b", "firefunction-v2", "firefunction-v2:70b", "gemma", "gemma:2b", "gemma:7b", "gemma2", "gemma2:2b", "gemma2:9b", "gemma2:27b", "llama2", "llama2:7b", "llama2:13b", "llama2:70b", "llama3", "llama3:8b", "llama3:70b", "llama3-chatqa", "llama3-chatqa:8b", "llama3-chatqa:70b", "llama3-gradient", "llama3-gradient:8b", "llama3-gradient:70b", "llama3.1", "llama3.1:8b", "llama3.1:70b", "llama3.1:405b", "llava", "llava:7b", "llava:13b", "llava:34b", "llava-llama3", "llava-llama3:8b", "llava-phi3", "llava-phi3:3.8b", "mistral", "mistral:7b", "mistral-large", "mistral-large:123b", "mistral-nemo", "mistral-nemo:12b", "mixtral", "mixtral:8x7b", "mixtral:8x22b", "moondream", "moondream:1.8b", "openhermes", "openhermes:v2.5", "phi3", "phi3:3.8b", "phi3:14b", "phi3.5", "phi3.5:3.8b", "qwen", "qwen:7b", "qwen:14b", "qwen:32b", "qwen:72b", "qwen:110b", "qwen2", "qwen2:0.5b", "qwen2:1.5b", "qwen2:7b", "qwen2:72b", "smollm", "smollm:135m", "smollm:360m", "smollm:1.7b"] as const
// ),
model: configEnum(
'Ollama model to use.',
'llama3.1',
["codegemma", "codegemma:2b", "codegemma:7b", "codellama", "codellama:7b", "codellama:13b", "codellama:34b", "codellama:70b", "codellama:code", "codellama:python", "command-r", "command-r:35b", "command-r-plus", "command-r-plus:104b", "deepseek-coder-v2", "deepseek-coder-v2:16b", "deepseek-coder-v2:236b", "falcon2", "falcon2:11b", "firefunction-v2", "firefunction-v2:70b", "gemma", "gemma:2b", "gemma:7b", "gemma2", "gemma2:2b", "gemma2:9b", "gemma2:27b", "llama2", "llama2:7b", "llama2:13b", "llama2:70b", "llama3", "llama3:8b", "llama3:70b", "llama3-chatqa", "llama3-chatqa:8b", "llama3-chatqa:70b", "llama3-gradient", "llama3-gradient:8b", "llama3-gradient:70b", "llama3.1", "llama3.2", "llama3.1:8b", "llama3.1:70b", "llama3.1:405b", "llava", "llava:7b", "llava:13b", "llava:34b", "llava-llama3", "llava-llama3:8b", "llava-phi3", "llava-phi3:3.8b", "mistral", "mistral:7b", "mistral-large", "mistral-large:123b", "mistral-nemo", "mistral-nemo:12b", "mixtral", "mixtral:8x7b", "mixtral:8x22b", "moondream", "moondream:1.8b", "openhermes", "openhermes:v2.5", "phi3", "phi3:3.8b", "phi3:14b", "phi3.5", "phi3.5:3.8b", "qwen", "qwen:7b", "qwen:14b", "qwen:32b", "qwen:72b", "qwen:110b", "qwen2", "qwen2:0.5b", "qwen2:1.5b", "qwen2:7b", "qwen2:72b", "smollm", "smollm:135m", "smollm:360m", "smollm:1.7b"] as const
),
},
openRouter: {
model: configString(
Expand Down

0 comments on commit 791f6b1

Please sign in to comment.