oflit-genai 1.0.0__tar.gz

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.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: oflit-genai
3
+ Version: 1.0.0
4
+ Summary: Официальный SDK для работы с моделями Oflit от Oiyres Inc Studio
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: torch
8
+ Requires-Dist: transformers
9
+ Requires-Dist: accelerate
@@ -0,0 +1 @@
1
+ from . import genai
@@ -0,0 +1,61 @@
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ class GenerateContentResponse:
5
+ def __init__(self, text: str):
6
+ self.text = text
7
+
8
+ class Models:
9
+ def __init__(self):
10
+ self._loaded_models = {}
11
+ self._tokenizers = {}
12
+ self.default_instruction = (
13
+ "Ты — Офлит (Oflit 1.0 Flash), эмоциональный ИИ от Oiyres Inc Studio. "
14
+ "Отвечай максимально коротко (1-2 предложения), живо и по делу."
15
+ )
16
+
17
+ def _load_model(self, model_name: str):
18
+ # Связываем красивое имя с базовой или вашей моделью на Hugging Face
19
+ model_map = {
20
+ "oflit-1.0-flash": "Qwen/Qwen2.5-1.5B-Instruct" # Позже замените на ваш репозиторий HF
21
+ }
22
+ hf_id = model_map.get(model_name, model_map["oflit-1.0-flash"])
23
+
24
+ if model_name not in self._loaded_models:
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ dtype = torch.float16 if device == "cuda" else torch.float32
27
+
28
+ self._tokenizers[model_name] = AutoTokenizer.from_pretrained(hf_id)
29
+ self._loaded_models[model_name] = AutoModelForCausalLM.from_pretrained(
30
+ hf_id, torch_dtype=dtype, device_map=device
31
+ )
32
+
33
+ def generate_content(self, model: str = "oflit-1.0-flash", contents: str = "", system_instruction: str = None) -> GenerateContentResponse:
34
+ self._load_model(model)
35
+ tokenizer = self._tokenizers[model]
36
+ net = self._loaded_models[model]
37
+ device = "cuda" if torch.cuda.is_available() else "cpu"
38
+
39
+ instruction = system_instruction or self.default_instruction
40
+ messages = [
41
+ {"role": "system", "content": instruction},
42
+ {"role": "user", "content": contents}
43
+ ]
44
+
45
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
46
+ inputs = tokenizer([text], return_tensors="pt").to(device)
47
+
48
+ outputs = net.generate(
49
+ **inputs,
50
+ max_new_tokens=90, # Ограничение для коротких ответов
51
+ temperature=0.7,
52
+ do_sample=True
53
+ )
54
+
55
+ reply = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
56
+ return GenerateContentResponse(text=reply)
57
+
58
+ class Client:
59
+ def __init__(self, api_key: str = None):
60
+ self.api_key = api_key
61
+ self.models = Models()
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: oflit-genai
3
+ Version: 1.0.0
4
+ Summary: Официальный SDK для работы с моделями Oflit от Oiyres Inc Studio
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: torch
8
+ Requires-Dist: transformers
9
+ Requires-Dist: accelerate
@@ -0,0 +1,8 @@
1
+ pyproject.toml
2
+ oflit/__init__.py
3
+ oflit/genai.py
4
+ oflit_genai.egg-info/PKG-INFO
5
+ oflit_genai.egg-info/SOURCES.txt
6
+ oflit_genai.egg-info/dependency_links.txt
7
+ oflit_genai.egg-info/requires.txt
8
+ oflit_genai.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ torch
2
+ transformers
3
+ accelerate
@@ -0,0 +1,15 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "oflit-genai"
7
+ version = "1.0.0"
8
+ description = "Официальный SDK для работы с моделями Oflit от Oiyres Inc Studio"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "torch",
13
+ "transformers",
14
+ "accelerate"
15
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+