Mark-Lasfar commited on
Commit ·
03fcf73
1
Parent(s): 6f8023f
Fix: Optimize loadStore function, fix preview mode and follow-status
Browse files- services/aiService.js +20 -22
services/aiService.js
CHANGED
|
@@ -42,21 +42,11 @@ class AIService {
|
|
| 42 |
/**
|
| 43 |
* اختيار النموذج المناسب للمهمة
|
| 44 |
*/
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
if (complexTasks.some(t => taskType.includes(t))) {
|
| 52 |
-
return this.models.precise;
|
| 53 |
-
}
|
| 54 |
-
if (simpleTasks.some(t => taskType.includes(t))) {
|
| 55 |
-
return this.models.fast;
|
| 56 |
-
}
|
| 57 |
-
// المهام المتوسطة
|
| 58 |
-
return this.models.fast;
|
| 59 |
-
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
* الحصول على مفتاح التخزين المؤقت
|
|
@@ -110,7 +100,7 @@ Respond with valid JSON when requested. Be concise, professional, and ensure out
|
|
| 110 |
'Authorization': `Bearer ${this.hfApiKey}`,
|
| 111 |
'Content-Type': 'application/json'
|
| 112 |
},
|
| 113 |
-
timeout:
|
| 114 |
}
|
| 115 |
);
|
| 116 |
|
|
@@ -139,23 +129,31 @@ Respond with valid JSON when requested. Be concise, professional, and ensure out
|
|
| 139 |
* استدعاء AI مع اختيار ذكي للنموذج
|
| 140 |
*/
|
| 141 |
async callAI(prompt, temperature = 0.7, taskType = 'general') {
|
| 142 |
-
|
| 143 |
-
const
|
|
|
|
| 144 |
const cached = this.cache.get(cacheKey);
|
| 145 |
|
| 146 |
if (cached && (Date.now() - cached.timestamp) < this.cacheTTL) {
|
| 147 |
return cached.result;
|
| 148 |
}
|
| 149 |
|
| 150 |
-
|
|
|
|
| 151 |
|
| 152 |
-
// إذا فشل
|
| 153 |
if (!result) {
|
| 154 |
-
const fallbackModel =
|
| 155 |
-
console.log(`
|
| 156 |
result = await this.callHuggingFace(prompt, temperature, fallbackModel);
|
| 157 |
}
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
if (result) {
|
| 160 |
this.cache.set(cacheKey, { result, timestamp: Date.now() });
|
| 161 |
return result;
|
|
|
|
| 42 |
/**
|
| 43 |
* اختيار النموذج المناسب للمهمة
|
| 44 |
*/
|
| 45 |
+
selectModel(taskType) {
|
| 46 |
+
// ✅ دائماً استخدم النموذج السريع (Qwen) لكل شيء أولاً
|
| 47 |
+
// DeepSeek سيُستخدم فقط كاحتياطي إذا فشل Qwen
|
| 48 |
+
return this.models.fast; // Qwen/Qwen2.5-7B-Instruct
|
| 49 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
/**
|
| 52 |
* الحصول على مفتاح التخزين المؤقت
|
|
|
|
| 100 |
'Authorization': `Bearer ${this.hfApiKey}`,
|
| 101 |
'Content-Type': 'application/json'
|
| 102 |
},
|
| 103 |
+
timeout: 30000 // 90 seconds timeout for complex tasks
|
| 104 |
}
|
| 105 |
);
|
| 106 |
|
|
|
|
| 129 |
* استدعاء AI مع اختيار ذكي للنموذج
|
| 130 |
*/
|
| 131 |
async callAI(prompt, temperature = 0.7, taskType = 'general') {
|
| 132 |
+
// ✅ استخدم النموذج السريع (Qwen) أولاً
|
| 133 |
+
const primaryModel = this.models.fast; // Qwen
|
| 134 |
+
const cacheKey = this.getCacheKey(prompt, taskType, primaryModel);
|
| 135 |
const cached = this.cache.get(cacheKey);
|
| 136 |
|
| 137 |
if (cached && (Date.now() - cached.timestamp) < this.cacheTTL) {
|
| 138 |
return cached.result;
|
| 139 |
}
|
| 140 |
|
| 141 |
+
console.log(`🤖 Trying primary model: ${primaryModel}`);
|
| 142 |
+
let result = await this.callHuggingFace(prompt, temperature, primaryModel);
|
| 143 |
|
| 144 |
+
// ✅ فقط إذا فشل Qwen، جرب DeepSeek كاحتياطي
|
| 145 |
if (!result) {
|
| 146 |
+
const fallbackModel = this.models.precise; // DeepSeek
|
| 147 |
+
console.log(`⚠️ Primary model failed, trying fallback: ${fallbackModel}`);
|
| 148 |
result = await this.callHuggingFace(prompt, temperature, fallbackModel);
|
| 149 |
}
|
| 150 |
|
| 151 |
+
// ✅ إذا فشل كلاهما، استخدم الاحتياطي النهائي
|
| 152 |
+
if (!result) {
|
| 153 |
+
console.log(`⚠️ Both models failed, using final fallback: ${this.models.fallback}`);
|
| 154 |
+
result = await this.callHuggingFace(prompt, temperature, this.models.fallback);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
if (result) {
|
| 158 |
this.cache.set(cacheKey, { result, timestamp: Date.now() });
|
| 159 |
return result;
|