Skip to content

Commit

Permalink
1. Fix the issue of failure to switch models when not using the offic…
Browse files Browse the repository at this point in the history
…ial Claude model and attempting to switch to the Claude model.

2. Fix function call equals None value when passed into the conversation history.
  • Loading branch information
yym68686 committed Dec 10, 2023
1 parent 68aed39 commit 7255f87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def delete_message(update, context, messageid, delay=10):
# InlineKeyboardButton("gpt-4-32k-0613", callback_data="gpt-4-32k-0613"),
# ],
[
InlineKeyboardButton("claude-2.1", callback_data="claude-2.1"),
InlineKeyboardButton("claude-2", callback_data="claude-2"),
InlineKeyboardButton("claude-2-web", callback_data="claude-2-web"),
],
[
Expand Down Expand Up @@ -341,7 +341,7 @@ async def button_press(update, context):
data = callback_query.data
if "gpt-" in data or "claude" in data:
config.GPT_ENGINE = data
if config.API and "gpt-" in data:
if (config.API and "gpt-" in data) or (config.API and not config.ClaudeAPI):
config.ChatGPTbot = GPT(api_key=f"{config.API}", engine=config.GPT_ENGINE, system_prompt=config.systemprompt, temperature=config.temperature)
config.ChatGPTbot.reset(convo_id=str(update.effective_chat.id), system_prompt=config.systemprompt)
if config.ClaudeAPI and "claude" in data:
Expand Down
2 changes: 1 addition & 1 deletion test/test_claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class claudebot:
def __init__(
self,
api_key: str,
engine: str = os.environ.get("GPT_ENGINE") or "claude-2.1",
engine: str = os.environ.get("GPT_ENGINE") or "claude-2",
temperature: float = 0.5,
top_p: float = 0.7,
chat_url: str = "https://api.anthropic.com/v1/complete",
Expand Down
12 changes: 8 additions & 4 deletions utils/chatgpt2api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_filtered_keys_from_object(obj: object, *keys: str) -> Set[str]:
"gpt-4-32k-0613",
"gpt-4-1106-preview",
"claude-2-web",
"claude-2.1",
"claude-2",
]

class claudeConversation(dict):
Expand All @@ -63,7 +63,7 @@ class claudebot:
def __init__(
self,
api_key: str,
engine: str = os.environ.get("GPT_ENGINE") or "claude-2.1",
engine: str = os.environ.get("GPT_ENGINE") or "claude-2",
temperature: float = 0.5,
top_p: float = 0.7,
chat_url: str = "https://api.anthropic.com/v1/complete",
Expand Down Expand Up @@ -353,10 +353,14 @@ def add_to_conversation(
"""
if convo_id not in self.conversation:
self.reset(convo_id=convo_id)
if function_name == "" and message != "":
if function_name == "" and message != "" and message != None:
self.conversation[convo_id].append({"role": role, "content": message})
else:
elif function_name != "" and message != "" and message != None:
self.conversation[convo_id].append({"role": role, "name": function_name, "content": message})
else:
print('\033[31m')
print("error: add_to_conversation message is None or empty")
print('\033[0m')

def __truncate_conversation(self, convo_id: str = "default") -> None:
"""
Expand Down

0 comments on commit 7255f87

Please sign in to comment.