完成通用选择模型,修复多选问题
This commit is contained in:
parent
dbb64d6fb3
commit
52b4969610
|
|
@ -46,4 +46,16 @@ export const DelFunctionService = (Data) => {
|
||||||
'token': Data.token, //token
|
'token': Data.token, //token
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FindModelListByFunctionName= (Data) => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
for (let key in Data) {
|
||||||
|
params.append(key, Data[key])
|
||||||
|
}
|
||||||
|
return request.post('/func/find_models_by_function', params,{
|
||||||
|
headers: {
|
||||||
|
'token': Data.token, //token
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { FormOption } from '@/types/form-option';
|
import { FormOption } from '@/types/form-option';
|
||||||
import { json } from 'd3';
|
|
||||||
import { FormInstance, FormRules, UploadProps } from 'element-plus';
|
import { FormInstance, FormRules, UploadProps } from 'element-plus';
|
||||||
import { PropType, ref } from 'vue';
|
import { PropType, ref } from 'vue';
|
||||||
|
|
||||||
|
|
@ -63,30 +62,30 @@ const { options, formData, edit, update } = defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//const form = ref({ ...(edit ? formData : {}) });
|
const form = ref({ ...(edit ? formData : {}) });
|
||||||
const form = ref();
|
// const form = ref();
|
||||||
|
|
||||||
const doFormData = () => {
|
// const doFormData = () => {
|
||||||
let a={}
|
// form.value ={};
|
||||||
let initialForm = { ...(edit ? formData : {}) };
|
// let initialForm = { ...(edit ? formData : {}) };
|
||||||
|
// //console.log("edit:",formData);
|
||||||
options.list.forEach(item => {
|
// options.list.forEach(item => {
|
||||||
if (item.type === 'select' && item.multiple) {
|
// if (item.type === 'select' && item.multiple) {
|
||||||
let ids = formData[item.prop];
|
// let ids = formData[item.prop];
|
||||||
let id_list = JSON.parse(ids);
|
// let id_list = JSON.parse(ids);
|
||||||
console.log(id_list);
|
// console.log(id_list);
|
||||||
let selectedValues = [];
|
// let selectedValues = [];
|
||||||
for (let i = 0; i < id_list.length; i++) {
|
// for (let i = 0; i < id_list.length; i++) {
|
||||||
selectedValues.push(id_list[i]["id"]);
|
// selectedValues.push(id_list[i]["id"]);
|
||||||
}
|
// }
|
||||||
if (!Array.isArray(initialForm[item.prop])) {
|
// if (!Array.isArray(initialForm[item.prop])) {
|
||||||
initialForm[item.prop] = selectedValues;
|
// initialForm[item.prop] = selectedValues;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
return initialForm;
|
// return initialForm;
|
||||||
};
|
// };
|
||||||
form.value=doFormData();
|
// form.value=doFormData();
|
||||||
|
|
||||||
const rules: FormRules = options.list.map(item => {
|
const rules: FormRules = options.list.map(item => {
|
||||||
if (item.required) {
|
if (item.required) {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,6 @@ export interface Function{
|
||||||
Info: string;
|
Info: string;
|
||||||
UserID: number;
|
UserID: number;
|
||||||
ModelID: number | Object | Array<any>;
|
ModelID: number | Object | Array<any>;
|
||||||
ModelIDs: string;
|
ModelIDS: string| Object | Array<any>;
|
||||||
Function: string;
|
Function: string;
|
||||||
}
|
}
|
||||||
|
|
@ -18,4 +18,18 @@ export interface ModelParameter{
|
||||||
APPID: string;
|
APPID: string;
|
||||||
APIKey: string;
|
APIKey: string;
|
||||||
APISecret: string;
|
APISecret: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ModelContent{
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string;
|
||||||
|
UpdatedAt: string;
|
||||||
|
DeletedAt: string;
|
||||||
|
Name: string;
|
||||||
|
Url: string;
|
||||||
|
UserID: number;
|
||||||
|
Type: string;
|
||||||
|
Parameter: string;
|
||||||
|
Description: string;
|
||||||
|
token: number; //消耗大模型的token
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +100,16 @@
|
||||||
>发送</el-button
|
>发送</el-button
|
||||||
>
|
>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
<el-col :span="3" style="text-align: center">
|
||||||
|
<el-select v-model="selectModel" placeholder="选择模型">
|
||||||
|
<el-option
|
||||||
|
v-for="item in ModelList"
|
||||||
|
:key="item.ID"
|
||||||
|
:label="item.Type +':' + item.Description"
|
||||||
|
:value="item.ID"
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -109,7 +119,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted, reactive, nextTick } from "vue";
|
import { ref, onMounted, onUnmounted, reactive, nextTick } from "vue";
|
||||||
import { ElCard, ElInput, ElButton } from "element-plus";
|
import { ElCard, ElInput, ElButton } from "element-plus";
|
||||||
import { WSMessage, AIQMessage, OllamaMessage } from "@/types/im";
|
import { WSMessage} from "@/types/im";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { GetMessageService } from "@/api/im";
|
import { GetMessageService } from "@/api/im";
|
||||||
import { Check, Loading, DocumentCopy } from "@element-plus/icons-vue";
|
import { Check, Loading, DocumentCopy } from "@element-plus/icons-vue";
|
||||||
|
|
@ -117,10 +127,12 @@ import MarkdownIt from "markdown-it";
|
||||||
import hljs from "highlight.js";
|
import hljs from "highlight.js";
|
||||||
import { Session } from "@/types/session";
|
import { Session } from "@/types/session";
|
||||||
import { FindSessionService } from "@/api/session";
|
import { FindSessionService } from "@/api/session";
|
||||||
|
import { FindModelListByFunctionName } from "@/api/function";
|
||||||
import markdownItHighlightjs from "markdown-it-highlightjs";
|
import markdownItHighlightjs from "markdown-it-highlightjs";
|
||||||
import markdownItKatex from "markdown-it-katex";
|
import markdownItKatex from "markdown-it-katex";
|
||||||
import mermaidPlugin from "@agoose77/markdown-it-mermaid";
|
import mermaidPlugin from "@agoose77/markdown-it-mermaid";
|
||||||
import "katex/dist/katex.min.css";
|
import "katex/dist/katex.min.css";
|
||||||
|
import { Model } from "@/types/model";
|
||||||
interface Message {
|
interface Message {
|
||||||
role: "user" | "assistant";
|
role: "user" | "assistant";
|
||||||
content: string;
|
content: string;
|
||||||
|
|
@ -149,6 +161,8 @@ const sessionID = ref(0);
|
||||||
const messagesContainer = ref<HTMLDivElement | null>(null);
|
const messagesContainer = ref<HTMLDivElement | null>(null);
|
||||||
const sessionIsShow = ref(false);
|
const sessionIsShow = ref(false);
|
||||||
const sessionName = ref("");
|
const sessionName = ref("");
|
||||||
|
const ModelList = ref<Model[]>([]);
|
||||||
|
const selectModel = ref(0);
|
||||||
|
|
||||||
const renderMarkdown = (content: string) => {
|
const renderMarkdown = (content: string) => {
|
||||||
return md.render(content);
|
return md.render(content);
|
||||||
|
|
@ -288,6 +302,7 @@ const sendMessage = () => {
|
||||||
type: "ollama",
|
type: "ollama",
|
||||||
function: "gen-ai-chat",
|
function: "gen-ai-chat",
|
||||||
session_id: sessionID.value,
|
session_id: sessionID.value,
|
||||||
|
model_id: selectModel.value,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
socket.value.send(JSON.stringify(msg));
|
socket.value.send(JSON.stringify(msg));
|
||||||
|
|
@ -388,6 +403,27 @@ const copyMessage = (content: string) => {
|
||||||
ElMessage.error("复制失败: " + error);
|
ElMessage.error("复制失败: " + error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const GetModelListByFunctionName = async () => {
|
||||||
|
let req = {
|
||||||
|
function: "gen-ai-chat",
|
||||||
|
token: localStorage.getItem("token"),
|
||||||
|
};
|
||||||
|
try{
|
||||||
|
let result = await FindModelListByFunctionName(req);
|
||||||
|
if (result["code"] === 0) {
|
||||||
|
ModelList.value = result["data"];
|
||||||
|
selectModel.value = ModelList.value[0].ID;
|
||||||
|
console.log("model_list:", ModelList.value);
|
||||||
|
} else {
|
||||||
|
ElMessage.error(result["msg"]);
|
||||||
|
}
|
||||||
|
}catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GetModelListByFunctionName();
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.chat-app {
|
.chat-app {
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ const getData = async () => {
|
||||||
type: "UserID"
|
type: "UserID"
|
||||||
}
|
}
|
||||||
let modelResult = await FindModelService(req);
|
let modelResult = await FindModelService(req);
|
||||||
|
model_select_opts.value.length = 0; // 清空数组
|
||||||
for (let i = 0; i < modelResult.data.length; i++) {
|
for (let i = 0; i < modelResult.data.length; i++) {
|
||||||
model_select_opts.value.push({
|
model_select_opts.value.push({
|
||||||
label: modelResult.data[i].Type + ":" + modelResult.data[i].Description,
|
label: modelResult.data[i].Type + ":" + modelResult.data[i].Description,
|
||||||
|
|
@ -112,7 +113,7 @@ let options = ref<FormOption>({
|
||||||
span: 12,
|
span: 12,
|
||||||
list: [
|
list: [
|
||||||
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
||||||
{ type: 'select', label: '模型', prop: 'ModelID', required: true, opts:model_select_opts.value },
|
{ type: 'select', label: '模型', prop: 'ModelIDS', required: true, opts:model_select_opts.value ,multiple: true},
|
||||||
{ type: 'input', label: '功能', prop: 'Function', required: true },
|
{ type: 'input', label: '功能', prop: 'Function', required: true },
|
||||||
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
||||||
]
|
]
|
||||||
|
|
@ -138,13 +139,20 @@ const rowData = ref({});
|
||||||
const handleEdit = async (row: Function) => {
|
const handleEdit = async (row: Function) => {
|
||||||
let data = row;
|
let data = row;
|
||||||
rowData.value = data;
|
rowData.value = data;
|
||||||
|
let model_ids = JSON.parse(data.ModelIDS.toString())
|
||||||
|
let model_id_list = []
|
||||||
|
for (let i = 0; i < model_ids.length; i++) {
|
||||||
|
model_id_list.push(model_ids[i]["id"])
|
||||||
|
}
|
||||||
|
rowData.value.ModelIDS = model_id_list
|
||||||
//console.log("edit_row_data:", rowData.value);
|
//console.log("edit_row_data:", rowData.value);
|
||||||
isEdit.value = true;
|
isEdit.value = true;
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
};
|
};
|
||||||
const updateData = async (data) => {
|
const updateData = async (data) => {
|
||||||
let model_id =[]
|
let model_id =[]
|
||||||
let model_id_list= data["ModelID"]
|
console.log("model update:",data)
|
||||||
|
let model_id_list= data["ModelIDS"]
|
||||||
for (let i = 0; i < model_id_list.length; i++) {
|
for (let i = 0; i < model_id_list.length; i++) {
|
||||||
model_id.push({"id":model_id_list[i]})
|
model_id.push({"id":model_id_list[i]})
|
||||||
}
|
}
|
||||||
|
|
@ -175,12 +183,20 @@ const updateData = async (data) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const addData = async (data) => {
|
const addData = async (data) => {
|
||||||
|
let model_id =[]
|
||||||
|
console.log("model update:",data)
|
||||||
|
let model_id_list= data["ModelIDS"]
|
||||||
|
for (let i = 0; i < model_id_list.length; i++) {
|
||||||
|
model_id.push({"id":model_id_list[i]})
|
||||||
|
}
|
||||||
|
let model_ids = JSON.stringify(model_id)
|
||||||
let result ={}
|
let result ={}
|
||||||
try{
|
try{
|
||||||
let req={
|
let req={
|
||||||
token:localStorage.getItem("token"),
|
token:localStorage.getItem("token"),
|
||||||
name: data.Name,
|
name: data.Name,
|
||||||
model_id: data.ModelID,
|
model_id: model_id_list[0],
|
||||||
|
model_ids: model_ids,
|
||||||
function: data.Function,
|
function: data.Function,
|
||||||
info: data.Info
|
info: data.Info
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue