Files
myprojplanet_vite/src/components/CAITools/CAITools.ts

199 lines
5.5 KiB
TypeScript
Raw Normal View History

2024-01-30 14:00:48 +01:00
import { defineComponent, ref, onMounted, computed } from 'vue'
import { useI18n } from '@src/boot/i18n'
import { tools } from '../../store/Modules/tools'
import { shared_consts } from '@/common/shared_vuejs'
import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore'
import { useQuasar } from 'quasar'
import { costanti } from '@costanti'
import { useRouter } from 'vue-router'
2025-02-06 19:00:19 +01:00
import { serv_constants } from '@store/Modules/serv_constants'
2024-01-30 14:00:48 +01:00
export default defineComponent({
name: 'CAITools',
props: {
},
components: {
},
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const userStore = useUserStore()
const globalStore = useGlobalStore()
const isfinishLoading = computed(() => globalStore.finishLoading)
const $router = useRouter()
2025-02-06 19:00:19 +01:00
const options = ref(<any>{})
2024-01-30 14:00:48 +01:00
const querySel = ref('')
2025-02-06 19:00:19 +01:00
const contestSysteList = [
{ label: 'Standard', value: '' },
{ label: 'Matematica', value: 'Sei un esperto in Matematica' },
{ label: 'Editoriale', value: 'Sei un esperto in Editoria e scrittura di articoli e blog' },
{ label: 'Programmazione', value: 'Sei un esperto in programmazione' },
]
const modelList = [
{ label: 'DeepSeek', value: 'deepseek-chat' },
]
const outputTypeList = [
{ label: 'Formato Testo', value: 'Ritornami l\'output in formato testo' },
{ label: 'Per Telegram', value: 'Ritornami l\'output formattato per incollarlo sulla chat Telegram, usando delle emoticons in punti chiave e il grassetto (**) nelle parole chiave.' },
{ label: 'Formato JSON', value: 'Ritornami l\'output in formato JSON' },
{ label: 'Formato CSV (campi separati da \'|\')', value: 'Ritornami l\'output in formato CSV, con i campi separati da \'|\'' },
]
const tempList = [{ label: 'Temperatura a 0.3', value: 0.3 },
{ label: 'Temperatura a 0.5', value: 0.5 },
{ label: 'Temperatura a 1', value: 1 },
{ label: 'Temperatura a 1.2', value: 1.2 },
{ label: 'Temperatura a 1.5', value: 1.5 },
]
const tokenList = [
{ label: '50 Token', value: 50 },
{ label: '100 Token', value: 100 },
{ label: '200 Token', value: 200 },
{ label: '500 Token', value: 500 },
{ label: '1000 Token', value: 1000 },
{ label: '2500 Token', value: 2500 },
{ label: '4000 Token', value: 4000 },
{ label: '5000 Token', value: 5000 },
{ label: '10000 Token', value: 10000 },
]
const model = ref('deepseek-chat')
const max_tokens = ref(100)
const outputType = ref('')
const temp = ref(0.3)
const stream = ref(false)
const contestsystem = ref('')
const inputPrompt = ref('');
const result = ref('');
const isLoading = ref(false);
const errorMessage = ref('');
const finish_reason = ref('');
const withexplain = ref(false);
const querylist = ref(<any[]>[])
const modelLabel = computed(() => {
const foundModel = modelList.find((item: any) => item.value === model.value);
return foundModel ? foundModel.label : null;
})
2024-01-30 14:00:48 +01:00
function mount() {
// Mount
2025-02-06 19:00:19 +01:00
querylist.value = globalStore.getQueryAI()
outputType.value = outputTypeList[0].value
2024-01-30 14:00:48 +01:00
}
2025-02-06 19:00:19 +01:00
async function handleSubmit() {
isLoading.value = true;
errorMessage.value = '';
result.value = '';
options.value = {
model: model.value,
max_tokens: max_tokens.value,
temp: temp.value,
stream: stream.value,
withexplain: withexplain.value,
}
try {
const resdata = await globalStore.getQueryDS(inputPrompt.value, options.value)
if (resdata.code === serv_constants.RIS_CODE_OK) {
if (resdata.choice) {
finish_reason.value = resdata.choice.finish_reason || ''
}
if (resdata.choice.message) {
result.value = resdata.choice.message.content || ''
}
} else if (resdata.code === serv_constants.RIS_CODE_ERR) {
errorMessage.value = resdata.error.message || resdata.error;
$q.notify({
color: 'negative',
icon: 'error',
message: 'Errore durante la richiesta',
caption: errorMessage.value
});
}
} catch (error: any) {
errorMessage.value = error.response?.data?.error || error.message;
$q.notify({
color: 'negative',
icon: 'error',
message: 'Errore durante la richiesta',
caption: errorMessage.value
});
}
isLoading.value = false;
}
const copyToClipboard = () => {
if (!result.value) return;
navigator.clipboard.writeText(result.value).then(() => {
$q.notify({
message: 'Copiato negli appunti!',
color: 'positive',
icon: 'check',
});
}).catch(err => {
console.error('Errore nella copia:', err);
$q.notify({
message: 'Errore nella copia!',
color: 'negative',
icon: 'error',
});
});
};
2024-01-30 14:00:48 +01:00
onMounted(mount)
return {
t,
querySel,
$q,
globalStore,
2025-02-06 19:00:19 +01:00
inputPrompt,
result,
isLoading,
errorMessage,
handleSubmit,
querylist,
copyToClipboard,
max_tokens,
tokenList,
modelList,
tempList,
stream,
model,
contestSysteList,
contestsystem,
finish_reason,
modelLabel,
withexplain,
outputType,
outputTypeList,
2024-01-30 14:00:48 +01:00
}
}
})