Spaces:
Running
Running
Update llm_sender_unified.py
Browse files- llm_sender_unified.py +22 -8
llm_sender_unified.py
CHANGED
|
@@ -41,6 +41,14 @@ class LLMSender(ABC):
|
|
| 41 |
"""تغییر مدل"""
|
| 42 |
self.model = model
|
| 43 |
logger.info(f"✅ مدل تغییر یافت به: {model}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def send_simple(self, text: str, lang: str = 'fa') -> str:
|
| 46 |
"""ارسال ساده بدون system message سفارشی"""
|
|
@@ -94,17 +102,23 @@ class LLMSender(ABC):
|
|
| 94 |
}
|
| 95 |
|
| 96 |
# ساخت request body
|
|
|
|
| 97 |
data = {
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
"temperature": temperature
|
| 105 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
| 108 |
for attempt in range(retry_count):
|
| 109 |
try:
|
| 110 |
logger.info(f"📤 ارسال درخواست به {self.__class__.__name__} (تلاش {attempt + 1}/{retry_count})...")
|
|
|
|
| 41 |
"""تغییر مدل"""
|
| 42 |
self.model = model
|
| 43 |
logger.info(f"✅ مدل تغییر یافت به: {model}")
|
| 44 |
+
|
| 45 |
+
def _uses_max_completion_tokens(self) -> bool:
|
| 46 |
+
"""بررسی اینکه آیا مدل از max_completion_tokens استفاده میکند"""
|
| 47 |
+
models_with_completion_tokens = [
|
| 48 |
+
'o1-preview', 'o1-mini', 'o1',
|
| 49 |
+
'gpt-5', 'gpt-5.1', 'gpt-5-mini', 'gpt-5-nano', 'gpt-5-for'
|
| 50 |
+
]
|
| 51 |
+
return any(self.model.startswith(prefix) for prefix in models_with_completion_tokens)
|
| 52 |
|
| 53 |
def send_simple(self, text: str, lang: str = 'fa') -> str:
|
| 54 |
"""ارسال ساده بدون system message سفارشی"""
|
|
|
|
| 102 |
}
|
| 103 |
|
| 104 |
# ساخت request body
|
| 105 |
+
|
| 106 |
data = {
|
| 107 |
+
"model": self.model,
|
| 108 |
+
"messages": [
|
| 109 |
+
{"role": "system", "content": system_msg},
|
| 110 |
+
{"role": "user", "content": text}
|
| 111 |
+
],
|
| 112 |
+
"temperature": temperature
|
|
|
|
| 113 |
}
|
| 114 |
+
|
| 115 |
+
# انتخاب پارامتر مناسب
|
| 116 |
+
if self._uses_max_completion_tokens():
|
| 117 |
+
data["max_completion_tokens"] = max_tokens
|
| 118 |
+
else:
|
| 119 |
+
data["max_tokens"] = max_tokens
|
| 120 |
|
| 121 |
+
# ارسال با retry mechanism
|
| 122 |
for attempt in range(retry_count):
|
| 123 |
try:
|
| 124 |
logger.info(f"📤 ارسال درخواست به {self.__class__.__name__} (تلاش {attempt + 1}/{retry_count})...")
|