mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
ai设置支持添加utools内置的ai
This commit is contained in:
parent
3d2d15e177
commit
a762b87d2b
@ -6,10 +6,7 @@
|
|||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
v-model="apiToAdd"
|
v-model="apiToAdd"
|
||||||
class="col"
|
class="col"
|
||||||
:options="[
|
:options="aiOptions"
|
||||||
{ label: 'OPENAI', value: 'openai' },
|
|
||||||
{ label: 'OLLAMA', value: 'ollama' },
|
|
||||||
]"
|
|
||||||
height="26px"
|
height="26px"
|
||||||
/>
|
/>
|
||||||
<q-icon
|
<q-icon
|
||||||
@ -78,8 +75,11 @@
|
|||||||
:placeholder="
|
:placeholder="
|
||||||
aiConfig.apiType === 'openai'
|
aiConfig.apiType === 'openai'
|
||||||
? '例:https://api.openai.com'
|
? '例:https://api.openai.com'
|
||||||
: '例:http://localhost:11434'
|
: aiConfig.apiType === 'ollama'
|
||||||
|
? '例:http://localhost:11434'
|
||||||
|
: '无需配置'
|
||||||
"
|
"
|
||||||
|
:disable="aiConfig.apiType === 'utools'"
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-badge
|
<q-badge
|
||||||
@ -179,7 +179,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent, ref } from "vue";
|
||||||
import { dbManager } from "js/utools.js";
|
import { dbManager } from "js/utools.js";
|
||||||
import ButtonGroup from "components/composer/common/ButtonGroup.vue";
|
import ButtonGroup from "components/composer/common/ButtonGroup.vue";
|
||||||
import draggable from "vuedraggable";
|
import draggable from "vuedraggable";
|
||||||
@ -191,6 +191,18 @@ export default defineComponent({
|
|||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
draggable,
|
draggable,
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
const aiOptions = ref([
|
||||||
|
{ label: "OPENAI接口", value: "openai" },
|
||||||
|
{ label: "OLLAMA接口", value: "ollama" },
|
||||||
|
]);
|
||||||
|
if (utools.allAiModels) {
|
||||||
|
aiOptions.value.push({ label: "uTools内置", value: "utools" });
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
aiOptions,
|
||||||
|
};
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
apiToAdd: "openai",
|
apiToAdd: "openai",
|
||||||
@ -202,6 +214,19 @@ export default defineComponent({
|
|||||||
emits: ["save"],
|
emits: ["save"],
|
||||||
methods: {
|
methods: {
|
||||||
async getModels(aiConfig) {
|
async getModels(aiConfig) {
|
||||||
|
if (aiConfig.apiType === "utools") {
|
||||||
|
try {
|
||||||
|
const models = await utools.allAiModels();
|
||||||
|
this.models = models.map((model) => model.id);
|
||||||
|
} catch (error) {
|
||||||
|
quickcommand.showMessageBox(
|
||||||
|
"获取 uTools AI 模型失败: " + error.message,
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
this.models = [];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { success, result, error } = await window.getModelsFromAiApi(
|
const { success, result, error } = await window.getModelsFromAiApi(
|
||||||
aiConfig
|
aiConfig
|
||||||
);
|
);
|
||||||
@ -223,13 +248,21 @@ export default defineComponent({
|
|||||||
this.aiConfigs.splice(index, 1);
|
this.aiConfigs.splice(index, 1);
|
||||||
},
|
},
|
||||||
addModel() {
|
addModel() {
|
||||||
this.aiConfigs.push({
|
const defaultConfig = {
|
||||||
id: getUniqueId(),
|
id: getUniqueId(),
|
||||||
apiType: this.apiToAdd,
|
apiType: this.apiToAdd,
|
||||||
apiUrl: "",
|
apiUrl: "",
|
||||||
apiToken: "",
|
apiToken: "",
|
||||||
model: "",
|
model: "",
|
||||||
name: "",
|
name: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.apiToAdd === "utools") {
|
||||||
|
defaultConfig.apiUrl = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.aiConfigs.push(defaultConfig);
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getConfigListHeight() {
|
getConfigListHeight() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user