Skip to content

Commit 754e016

Browse files
feat: Optimize the Ollama configuration workflow (#12063)
1 parent f67ce75 commit 754e016

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

agent/app/service/agents.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,7 @@ func writeOpenclawConfig(confDir, provider, modelName, apiType string, maxTokens
17551755
} else if provider == "ollama" {
17561756
cfg.Agents.Defaults.Model.Primary = modelName
17571757
useAPIType, _, _ := resolveRuntimeParams(provider, apiType, maxTokens, contextWindow)
1758+
reasoning := useAPIType != "openai-completions"
17581759
cfg.Models = &modelsConfig{
17591760
Mode: "merge",
17601761
Providers: map[string]modelProvider{
@@ -1766,7 +1767,7 @@ func writeOpenclawConfig(confDir, provider, modelName, apiType string, maxTokens
17661767
{
17671768
ID: modelID,
17681769
Name: modelID,
1769-
Reasoning: true,
1770+
Reasoning: reasoning,
17701771
Input: []string{"text"},
17711772
ContextWindow: 160000,
17721773
MaxTokens: 8192,

frontend/src/views/ai/agents/agent/config/tabs/model.vue

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
</el-checkbox>
1212
</el-form-item>
1313
<el-form-item :label="t('aiTools.model.model')" prop="model">
14-
<el-input v-if="form.manualModel" v-model="form.model" />
14+
<el-input v-if="form.manualModel && isOllamaProvider" v-model="ollamaModelSuffix">
15+
<template #prepend>ollama/</template>
16+
</el-input>
17+
<el-input v-else-if="form.manualModel" v-model="form.model" />
1518
<el-select v-else v-model="form.model" filterable>
1619
<el-option v-for="item in modelOptions" :key="item.id" :label="item.name" :value="item.id" />
1720
</el-select>
@@ -25,7 +28,7 @@
2528
</template>
2629

2730
<script setup lang="ts">
28-
import { reactive, ref } from 'vue';
31+
import { computed, reactive, ref } from 'vue';
2932
import type { FormInstance } from 'element-plus';
3033
import { useI18n } from 'vue-i18n';
3134
import { AI } from '@/api/interface/ai';
@@ -52,6 +55,21 @@ const form = reactive({
5255
model: '',
5356
});
5457
58+
const isOllamaProvider = computed(() => provdier.value === 'ollama');
59+
60+
const ollamaModelSuffix = computed({
61+
get: () => {
62+
const model = form.model || '';
63+
if (model.startsWith('ollama/')) {
64+
return model.slice('ollama/'.length);
65+
}
66+
return model;
67+
},
68+
set: (value: string) => {
69+
form.model = `ollama/${value || ''}`;
70+
},
71+
});
72+
5573
const rules = reactive({
5674
accountId: [Rules.requiredSelect],
5775
model: [Rules.requiredInput],
@@ -97,6 +115,14 @@ const handleAccountChange = () => {
97115
modelOptions.value = [];
98116
return;
99117
}
118+
if (selected.provider === 'ollama') {
119+
form.manualModel = true;
120+
if (!form.model.startsWith('ollama/')) {
121+
form.model = 'ollama/';
122+
}
123+
setModelsByProvider(selected.provider);
124+
return;
125+
}
100126
setModelsByProvider(selected.provider);
101127
if (!form.manualModel && (!form.model || !form.model.startsWith(`${selected.provider}/`))) {
102128
form.model = modelOptions.value.length > 0 ? modelOptions.value[0].id : '';
@@ -109,6 +135,9 @@ const handleManualModelChange = (val: unknown) => {
109135
form.manualModel = true;
110136
return;
111137
}
138+
if (selected?.provider === 'ollama' && Boolean(val) && !form.model.startsWith('ollama/')) {
139+
form.model = 'ollama/';
140+
}
112141
if (Boolean(val)) {
113142
return;
114143
}
@@ -136,9 +165,11 @@ const load = async (agent: AI.AgentItem) => {
136165
const currentAccount =
137166
accountOptions.value.find((item) => item.id === agent.accountId) || accountOptions.value[0];
138167
form.accountId = currentAccount.id;
168+
provdier.value = currentAccount.provider;
139169
setModelsByProvider(currentAccount.provider);
140170
const inProviderModels = modelOptions.value.some((item) => item.id === agent.model);
141-
form.manualModel = currentAccount.provider === 'custom' || !inProviderModels;
171+
form.manualModel =
172+
currentAccount.provider === 'custom' || currentAccount.provider === 'ollama' || !inProviderModels;
142173
if (agent.model && (form.manualModel || agent.model.startsWith(`${currentAccount.provider}/`))) {
143174
form.model = agent.model;
144175
} else {
@@ -147,6 +178,9 @@ const load = async (agent: AI.AgentItem) => {
147178
if (currentAccount.provider === 'custom' && currentAccount.model && !form.model) {
148179
form.model = currentAccount.model;
149180
}
181+
if (currentAccount.provider === 'ollama' && !form.model.startsWith('ollama/')) {
182+
form.model = 'ollama/';
183+
}
150184
} finally {
151185
loading.value = false;
152186
}

0 commit comments

Comments
 (0)