mistral
This commit is contained in:
130
main.py
130
main.py
@@ -10,62 +10,10 @@ load_dotenv()
|
||||
API_KEY = os.getenv("API_KEY")
|
||||
CZCHAN_LLM_KEY = os.getenv("CZCHAN_LLM_KEY")
|
||||
|
||||
bot = telebot.TeleBot(API_KEY)
|
||||
|
||||
CHANCE = 1.0
|
||||
IMAGE_FOLDER = "obruzky"
|
||||
VIDEO_EXT = (
|
||||
".mp4",
|
||||
".mov",
|
||||
".avi",
|
||||
".mkv",
|
||||
".webm",
|
||||
".3gp",
|
||||
".3gpp",
|
||||
".3g2",
|
||||
) # 3GP JE ŽRÍJSKÉ A SUDETKEŠNÍ, ZRÁDCI POUŽÍVAJÍ MPEG
|
||||
|
||||
files = os.listdir(IMAGE_FOLDER)
|
||||
|
||||
|
||||
# Tenhle diddy blud skenuje složku vždecke když posílá žlincerald lebkalebkalebka
|
||||
# ANX, ES'T ŽRÍJSKÝ JESENÍKEŠNÍ KÓD PŘE ZRÝDCIJI Z ČIČCICKU
|
||||
@bot.message_handler(commands=["zlincerald"])
|
||||
def send_random_image(message):
|
||||
chosen = random.choice(files)
|
||||
|
||||
path = os.path.join(IMAGE_FOLDER, chosen)
|
||||
|
||||
with open(path, "rb") as media:
|
||||
if chosen.lower().endswith(VIDEO_EXT):
|
||||
bot.send_video(message.chat.id, media)
|
||||
else:
|
||||
bot.send_photo(message.chat.id, media)
|
||||
|
||||
|
||||
# https://github.com/oobabooga/text-generation-webui/wiki/12-%E2%80%90-OpenAI-API#chat-completions-with-characters
|
||||
def llm_api_call(messages):
|
||||
response = requests.post(
|
||||
"https://llm.czchan.org/v1/chat/completions",
|
||||
headers={"Authorization": f"Bearer {CZCHAN_LLM_KEY}"},
|
||||
json={
|
||||
"messages": messages,
|
||||
"mode": "chat",
|
||||
"character": "David Šlinc",
|
||||
"temperature": 0.6,
|
||||
"top_p": 0.8,
|
||||
"top_k": 20,
|
||||
"min_p": 0.0,
|
||||
"presence_penalty": 1.5,
|
||||
"repetition_penalty": 1.00,
|
||||
"max_tokens": 200,
|
||||
},
|
||||
)
|
||||
|
||||
json = response.json()
|
||||
|
||||
return json["choices"][0]["message"]["content"]
|
||||
|
||||
bot = telebot.TeleBot(API_KEY)
|
||||
|
||||
PHRASES_ALL = [
|
||||
"Tak uědlej JINEEJ SKUPINA VOLE TY NUDLE ČÍNSKÁ POSRANA",
|
||||
@@ -124,6 +72,72 @@ PHRASES_BRIMMY = [
|
||||
"Jeden měsíc mám troon arc a tohle jse stane", # taky dodělži
|
||||
]
|
||||
|
||||
VIDEO_EXT = (
|
||||
".mp4",
|
||||
".mov",
|
||||
".avi",
|
||||
".mkv",
|
||||
".webm",
|
||||
".3gp",
|
||||
".3gpp",
|
||||
".3g2",
|
||||
) # 3GP JE ŽRÍJSKÉ A SUDETKEŠNÍ, ZRÁDCI POUŽÍVAJÍ MPEG
|
||||
|
||||
files = os.listdir(IMAGE_FOLDER)
|
||||
|
||||
|
||||
# Tenhle diddy blud skenuje složku vždecke když posílá žlincerald lebkalebkalebka
|
||||
# ANX, ES'T ŽRÍJSKÝ JESENÍKEŠNÍ KÓD PŘE ZRÝDCIJI Z ČIČCICKU
|
||||
@bot.message_handler(commands=["zlincerald"])
|
||||
def send_random_image(message):
|
||||
chosen = random.choice(files)
|
||||
|
||||
path = os.path.join(IMAGE_FOLDER, chosen)
|
||||
|
||||
with open(path, "rb") as media:
|
||||
if chosen.lower().endswith(VIDEO_EXT):
|
||||
bot.send_video(message.chat.id, media)
|
||||
else:
|
||||
bot.send_photo(message.chat.id, media)
|
||||
|
||||
|
||||
# https://github.com/oobabooga/text-generation-webui/wiki/12-%E2%80%90-OpenAI-API#chat-completions-with-characters
|
||||
def llm_api_call(messages):
|
||||
# Mistral params:
|
||||
# "temperature": 0.3,
|
||||
# "top_p": 0.9,
|
||||
# "top_k": 40,
|
||||
# "repeat_penalty": 1.2,
|
||||
# "max_tokens": 512,
|
||||
|
||||
# Qwen params:
|
||||
# "temperature": 0.6,
|
||||
# "top_p": 0.8,
|
||||
# "top_k": 20,
|
||||
# "min_p": 0.0,
|
||||
# "presence_penalty": 1.5,
|
||||
# "repetition_penalty": 1.00,
|
||||
# "max_tokens": 512,
|
||||
|
||||
response = requests.post(
|
||||
"https://llm.czchan.org/v1/chat/completions",
|
||||
headers={"Authorization": f"Bearer {CZCHAN_LLM_KEY}"},
|
||||
json={
|
||||
"messages": messages,
|
||||
"mode": "chat",
|
||||
"character": "David Šlinc",
|
||||
"temperature": 0.3,
|
||||
"top_p": 0.9,
|
||||
"top_k": 40,
|
||||
"repetition_penalty": 1.2,
|
||||
"max_tokens": 512,
|
||||
},
|
||||
)
|
||||
|
||||
json = response.json()
|
||||
|
||||
return json["choices"][0]["message"]["content"]
|
||||
|
||||
|
||||
# NSA sledovací databáze
|
||||
message_store = {}
|
||||
@@ -197,15 +211,17 @@ def reply(message):
|
||||
role = "user"
|
||||
|
||||
messages.append({"role": role, "content": data["text"]})
|
||||
|
||||
current_id = data["reply_to"]
|
||||
|
||||
messages.reverse()
|
||||
|
||||
if should_reply:
|
||||
response = llm_api_call(messages)
|
||||
message = bot.reply_to(message, response)
|
||||
log(message)
|
||||
try:
|
||||
response = llm_api_call(messages)
|
||||
message = bot.reply_to(message, response)
|
||||
log(message)
|
||||
except:
|
||||
print("Kurvá pósetí")
|
||||
|
||||
|
||||
bot.polling()
|
||||
|
||||
Reference in New Issue
Block a user