neogram 9.3.1__py3-none-any.whl → 9.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- neogram/ii.py +13 -62
- {neogram-9.3.1.dist-info → neogram-9.3.3.dist-info}/METADATA +2 -3
- neogram-9.3.3.dist-info/RECORD +8 -0
- neogram-9.3.1.dist-info/RECORD +0 -8
- {neogram-9.3.1.dist-info → neogram-9.3.3.dist-info}/WHEEL +0 -0
- {neogram-9.3.1.dist-info → neogram-9.3.3.dist-info}/licenses/LICENSE +0 -0
- {neogram-9.3.1.dist-info → neogram-9.3.3.dist-info}/top_level.txt +0 -0
neogram/ii.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import requests, json, base64, threading, re, bs4
|
|
1
|
+
import requests, json, base64, threading, re, bs4, uuid
|
|
2
2
|
from typing import Union, BinaryIO
|
|
3
3
|
from curl_cffi.requests import Session
|
|
4
4
|
|
|
5
5
|
#Блок - Нейросети
|
|
6
6
|
class OnlySQ:
|
|
7
|
+
def __init__(self, key: str):
|
|
8
|
+
self.key = key
|
|
9
|
+
|
|
7
10
|
def get_models(self, modality: str | list = None, can_tools: bool = None, can_stream: bool = None, status: str = None, max_cost: float = None, return_names: bool = False) -> list:
|
|
8
11
|
"""
|
|
9
12
|
Фильтрует модели по заданным параметрам
|
|
@@ -35,6 +38,10 @@ class OnlySQ:
|
|
|
35
38
|
model_tools = model_data.get("can-tools", False)
|
|
36
39
|
if model_tools != can_tools:
|
|
37
40
|
matches = False
|
|
41
|
+
if matches and can-think is not None:
|
|
42
|
+
model_can_think = model_data.get("can-think", False)
|
|
43
|
+
if model_can_think != can_think:
|
|
44
|
+
matches = False
|
|
38
45
|
if matches and can_stream is not None:
|
|
39
46
|
model_can_stream = model_data.get("can-stream", False)
|
|
40
47
|
if model_can_stream != can_stream:
|
|
@@ -57,28 +64,28 @@ class OnlySQ:
|
|
|
57
64
|
print(f"OnlySQ(get_models): {e}")
|
|
58
65
|
return []
|
|
59
66
|
|
|
60
|
-
def generate_answer(self, model: str = "gpt-5.2-chat", messages: dict = None
|
|
67
|
+
def generate_answer(self, model: str = "gpt-5.2-chat", messages: dict = None) -> str:
|
|
61
68
|
"""Генерация ответа с использованием onlysq"""
|
|
62
69
|
try:
|
|
63
70
|
if messages is None:
|
|
64
71
|
raise ValueError("Забыли указать messages")
|
|
65
72
|
else:
|
|
66
73
|
payload = {"model": model, "request": {"messages": messages}}
|
|
67
|
-
response = requests.post("http://api.onlysq.ru/ai/v2", json=payload, headers={"Authorization": f"Bearer {key}"})
|
|
74
|
+
response = requests.post("http://api.onlysq.ru/ai/v2", json=payload, headers={"Authorization": f"Bearer {self.key}"})
|
|
68
75
|
response.raise_for_status()
|
|
69
76
|
return response.json()["choices"][0]["message"]["content"]
|
|
70
77
|
except Exception as e:
|
|
71
78
|
print(f"OnlySQ(generate_answer): {e}")
|
|
72
79
|
return "Error"
|
|
73
80
|
|
|
74
|
-
def generate_image(self, model: str = "flux", prompt: str = None, ratio: str = "16:9", filename: str = 'image.png'
|
|
81
|
+
def generate_image(self, model: str = "flux", prompt: str = None, ratio: str = "16:9", filename: str = 'image.png') -> bool:
|
|
75
82
|
"""Генерация фотографии с использованием onlysq"""
|
|
76
83
|
try:
|
|
77
84
|
if prompt is None:
|
|
78
85
|
raise ValueError("Забыли указать prompt")
|
|
79
86
|
else:
|
|
80
87
|
payload = {"model": model, "prompt": prompt, "ratio": ratio}
|
|
81
|
-
response = requests.post("https://api.onlysq.ru/ai/imagen", json=payload, headers={"Authorization": f"Bearer {key}"})
|
|
88
|
+
response = requests.post("https://api.onlysq.ru/ai/imagen", json=payload, headers={"Authorization": f"Bearer {self.key}"})
|
|
82
89
|
if response.status_code == 200:
|
|
83
90
|
img_bytes = base64.b64decode(response.json()["files"][0])
|
|
84
91
|
with open(filename, 'wb') as f:
|
|
@@ -133,60 +140,6 @@ class Deef:
|
|
|
133
140
|
except FileNotFoundError:
|
|
134
141
|
return None
|
|
135
142
|
|
|
136
|
-
def gen_ai_response(self, model: str = "Qwen3 235B", messages: list = None) -> dict[str]:
|
|
137
|
-
"""
|
|
138
|
-
Отправляет запрос к API и возвращает словарь с полной информацией
|
|
139
|
-
Args:
|
|
140
|
-
model: Модель нейросети (Qwen3 235B или GPT OSS 120B)
|
|
141
|
-
messages: Список сообщений в формате [{"role": "...", "content": "..."}]
|
|
142
|
-
Returns:
|
|
143
|
-
dict[str]: Словарь с ключами:
|
|
144
|
-
- reasoning: Размышления модели
|
|
145
|
-
- answer: Финальный ответ модели
|
|
146
|
-
- status: Статус выполнения
|
|
147
|
-
- cluster_info: Информация о кластере (если есть)
|
|
148
|
-
"""
|
|
149
|
-
try:
|
|
150
|
-
if messages is None:
|
|
151
|
-
raise ValueError("Забыли указать messages")
|
|
152
|
-
else:
|
|
153
|
-
model_to_cluster = {"Qwen3 235B": "hybrid", "GPT OSS 120B": "nvidia"}
|
|
154
|
-
cluster_mode = model_to_cluster.get(model)
|
|
155
|
-
if cluster_mode is None:
|
|
156
|
-
raise ValueError(f"Неизвестная модель: {model}, Доступные модели: {list(model_to_cluster.keys())}")
|
|
157
|
-
data = {"model": model, "clusterMode": cluster_mode, "messages": messages, "enableThinking": True}
|
|
158
|
-
url = "https://chat.gradient.network/api/generate"
|
|
159
|
-
response = requests.post(url, json=data, stream=True)
|
|
160
|
-
result = {"reasoning": "", "answer": "", "status": "unknown", "cluster_info": None}
|
|
161
|
-
for line in response.iter_lines():
|
|
162
|
-
if line:
|
|
163
|
-
try:
|
|
164
|
-
json_obj = json.loads(line.decode('utf-8'))
|
|
165
|
-
message_type = json_obj.get("type")
|
|
166
|
-
if message_type == "reply":
|
|
167
|
-
data_content = json_obj.get("data", {})
|
|
168
|
-
if "reasoningContent" in data_content:
|
|
169
|
-
result["reasoning"] += data_content.get("reasoningContent", "")
|
|
170
|
-
if "content" in data_content:
|
|
171
|
-
result["answer"] += data_content.get("content", "")
|
|
172
|
-
elif message_type == "jobInfo":
|
|
173
|
-
status = json_obj.get("data", {}).get("status")
|
|
174
|
-
result["status"] = status
|
|
175
|
-
if status == "completed":
|
|
176
|
-
break
|
|
177
|
-
elif message_type == "clusterInfo":
|
|
178
|
-
result["cluster_info"] = json_obj.get("data", {})
|
|
179
|
-
except json.JSONDecodeError as e:
|
|
180
|
-
print(f"Ошибка декодирования JSON: {e}")
|
|
181
|
-
continue
|
|
182
|
-
except Exception as e:
|
|
183
|
-
print(f"Неожиданная ошибка: {e}")
|
|
184
|
-
continue
|
|
185
|
-
return result
|
|
186
|
-
except Exception as e:
|
|
187
|
-
print(f"Deef(gen_ai_response): {e}")
|
|
188
|
-
return {"reasoning": "Error", "answer": "Error", "status": "unknown", "cluster_info": None}
|
|
189
|
-
|
|
190
143
|
def perplexity_ask(self, model: str, query: str) -> dict:
|
|
191
144
|
"""
|
|
192
145
|
Вывод: словари с ключом 'type' и данными:
|
|
@@ -204,9 +157,7 @@ class Deef:
|
|
|
204
157
|
"grok4", "gemini2flash", "pplx_pro", "pplx_pro_upgraded", "pplx_alpha",
|
|
205
158
|
"pplx_beta", "comet_max_assistant", "o3_research", "o3pro_research", "claude40sonnet_research",
|
|
206
159
|
"claude40sonnetthinking_research", "claude40opus_research", "claude40opusthinking_research", "o3_labs", "o3pro_labs",
|
|
207
|
-
"claude40sonnetthinking_labs", "claude40opusthinking_labs", "o4mini", "
|
|
208
|
-
"gpt45", "gpt4", "o3mini", "claude35haiku", "llama_x_large",
|
|
209
|
-
"mistral", "claude3opus", "gemini", "pplx_reasoning", "r1"]
|
|
160
|
+
"claude40sonnetthinking_labs", "claude40opusthinking_labs", "o4mini", "claude3opus", "pplx_reasoning", "r1"]
|
|
210
161
|
BASE_URL = "https://www.perplexity.ai"
|
|
211
162
|
if model not in MODELS:
|
|
212
163
|
model = MODELS[0]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: neogram
|
|
3
|
-
Version: 9.3.
|
|
3
|
+
Version: 9.3.3
|
|
4
4
|
Summary: neogram is a lightweight Python module for working with the Telegram Bot API and AI. It combines simple Telegram workflows with powerful features like text and image generation, translation, and more.
|
|
5
5
|
Author: SiriLV
|
|
6
6
|
Author-email: siriteamrs@gmail.com
|
|
@@ -26,7 +26,7 @@ Dynamic: requires-dist
|
|
|
26
26
|
Dynamic: requires-python
|
|
27
27
|
Dynamic: summary
|
|
28
28
|
|
|
29
|
-
# 📚 Документация neogram v9.3.
|
|
29
|
+
# 📚 Документация neogram v9.3.3
|
|
30
30
|
|
|
31
31
|
**Установка:**
|
|
32
32
|
|
|
@@ -88,7 +88,6 @@ bot = Bot(token="YOUR_TOKEN", timeout=60)
|
|
|
88
88
|
Набор утилит и альтернативных API.
|
|
89
89
|
* `translate(text, lang)`: Перевод текста (через Google Translate).
|
|
90
90
|
* `short_url(long_url)`: Сокращение ссылок (clck.ru).
|
|
91
|
-
* `gen_ai_response(model, messages)`: Генерация ответа (Qwen/GPT OSS).
|
|
92
91
|
* `perplexity_ask(model, query)`: Генерация через PerplexityAI
|
|
93
92
|
* `encode_base64(path)`: Кодирование файла в base64.
|
|
94
93
|
* `run_in_bg(func, ...)`: Запуск функции в отдельном потоке.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
neogram/__init__.py,sha256=C47Ofb8xvEqQlB-6Vt8hzOPpWcjASjSV8YID_bxbkW4,7307
|
|
2
|
+
neogram/fgram.py,sha256=zO3_MhJyCtJUzbU6FYY9FO747GSQLkdWqr45zYehNMs,257655
|
|
3
|
+
neogram/ii.py,sha256=jm95_eKlFKju4CCbFshgtO2_Wgl5AKNgSl6TDeCT0IY,18434
|
|
4
|
+
neogram-9.3.3.dist-info/licenses/LICENSE,sha256=FAb9EYIqo8kpOGEwL_lH45SL_SLJ9wDxbSSRFpsSzvs,1112
|
|
5
|
+
neogram-9.3.3.dist-info/METADATA,sha256=SVdJo2bMm2vXuEJUlHTo8VTPMQQZ4a7XDK-noaUrb6w,50101
|
|
6
|
+
neogram-9.3.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
+
neogram-9.3.3.dist-info/top_level.txt,sha256=NqTlzfnaxZNIo9TCYSbG_LtE05Kx6JfrSSgzVPMAawA,8
|
|
8
|
+
neogram-9.3.3.dist-info/RECORD,,
|
neogram-9.3.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
neogram/__init__.py,sha256=C47Ofb8xvEqQlB-6Vt8hzOPpWcjASjSV8YID_bxbkW4,7307
|
|
2
|
-
neogram/fgram.py,sha256=zO3_MhJyCtJUzbU6FYY9FO747GSQLkdWqr45zYehNMs,257655
|
|
3
|
-
neogram/ii.py,sha256=zn89zKLXWPcNh001vUqoubB1BE00NyLmphTwRQYHNnA,21645
|
|
4
|
-
neogram-9.3.1.dist-info/licenses/LICENSE,sha256=FAb9EYIqo8kpOGEwL_lH45SL_SLJ9wDxbSSRFpsSzvs,1112
|
|
5
|
-
neogram-9.3.1.dist-info/METADATA,sha256=Z-TlncYXpnJa_2lONHWyEdv3064rv2P1D8zD5CWaEoM,50190
|
|
6
|
-
neogram-9.3.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
-
neogram-9.3.1.dist-info/top_level.txt,sha256=NqTlzfnaxZNIo9TCYSbG_LtE05Kx6JfrSSgzVPMAawA,8
|
|
8
|
-
neogram-9.3.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|