mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
fix: chatgpt fix
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
3b65e61377
commit
e91862a548
@ -5,6 +5,7 @@ from openai import OpenAI
|
|||||||
from telebot import TeleBot
|
from telebot import TeleBot
|
||||||
from telebot.types import Message
|
from telebot.types import Message
|
||||||
from expiringdict import ExpiringDict
|
from expiringdict import ExpiringDict
|
||||||
|
from rich import print
|
||||||
|
|
||||||
from . import *
|
from . import *
|
||||||
|
|
||||||
@ -16,8 +17,8 @@ markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
|||||||
|
|
||||||
CHATGPT_API_KEY = environ.get("OPENAI_API_KEY")
|
CHATGPT_API_KEY = environ.get("OPENAI_API_KEY")
|
||||||
CHATGPT_BASE_URL = environ.get("OPENAI_API_BASE") or "https://api.openai.com/v1"
|
CHATGPT_BASE_URL = environ.get("OPENAI_API_BASE") or "https://api.openai.com/v1"
|
||||||
CHATGPT_MODEL = "gpt-3.5-turbo"
|
CHATGPT_MODEL = "gpt-4o-mini-2024-07-18"
|
||||||
CHATGPT_PRO_MODEL = "gpt-4o-2024-05-13"
|
CHATGPT_PRO_MODEL = "gpt-4o-mini-2024-07-18"
|
||||||
|
|
||||||
|
|
||||||
client = OpenAI(api_key=CHATGPT_API_KEY, base_url=CHATGPT_BASE_URL)
|
client = OpenAI(api_key=CHATGPT_API_KEY, base_url=CHATGPT_BASE_URL)
|
||||||
@ -30,6 +31,7 @@ chatgpt_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
|||||||
|
|
||||||
def chatgpt_handler(message: Message, bot: TeleBot) -> None:
|
def chatgpt_handler(message: Message, bot: TeleBot) -> None:
|
||||||
"""gpt : /gpt <question>"""
|
"""gpt : /gpt <question>"""
|
||||||
|
print(message)
|
||||||
m = message.text.strip()
|
m = message.text.strip()
|
||||||
|
|
||||||
player_message = []
|
player_message = []
|
||||||
@ -126,13 +128,14 @@ def chatgpt_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
try:
|
try:
|
||||||
r = client.chat.completions.create(
|
r = client.chat.completions.create(
|
||||||
messages=player_message,
|
messages=player_message,
|
||||||
max_tokens=4096,
|
|
||||||
model=CHATGPT_PRO_MODEL,
|
model=CHATGPT_PRO_MODEL,
|
||||||
stream=True,
|
stream=True,
|
||||||
)
|
)
|
||||||
s = ""
|
s = ""
|
||||||
start = time.time()
|
start = time.time()
|
||||||
for chunk in r:
|
for chunk in r:
|
||||||
|
print(chunk)
|
||||||
|
if chunk.choices:
|
||||||
if chunk.choices[0].delta.content is None:
|
if chunk.choices[0].delta.content is None:
|
||||||
break
|
break
|
||||||
s += chunk.choices[0].delta.content
|
s += chunk.choices[0].delta.content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user