- Iniziato a scrivere la CHATBOT...
This commit is contained in:
BIN
1_module copia.jpg
Normal file
BIN
1_module copia.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 536 KiB |
@@ -162,6 +162,7 @@ export const shared_consts = {
|
||||
CATALOGO: 310,
|
||||
RACCOLTA: 315,
|
||||
TOOLSAI: 320,
|
||||
CHATBOT: 325,
|
||||
MAPPA: 350,
|
||||
MAPPAUTENTI: 360,
|
||||
MAPPACOMUNI: 370,
|
||||
@@ -1976,6 +1977,14 @@ export const shared_consts = {
|
||||
value: 315,
|
||||
label: 'RACCOLTA CATALOGHI',
|
||||
},
|
||||
{
|
||||
value: 320,
|
||||
label: 'TOOLS AI',
|
||||
},
|
||||
{
|
||||
value: 325,
|
||||
label: 'CHATBOT',
|
||||
},
|
||||
{
|
||||
value: 350,
|
||||
label: 'MAPPA',
|
||||
|
||||
@@ -40,6 +40,8 @@ export default defineComponent({
|
||||
]
|
||||
const modelList = [
|
||||
{ label: 'DeepSeek', value: 'deepseek-chat' },
|
||||
{ label: 'Gemma-2B', value: 'gemma:2b' },
|
||||
{ label: 'Gemma3', value: 'gemma3:12b' },
|
||||
]
|
||||
|
||||
const outputTypeList = [
|
||||
|
||||
@@ -103,7 +103,6 @@ export default defineComponent({
|
||||
|
||||
const filter = ref('');
|
||||
|
||||
|
||||
const importSelectedBooks = () => {
|
||||
if (searchResults.value.length === 0) {
|
||||
$q.notify({
|
||||
@@ -116,9 +115,8 @@ export default defineComponent({
|
||||
// Aggiungi i libri selezionati alla lista dell'utente
|
||||
emit(
|
||||
'addArrayTitlesToList',
|
||||
searchResults.value.filter((row) => row.select),
|
||||
searchResults.value.filter((row) => row.select)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
const pagination = reactive({
|
||||
@@ -197,7 +195,6 @@ export default defineComponent({
|
||||
color: 'negative',
|
||||
});
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
error.value = 'Errore nella ricerca dei libri';
|
||||
} finally {
|
||||
@@ -289,9 +286,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function deselectAll() {
|
||||
|
||||
searchResults.value.forEach((row) => (row.select = false));
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -647,7 +647,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function condividi() {
|
||||
const mystr = "❇️ Ecco l'annuncio da condividere !\nPuoi copiarlo oppure inoltrarlo a chi vuoi.\n\nE\' utile pubblicarlo anche nel gruppo Telegram RISO territoriale o in <a href=\'https://t.me/riso_gruppo/1911\'>RISO RIevoluzione SOlidale</a> (Topic \'Annunci RISO\') "
|
||||
const mystr = "❇️ Ecco l'annuncio da condividere !\nPuoi copiarlo oppure inoltrarlo a chi vuoi.\n\nE\' utile pubblicarlo anche nel gruppo Telegram RISO territoriale o in <a href=\'https://riso.app/riso_gruppo\'>☀️💚 RISO - Rete Italiana Scambi Orizzontali</a> (Topic \'Annunci RISO\') "
|
||||
await tools.sendMsgTelegramCmd($q, t, shared_consts.MsgTeleg.SHARE_TEXT, false, mystr)
|
||||
|
||||
tools.copyToClip($q, getlinkpage(), true)
|
||||
|
||||
@@ -12,6 +12,7 @@ import { CImgTitle } from '../CImgTitle/index'
|
||||
import { CImgPoster } from '@src/components/CImgPoster'
|
||||
import { CTitle } from '@src/components/CTitle/index'
|
||||
import { CGridOriz } from '@src/components/CGridOriz/index'
|
||||
import { ChatBot } from '@src/components/ChatBot/index'
|
||||
import { CCatalogList } from '@src/components/CCatalogList/index'
|
||||
import { CRaccoltaCataloghi } from '@src/components/CRaccoltaCataloghi/index'
|
||||
import { tools } from '@tools'
|
||||
@@ -80,6 +81,7 @@ export default defineComponent({
|
||||
CMapComuni, CMapUsers, CMapGetCoordinates, CMapEditAddressByCoord,
|
||||
CDashGroup, CMovements, CGridOriz, CQRCode, CCatalogList,
|
||||
CSearchProduct, CRaccoltaCataloghi, CPageViewStats,
|
||||
ChatBot,
|
||||
// , //CMapMarker,
|
||||
},
|
||||
emits: ['selElemClick'],
|
||||
|
||||
@@ -974,6 +974,15 @@
|
||||
</div>
|
||||
<CAITools></CAITools>
|
||||
</div>
|
||||
<div v-else-if="myel.type === shared_consts.ELEMTYPE.CHATBOT">
|
||||
<div
|
||||
v-if="editOn"
|
||||
class="elemEdit"
|
||||
>
|
||||
CHATBOT:
|
||||
</div>
|
||||
<ChatBot></ChatBot>
|
||||
</div>
|
||||
<div v-else-if="myel.type === shared_consts.ELEMTYPE.NOTIFATTOP">
|
||||
<div
|
||||
v-if="editOn"
|
||||
|
||||
@@ -160,7 +160,6 @@ export default defineComponent({
|
||||
// console.log('load')
|
||||
myloadingload.value = true
|
||||
datastat.value = await globalStore.getStatSite()
|
||||
datastat.value = {}
|
||||
|
||||
eseguipolling.value = true
|
||||
|
||||
|
||||
12
src/components/ChatBot/ChatBot.scss
Executable file
12
src/components/ChatBot/ChatBot.scss
Executable file
@@ -0,0 +1,12 @@
|
||||
.chat-container {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.user {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.bot {
|
||||
text-align: left;
|
||||
}
|
||||
45
src/components/ChatBot/ChatBot.ts
Executable file
45
src/components/ChatBot/ChatBot.ts
Executable file
@@ -0,0 +1,45 @@
|
||||
import type { PropType } from 'vue';
|
||||
import { computed, defineComponent, ref } from 'vue';
|
||||
|
||||
import type { IOperators } from '@model';
|
||||
import { tools } from '@tools';
|
||||
|
||||
|
||||
import axios from 'axios'
|
||||
import { useMessageStore, useUserStore } from 'app/src/store';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ChatBot',
|
||||
props: {},
|
||||
setup(props) {
|
||||
const userMessage = ref<string>('');
|
||||
const messageStore = useMessageStore()
|
||||
const messages = ref<Array<{ sender: string; text: string }>>([]);
|
||||
|
||||
const sendMessage = async () => {
|
||||
if (userMessage.value.trim()) {
|
||||
messages.value.push({ sender: 'user', text: userMessage.value });
|
||||
|
||||
try {
|
||||
const response = await messageStore.chatBot({
|
||||
message: userMessage.value,
|
||||
})
|
||||
const botMessage = response[0]?.text || 'Non ho capito';
|
||||
messages.value.push({ sender: 'bot', text: botMessage });
|
||||
} catch (error) {
|
||||
console.error('Errore nella comunicazione con il backend', error);
|
||||
messages.value.push({ sender: 'bot', text: 'Errore di comunicazione' });
|
||||
}
|
||||
|
||||
userMessage.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
tools,
|
||||
userMessage,
|
||||
messages,
|
||||
sendMessage,
|
||||
};
|
||||
},
|
||||
});
|
||||
18
src/components/ChatBot/ChatBot.vue
Executable file
18
src/components/ChatBot/ChatBot.vue
Executable file
@@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<q-page>
|
||||
<div class="chat-container">
|
||||
<div v-for="(message, index) in messages" :key="index" :class="message.sender">
|
||||
<p>{{ message.text }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<q-input v-model="userMessage" @keyup.enter="sendMessage" label="Scrivi un messaggio" />
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
|
||||
<script lang="ts" src="./ChatBot.ts">
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './ChatBot.scss';
|
||||
</style>
|
||||
1
src/components/ChatBot/index.ts
Executable file
1
src/components/ChatBot/index.ts
Executable file
@@ -0,0 +1 @@
|
||||
export {default as ChatBot} from './ChatBot.vue'
|
||||
@@ -1267,6 +1267,7 @@ const msg_it = {
|
||||
isTemplate: 'E\' un modello',
|
||||
catAI: 'Categorie AI',
|
||||
toolsAI: 'Strumenti AI',
|
||||
CHATBOT: 'Chat BOT',
|
||||
aitools: 'Ricerca',
|
||||
queryAI: 'Query AI',
|
||||
admin_ai: 'Gestione AI',
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { Api } from '@api'
|
||||
import { defineStore } from 'pinia';
|
||||
import { Api } from '@api';
|
||||
|
||||
import { serv_constants } from './Modules/serv_constants'
|
||||
import { serv_constants } from './Modules/serv_constants';
|
||||
|
||||
import type { IMessage, IMessageState, IMsgUsers } from '../model';
|
||||
import { StatusMessage } from '../model'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { MsgDefault } from '@src/model'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { StatusMessage } from '../model';
|
||||
import { tools } from '@src/store/Modules/tools';
|
||||
import { MsgDefault } from '@src/model';
|
||||
import { shared_consts } from '@src/common/shared_vuejs';
|
||||
import { useUserStore } from '@store/UserStore';
|
||||
|
||||
export const useMessageStore = defineStore('MessageStore', {
|
||||
state: (): IMessageState => ({
|
||||
@@ -17,57 +17,57 @@ export const useMessageStore = defineStore('MessageStore', {
|
||||
}),
|
||||
|
||||
getters: {
|
||||
|
||||
getlasts_messages: (mystate: IMessageState) => (): IMessage[] => {
|
||||
const ctrec = (mystate.last_msgs) ? mystate.last_msgs.slice(0, 5) : []
|
||||
const ctrec = mystate.last_msgs ? mystate.last_msgs.slice(0, 5) : [];
|
||||
// const ctrec = (mystate.msgs) ? mystate.msgs.slice().reverse().slice(0, 5) : []
|
||||
return (ctrec)
|
||||
|
||||
return ctrec;
|
||||
},
|
||||
|
||||
getnumMsgUnread: (mystate: IMessageState) => () => {
|
||||
return mystate.last_msgs.filter((msg) => !msg.read).length
|
||||
return mystate.last_msgs.filter((msg) => !msg.read).length;
|
||||
},
|
||||
|
||||
},
|
||||
actions: {
|
||||
|
||||
setMsg(arrmsg: IMessage[], username: string) {
|
||||
// console.log('arrmsg', arrmsg)
|
||||
const userStore = useUserStore()
|
||||
const userStore = useUserStore();
|
||||
|
||||
if (arrmsg.length > 0) {
|
||||
let users_msg: any = this.users_msg.find((rec: IMsgUsers) => rec.username === username)
|
||||
let users_msg: any = this.users_msg.find(
|
||||
(rec: IMsgUsers) => rec.username === username
|
||||
);
|
||||
if (!users_msg) {
|
||||
this.users_msg.push({ username, msgs: [] })
|
||||
users_msg = this.users_msg.find((rec) => rec.username === username)
|
||||
this.users_msg.push({ username, msgs: [] });
|
||||
users_msg = this.users_msg.find((rec) => rec.username === username);
|
||||
}
|
||||
users_msg.msgs.push(...arrmsg)
|
||||
users_msg.msgs.push(...arrmsg);
|
||||
// console.table(users_msg.msgs)
|
||||
|
||||
// users_msg.msgs = tools.getUnique(users_msg.msgs, '_id')
|
||||
// console.table(users_msg.msgs)
|
||||
|
||||
if (users_msg.msgs) {
|
||||
let userother: any = users_msg.msgs.slice(-1)[0].dest
|
||||
let userother: any = users_msg.msgs.slice(-1)[0].dest;
|
||||
if (userother === userStore.my.username)
|
||||
userother = users_msg.msgs.slice(-1)[0].origin
|
||||
userother = users_msg.msgs.slice(-1)[0].origin;
|
||||
|
||||
let index = this.last_msgs.findIndex((rec: IMessage) => (rec.dest === userother) || (rec.origin === userother))
|
||||
let index = this.last_msgs.findIndex(
|
||||
(rec: IMessage) => rec.dest === userother || rec.origin === userother
|
||||
);
|
||||
if (index >= 0) {
|
||||
// Update last message
|
||||
this.last_msgs[index] = users_msg.msgs.slice(-1)[0]
|
||||
this.last_msgs[index] = users_msg.msgs.slice(-1)[0];
|
||||
} else {
|
||||
this.last_msgs.push(users_msg.msgs.slice(-1)[0])
|
||||
index = this.last_msgs.findIndex((rec: IMessage) => (rec.dest === userother) || (rec.origin === userother))
|
||||
this.last_msgs.push(users_msg.msgs.slice(-1)[0]);
|
||||
index = this.last_msgs.findIndex(
|
||||
(rec: IMessage) => rec.dest === userother || rec.origin === userother
|
||||
);
|
||||
}
|
||||
if (this.last_msgs[index])
|
||||
users_msg.lastdataread = this.last_msgs[index].datemsg
|
||||
else
|
||||
users_msg.lastdataread = tools.getLastDateReadReset()
|
||||
|
||||
users_msg.lastdataread = this.last_msgs[index].datemsg;
|
||||
else users_msg.lastdataread = tools.getLastDateReadReset();
|
||||
} else {
|
||||
users_msg.lastdataread = tools.getLastDateReadReset()
|
||||
users_msg.lastdataread = tools.getLastDateReadReset();
|
||||
}
|
||||
|
||||
// console.log('RICeVUTO', arrmsg, 'lastdataread', users_msg.lastdataread)
|
||||
@@ -75,39 +75,55 @@ export const useMessageStore = defineStore('MessageStore', {
|
||||
}
|
||||
},
|
||||
|
||||
async updateMsgDataFromServer({ username, lastdataread }: { username: string, lastdataread: Date }) {
|
||||
async updateMsgDataFromServer({
|
||||
username,
|
||||
lastdataread,
|
||||
}: {
|
||||
username: string;
|
||||
lastdataread: Date;
|
||||
}) {
|
||||
// console.log('updateMsgDataFromServer', username, lastdataread)
|
||||
|
||||
return Api.SendReq(`/sendmsg/${username}/${lastdataread}/${tools.getEnv('VITE_APP_ID')}`, 'GET', null)
|
||||
return Api.SendReq(
|
||||
`/sendmsg/${username}/${lastdataread}/${tools.getEnv('VITE_APP_ID')}`,
|
||||
'GET',
|
||||
null
|
||||
)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
if (res.status === 200) {
|
||||
this.setMsg(res.data.arrmsg, username)
|
||||
return true
|
||||
this.setMsg(res.data.arrmsg, username);
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
return false;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
console.error(error);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
async SendMsgEvent(msg: IMessage) {
|
||||
console.log('SendMsgEvent', msg)
|
||||
console.log('SendMsgEvent', msg);
|
||||
|
||||
const data: IMessage = { ...MsgDefault, ...msg }
|
||||
const data: IMessage = { ...MsgDefault, ...msg };
|
||||
|
||||
const userStore = useUserStore()
|
||||
const userStore = useUserStore();
|
||||
|
||||
data.source!.page = ''
|
||||
data.idapp = tools.getEnv('VITE_APP_ID')
|
||||
data.origin = userStore.my.username
|
||||
data.datemsg = tools.getDateNow()
|
||||
data.status = StatusMessage.WaitingToSend
|
||||
data.source!.page = '';
|
||||
data.idapp = tools.getEnv('VITE_APP_ID');
|
||||
data.origin = userStore.my.username;
|
||||
data.datemsg = tools.getDateNow();
|
||||
data.status = StatusMessage.WaitingToSend;
|
||||
// Options
|
||||
data.typesend = tools.SetBit(data.typesend, shared_consts.MessageOptions.Notify_ByEmail)
|
||||
data.typesend = tools.SetBit(data.typesend, shared_consts.MessageOptions.Notify_ByPushNotification)
|
||||
data.typesend = tools.SetBit(
|
||||
data.typesend,
|
||||
shared_consts.MessageOptions.Notify_ByEmail
|
||||
);
|
||||
data.typesend = tools.SetBit(
|
||||
data.typesend,
|
||||
shared_consts.MessageOptions.Notify_ByPushNotification
|
||||
);
|
||||
|
||||
// console.log('DOPO:')
|
||||
// console.table(data)
|
||||
@@ -117,21 +133,30 @@ export const useMessageStore = defineStore('MessageStore', {
|
||||
// console.log('res', res)
|
||||
if (res.status === 200) {
|
||||
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
||||
data._id = res.data.id
|
||||
data._id = res.data.id;
|
||||
|
||||
const myarr = []
|
||||
myarr.push(data)
|
||||
const myarr = [];
|
||||
myarr.push(data);
|
||||
|
||||
this.setMsg(myarr, data.dest)
|
||||
return true
|
||||
this.setMsg(myarr, data.dest);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
console.error(error);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
async chatBot(payload: any): Promise<any> {
|
||||
const response = await Api.SendReq('/api/chatbot', 'POST', { payload });
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error('Errore nella risposta del server');
|
||||
}
|
||||
|
||||
return response.data; // Supponiamo che il backend ritorni un array di oggetti con id e title
|
||||
},
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user