- AI
- Aggiornamento QUASAR
This commit is contained in:
@@ -13,12 +13,12 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const CatAISchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
@@ -47,7 +47,7 @@ CatAISchema.statics.executeQueryTable = function (idapp, params) {
|
||||
};
|
||||
|
||||
CatAISchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = {};
|
||||
const myfind = { idapp };
|
||||
|
||||
return await CatAI.find(myfind).sort({ name: 1 });
|
||||
};
|
||||
|
||||
@@ -15,6 +15,8 @@ mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const OpenAI = require("openai");
|
||||
|
||||
const QueryAISchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -73,7 +75,7 @@ QueryAISchema.statics.getFieldsForSearch = function () {
|
||||
|
||||
QueryAISchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ const globalTables = require('../tools/globalTables');
|
||||
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
const OpenAI = require("openai");
|
||||
|
||||
router.post('/getlist', authenticate_noerror, async function (req, res, next) {
|
||||
|
||||
@@ -43,4 +44,66 @@ router.post('/getlist', authenticate_noerror, async function (req, res, next) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
async function getDeepSeekResponse(prompt, options) {
|
||||
try {
|
||||
|
||||
const deepseek = new OpenAI({
|
||||
baseURL: 'https://api.deepseek.com/v1', // Verifica il percorso esatto dalle API
|
||||
apiKey: process.env.DS_API_KEY, // Mai hardcodare la chiave!
|
||||
defaultHeaders: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!options.withexplain) {
|
||||
prompt = prompt + '\n' + 'Ritornami solo il risultato, senza spiegazione.'
|
||||
}
|
||||
if (options.outputType) {
|
||||
prompt = prompt + '\n' + options.outputType;
|
||||
}
|
||||
|
||||
const completion = await deepseek.chat.completions.create({
|
||||
model: options.model || "deepseek-chat",
|
||||
messages: [
|
||||
{ role: "system", content: options.contestsystem || "" },
|
||||
{ role: "user", content: prompt }
|
||||
],
|
||||
temperature: options.temp || 0.3,
|
||||
max_tokens: options.max_tokens || 1000,
|
||||
stream: options.stream || false,
|
||||
});
|
||||
|
||||
if (!completion || !completion.choices || completion.choices.length === 0) {
|
||||
throw new Error('Invalid response from DeepSeek API');
|
||||
}
|
||||
|
||||
return completion.choices[0];
|
||||
} catch (error) {
|
||||
console.error('DeepSeek Error:', error.response?.data || error.message);
|
||||
throw new Error('Failed to get AI response');
|
||||
}
|
||||
}
|
||||
|
||||
// Endpoint per DeepSeek
|
||||
router.post('/ds', authenticate, async (req, res) => {
|
||||
try {
|
||||
let prompt = req.body.prompt;
|
||||
let options = req.body.options;
|
||||
|
||||
const choice = await getDeepSeekResponse(prompt, options);
|
||||
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
choice,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('DeepSeek API Error:', error.response?.data || error.message);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, error: 'Errore nella chiamata a DeepSeek: ' + error.response?.data || error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -74,7 +74,7 @@ const Department = require('../models/department');
|
||||
const CatProd = require('../models/catprod');
|
||||
const Collana = require('../models/collana');
|
||||
const CatAI = require('../models/catai');
|
||||
const QueryAI = require('../models/queryai');
|
||||
const { QueryAI } = require('../models/queryai');
|
||||
const SubCatProd = require('../models/subcatprod');
|
||||
const { Category } = require('../models/category');
|
||||
const ShareWithUs = require('../models/sharewithus');
|
||||
|
||||
Reference in New Issue
Block a user