make use of user setting temperature

main
pluja 2023-04-12 17:03:09 +02:00
rodzic bc6801fa06
commit 28921d6b6d
1 zmienionych plików z 6 dodań i 6 usunięć

12
main.py
Wyświetl plik

@ -60,14 +60,14 @@ def restricted(func):
return
else:
if not f"{update.effective_chat.id}" in users:
users[f"{update.effective_chat.id}"] = {"context": [], "usage": {"chatgpt": 0,"whisper": 0,"dalle": 0,}, "options": {"whisper-to-chat": WHISPER_TO_CHAT, "temperature": 0.9, "max-context": 5}}
users[f"{update.effective_chat.id}"] = {"context": [], "usage": {"chatgpt": 0,"whisper": 0,"dalle": 0,}, "options": {"whisper-to-chat": WHISPER_TO_CHAT, "temperature": float(TEMPERATURE), "max-context": MAX_USER_CONTEXT}}
return await func(update, context, *args, **kwargs)
return wrapped
async def messageGPT(text: str, chat_id: str):
# Initialize user if not present
if chat_id not in users:
users[chat_id] = {"context": [], "usage": {"chatgpt": 0, "whisper": 0, "dalle": 0}}
users[chat_id] = {"context": [], "usage": {"chatgpt": 0,"whisper": 0,"dalle": 0,}, "options": {"whisper-to-chat": WHISPER_TO_CHAT, "temperature": float(TEMPERATURE), "max-context": MAX_USER_CONTEXT}}
# Update context
user_context = users[chat_id]["context"]
@ -81,7 +81,7 @@ async def messageGPT(text: str, chat_id: str):
response = openai.ChatCompletion.create(
model=MODEL,
messages=[{"role": "system", "content": SYSTEM_PROMPT}] + user_context,
temperature=float(TEMPERATURE)
temperature=users[chat_id]["options"]["temperature"],
)
except:
return "There was a problem with OpenAI, so I can't answer you."
@ -106,7 +106,7 @@ async def messageGPT(text: str, chat_id: str):
@restricted
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not f"{update.effective_chat.id}" in users:
users[f"{update.effective_chat.id}"] = {"context": [], "usage": {"chatgpt": 0,"whisper": 0,"dalle": 0,}, "options": {"whisper-to-chat": WHISPER_TO_CHAT, "temperature": 0.9, "max-context": 5}}
users[f"{update.effective_chat.id}"] = {"context": [], "usage": {"chatgpt": 0,"whisper": 0,"dalle": 0,}, "options": {"whisper-to-chat": WHISPER_TO_CHAT, "temperature": float(TEMPERATURE), "max-context": MAX_USER_CONTEXT}}
await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
@restricted
@ -182,7 +182,7 @@ async def attachment(update: Update, context: ContextTypes.DEFAULT_TYPE):
if audioMessage and users[f"{chat_id}"]["options"]["whisper-to-chat"]:
chatGPT_response = await messageGPT(transcript['text'], str(chat_id))
transcript['text'] = "> " + transcript['text'] + "\n\n " + chatGPT_response
transcript['text'] = "> " + transcript['text'] + "\n\n" + chatGPT_response
# Check if the transcript length is longer than 4095 characters
if len(transcript['text']) > 4095:
@ -214,7 +214,7 @@ async def chat(update: Update, context: ContextTypes.DEFAULT_TYPE):
# Check if replying and add context
if hasattr(update.message.reply_to_message, "text"):
user_prompt = f"In reply to: '{update.message.reply_to_message.text}' \n---\n {update.message.text}"
user_prompt = f"In reply to: '{update.message.reply_to_message.text}' \n---\n{update.message.text}"
else:
user_prompt = update.message.text