Skip to content

Commit

Permalink
Fixed bug: in gpt-4-vision-preview that causes an error when NICk is …
Browse files Browse the repository at this point in the history
…present
  • Loading branch information
yym68686 committed Dec 20, 2023
1 parent 9f2bc32 commit cac30e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,32 @@
async def command_bot(update, context, language=None, prompt=translator_prompt, title="", robot=None, has_command=True):
image_url = None
if update.edited_message:
message = update.edited_message.text if config.NICK is None else update.edited_message.text[botNicKLength:].strip() if update.edited_message.text[:botNicKLength].lower() == botNick else None
rawtext = update.edited_message.text
chatid = update.edited_message.chat_id
messageid = update.edited_message.message_id
if update.edited_message.text:
message = update.edited_message.text if config.NICK is None else update.edited_message.text[botNicKLength:].strip() if update.edited_message.text[:botNicKLength].lower() == botNick else None
rawtext = update.edited_message.text

if update.edited_message.photo:
photo = update.edited_message.photo[-1]
file_id = photo.file_id
photo_file = await context.bot.getFile(file_id)
image_url = photo_file.file_path

message = rawtext = update.edited_message.caption
message = rawtext = update.edited_message.caption if config.NICK is None else update.edited_message.caption[botNicKLength:].strip() if update.edited_message.caption[:botNicKLength].lower() == botNick else None
else:
message = update.message.text if config.NICK is None else update.message.text[botNicKLength:].strip() if update.message.text[:botNicKLength].lower() == botNick else None
rawtext = update.message.text
chatid = update.message.chat_id
messageid = update.message.message_id

if update.message.text:
message = update.message.text if config.NICK is None else update.message.text[botNicKLength:].strip() if update.message.text[:botNicKLength].lower() == botNick else None
rawtext = update.message.text
if update.message.photo:
photo = update.message.photo[-1]
file_id = photo.file_id
photo_file = await context.bot.getFile(file_id)
image_url = photo_file.file_path

message = rawtext = update.message.caption
message = rawtext = update.message.caption if config.NICK is None else update.message.caption[botNicKLength:].strip() if update.message.caption[:botNicKLength].lower() == botNick else None
print("\033[32m", update.effective_user.username, update.effective_user.id, rawtext, "\033[0m")

if has_command == False or len(context.args) > 0:
Expand All @@ -73,8 +74,11 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
if message:
if "claude" in config.GPT_ENGINE and config.ClaudeAPI:
robot = config.claudeBot
if image_url:
robot = config.GPT4visionbot
title = "`🤖️ gpt-4-vision-preview`\n\n"
message = [{"type": "text", "text": message}]
if image_url and config.GPT_ENGINE == "gpt-4-vision-preview":
if (image_url and config.GPT_ENGINE == "gpt-4-vision-preview") or (image_url and robot == config.GPT4visionbot):
message.append(
{
"type": "image_url",
Expand Down
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
from utils.chatgpt2api import Imagebot, claudebot
if API:
ChatGPTbot = GPT(api_key=f"{API}", engine=GPT_ENGINE, system_prompt=systemprompt, temperature=temperature)
try:
GPT4visionbot = GPT(api_key=f"{API}", engine="gpt-4-vision-preview", system_prompt=systemprompt, temperature=temperature)
except:
print("无法使用 gpt-4-vision-preview 模型")
translate_bot = GPT(api_key=f"{API}", engine=GPT_ENGINE, system_prompt=systemprompt, temperature=temperature)
dallbot = Imagebot(api_key=f"{API}")
else:
Expand Down
2 changes: 1 addition & 1 deletion utils/chatgpt2api.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def get_post_body(
"n": kwargs.get("n", self.reply_count),
"user": role,
}
if config.GPT_ENGINE != "gpt-4-vision-preview":
if self.engine != "gpt-4-vision-preview":
json_post_body.update(copy.deepcopy(body))
json_post_body.update(copy.deepcopy(function_call_list["base"]))
if config.SEARCH_USE_GPT:
Expand Down

0 comments on commit cac30e9

Please sign in to comment.