aistv 1.3.2__tar.gz → 1.3.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aistv
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: STV AI Chatbot Library for Python
5
5
  Home-page: https://github.com/phuctrong1tuv
6
6
  Author: Trọng Phúc
@@ -17,19 +17,52 @@ import requests
17
17
  from groq import Groq
18
18
 
19
19
  DB_FILE = "usage.db"
20
- MAX_REQUESTS_PER_DAY = 20
21
20
  SPAM_DELAY_SECONDS = 5
21
+
22
+ # Giới hạn theo loại token
23
+ FREE_MAX_REQUESTS = 20
24
+ NORMAL_MAX_REQUESTS = 30
25
+ VIP_MAX_REQUESTS = None # Không giới hạn
26
+
27
+ # Ví dụ token thường và token VIP bạn quản lý
28
+ TOKEN_VIP_SET = {
29
+ "aistv",
30
+ "phuc",
31
+ }
32
+
33
+ TOKEN_NORMAL_SET = {
34
+ "aistvgsk_wr9rnhdGCQYCaeAEFQusWGdyb3FYF4LVKrxM0I9JDSGkZIVIymwPgsk_wr9rnhdGCQYCaeAEFQusWGdyb3FYF4LVKrxM0I9JDSGkZIVIymwPgsk_wr9rnhdGCQYCaeAEFQusWGdyb3FYF4LVKrxM0I9JDSGkZIVIymwPgsk_wr9rnhdGCQYCaeAEFQusWGdyb3FYF4LVKrxM0I9JDSGkZIVIymwP",
35
+ "tokengsk_wr9rnhdGCQYCaeAEFQusWGdyb3FYF4LVKrxM0I9JDSGkZIVIymwP",
36
+ }
37
+
22
38
  API_KEY = "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"
23
39
 
24
40
  class STVBot:
25
- def __init__(self, user_id: str, system_prompt: str = None):
41
+ def __init__(self, token: str = None, system_prompt: str = None):
42
+ """
43
+ token: None (free user), or token string (normal or VIP)
44
+ """
26
45
  if not system_prompt:
27
46
  system_prompt = "Tôi là AI STV, được phát triển bởi Trọng Phúc."
28
47
  self.client = Groq(api_key=API_KEY)
29
48
  self.system_prompt = system_prompt
30
49
  self.model = "meta-llama/llama-4-maverick-17b-128e-instruct"
31
50
  self.history = [{"role": "system", "content": self.system_prompt}]
32
- self.user_id = user_id
51
+
52
+ self.token = token
53
+ if token is None:
54
+ self.max_requests = FREE_MAX_REQUESTS
55
+ self.user_id = "free_user"
56
+ elif token in TOKEN_VIP_SET:
57
+ self.max_requests = VIP_MAX_REQUESTS
58
+ self.user_id = token
59
+ elif token in TOKEN_NORMAL_SET:
60
+ self.max_requests = NORMAL_MAX_REQUESTS
61
+ self.user_id = token
62
+ else:
63
+ # Token không hợp lệ tính free
64
+ self.max_requests = FREE_MAX_REQUESTS
65
+ self.user_id = "free_user"
33
66
 
34
67
  # Kết nối DB SQLite
35
68
  self.conn = sqlite3.connect(DB_FILE, check_same_thread=False)
@@ -83,10 +116,10 @@ class STVBot:
83
116
  usage["count"] = 0
84
117
  usage["last_date"] = today
85
118
 
86
- if usage["count"] >= MAX_REQUESTS_PER_DAY:
119
+ if self.max_requests is not None and usage["count"] >= self.max_requests:
87
120
  return (
88
- "⚠️ Bạn đã sử dụng hết giới hạn 20 câu hỏi miễn phí trong ngày.\n"
89
- "Vui lòng thử lại vào ngày mai hoặc liên hệ để được cấp thêm quyền."
121
+ f"⚠️ Bạn đã sử dụng hết giới hạn {self.max_requests} câu hỏi trong ngày.\n"
122
+ "Vui lòng thử lại vào ngày mai hoặc liên hệ để được cấp thêm quyền.https://discord.gg/Ze7RTExgdv"
90
123
  )
91
124
 
92
125
  if now - usage["last_time"] < SPAM_DELAY_SECONDS:
@@ -104,11 +137,12 @@ class STVBot:
104
137
  reply = chat_completion.choices[0].message.content
105
138
  self.history.append({"role": "assistant", "content": reply})
106
139
 
107
- usage["count"] += 1
108
- usage["last_time"] = now
109
- self._save_usage(usage["count"], usage["last_time"], usage["last_date"])
140
+ if self.max_requests is not None:
141
+ usage["count"] += 1
142
+ usage["last_time"] = now
143
+ self._save_usage(usage["count"], usage["last_time"], usage["last_date"])
110
144
 
111
145
  return reply.strip()
112
146
 
113
147
  except Exception as e:
114
- return f"⚠️ Lỗi khi: {e}"
148
+ return f"⚠️ Lỗi khi gọi API: {e}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aistv
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: STV AI Chatbot Library for Python
5
5
  Home-page: https://github.com/phuctrong1tuv
6
6
  Author: Trọng Phúc
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="aistv",
5
- version="1.3.2",
5
+ version="1.3.4",
6
6
  description="STV AI Chatbot Library for Python",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes