Skip to content

Commit

Permalink
Fix variable data-types mismatch at console
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Dec 21, 2023
1 parent 1ef168e commit ce4bc14
Showing 1 changed file with 48 additions and 31 deletions.
79 changes: 48 additions & 31 deletions WebChatGPT/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def do_help(self, text):
├────┼────────────────────────┼─────────────────────────────────────┤
│ 7 │ previous_conversations │ Show previous conversations │
├────┼────────────────────────┼─────────────────────────────────────┤
│ 8 │ delete_conversations │ Delete a particular conversation │
│ 8 │ delete_conversation │ Delete a particular conversation │
├────┼────────────────────────┼─────────────────────────────────────┤
│ 9 │ prompts │ Generate random prompts │
├────┼────────────────────────┼─────────────────────────────────────┤
Expand All @@ -186,6 +186,7 @@ def do_help(self, text):
├────┼────────────────────────┼─────────────────────────────────────┤
│ 16 │ exit │ Quits Program │
╘════╧════════════════════════╧═════════════════════════════════════╛
Submit any bug at : {__repo__}/issues/new
Have some fun!
Expand All @@ -202,7 +203,9 @@ def do_history(self, line):
"""Show conversation history"""
history = self.bot.chat_history(
conversation_id=click.prompt(
"Conversation ID", default=self.bot.current_conversation_id
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
)
)
formatted_chats = []
Expand All @@ -226,7 +229,9 @@ def do_history(self, line):
)
if click.confirm("Do you wish to save this"):
path = click.prompt(
"Enter path to save to", default=history.get("title") + ".json"
"Enter path to save to",
default=history.get("title") + ".json",
type=click.STRING,
)
with open(path, "w") as fh:
json.dump(
Expand All @@ -235,7 +240,7 @@ def do_history(self, line):
indent=click.prompt(
"Json Indentantion level",
default=4,
type=int,
type=click.INT,
),
)
click.secho(f"Saved successfully to `{path}`")
Expand All @@ -244,7 +249,9 @@ def do_share(self, line):
"""Share a conversation by link"""
share_info = self.bot.share_conversation(
conversation_id=click.prompt(
"Conversation ID", default=self.bot.current_conversation_id
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
),
is_anonymous=click.confirm("Is anonymous", default=True),
is_public=click.confirm("Is public", default=True),
Expand All @@ -259,19 +266,23 @@ def do_stop_share(self, line):
success_report = self.bot.stop_sharing_conversation(
self.bot.share_conversation(
conversation_id=click.prompt(
"Conversation ID", default=self.bot.current_conversation_id
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
),
).get("share_id")
)
self.output_bond("Success Report", success_report, is_json=True)

def do_rename(self, line):
"""Renames conversation title"""
new_title = click.prompt("New title", default=line)
new_title = click.prompt("New title", default=line, type=click.STRING)
if click.confirm("Are you sure to change conversation title"):
response = self.bot.rename_conversation(
conversation_id=click.prompt(
"Conversation ID", default=self.bot.current_conversation_id
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
),
title=new_title,
)
Expand All @@ -281,8 +292,10 @@ def do_rename(self, line):

def do_archive(self, line):
"""Archives or unarchive a conversation"""
conversation_id = (
click.prompt("Conversation ID", default=self.bot.current_conversation_id),
conversation_id = click.prompt(
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
)
is_archive = click.confirm(
"Is archive",
Expand All @@ -303,16 +316,18 @@ def do_shared_conversations(self, line):
def do_previous_conversations(self, line):
"""Shows previous conversations"""
previous_convos = self.bot.previous_conversations(
limit=click.prompt("Convesation limit", type=int, default=28),
offset=click.prompt("Conversation offset", type=int, default=0),
limit=click.prompt("Convesation limit", type=click.INT, default=28),
offset=click.prompt("Conversation offset", type=click.INT, default=0),
all=True,
)
self.output_bond("Previous Conversations", previous_convos, is_json=True)

def do_delete_conversations(self, line):
def do_delete_conversation(self, line):
"""Deletes a particular conversation"""
conversation_id = (
click.prompt("Conversation ID", default=self.bot.current_conversation_id),
conversation_id = click.prompt(
"Conversation ID",
default=self.bot.current_conversation_id,
type=click.STRING,
)
if click.confirm("Are you sure to delete this conversation"):
response = self.bot.delete_conversation(
Expand All @@ -323,7 +338,7 @@ def do_delete_conversations(self, line):
def do_prompts(self, line):
"""Generate random prompts"""
prompts = self.bot.prompt_library(
limit=click.prompt("Total prompts", type=int, default=4),
limit=click.prompt("Total prompts", type=click.INT, default=4),
)
self.output_bond("Random Prompts", prompts, is_json=True)

Expand All @@ -337,7 +352,9 @@ def do_account_info(self, line):
def do_ask(self, line):
"""Show raw response from ChatGPT"""
response = self.bot.ask(
prompt=line if bool(line.strip()) else click.prompt("Prompt")
prompt=line
if bool(line.strip())
else click.prompt("Prompt", type=click.STRING)
)
self.output_bond("Raw Response", response, is_json=True)

Expand All @@ -353,24 +370,24 @@ def do_migrate(self, line):
if click.confirm(
"Are you sure to shift to new conversation",
):
sort_var = lambda val: val[0] if isinstance(val, tuple) else val
self.model = (click.prompt("ChatGPT model", default=sort_var(self.model)),)
self.conversation_index = (
click.prompt(
"Conversation Index",
default=sort_var(self.conversation_index),
),
self.model = click.prompt(
"ChatGPT model", default=self.model, type=click.STRING
)
self.timeout = (
click.prompt(
"Request timeout", type=int, default=sort_var(self.timeout)
),
self.conversation_index = click.prompt(
"Conversation Index",
default=self.conversation_index,
type=click.INT,
)
self.timeout = click.prompt(
"Request timeout",
default=self.timeout,
type=click.INT,
)
self.bot = ChatGPT(
self.cookie_path,
model=sort_var(self.model),
conversation_index=sort_var(self.conversation_index),
timeout=sort_var(self.timeout),
model=self.model,
conversation_index=self.conversation_index,
timeout=self.timeout,
)

def do_exit(self, line):
Expand Down

0 comments on commit ce4bc14

Please sign in to comment.