Skip to content

Commit

Permalink
fix variable referenced before assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Cheong committed Feb 21, 2023
1 parent 9d50d16 commit 19d8edf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/revChatGPT/V1.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def ask(
stream=True,
)
self.__check_response(response)
if response.text == 'Internal Server Error':
raise Exception("Error: " + str(line))
for line in response.iter_lines():
line = str(line)[2:-1]
if line == "Internal Server Error":
raise Exception("Error: " + str(line))
if line == "" or line is None:
continue
if "data: " in line:
Expand All @@ -191,7 +191,7 @@ def ask(
continue
if not self.__check_fields(line):
raise Exception("Field missing. Details: " + str(line))

message = line["message"]["content"]["parts"][0]
conversation_id = line["conversation_id"]
parent_id = line["message"]["id"]
Expand Down Expand Up @@ -236,17 +236,17 @@ def get_conversations(self, offset=0, limit=20):
data = json.loads(response.text)
return data["items"]

def get_msg_history(self, convo_id, encoding = "utf-8"):
def get_msg_history(self, convo_id, encoding="utf-8"):
"""
Get message history
:param id: UUID of conversation
"""
url = BASE_URL + f"api/conversation/{convo_id}"
response = self.session.get(url)
if encoding != None:
response.encoding = encoding
response.encoding = encoding
else:
response.encoding = response.apparent_encoding
response.encoding = response.apparent_encoding
self.__check_response(response)
data = json.loads(response.text)
return data
Expand Down Expand Up @@ -401,7 +401,9 @@ def handle_commands(command: str) -> bool:
print(f"Rolled back {rollback} messages.")
elif command.startswith("!setconversation"):
try:
chatbot.conversation_id = chatbot.config["conversation_id"] = command.split(" ")[1]
chatbot.conversation_id = chatbot.config[
"conversation_id"
] = command.split(" ")[1]
print("Conversation has been changed")
except IndexError:
print("Please include conversation UUID in command")
Expand Down

0 comments on commit 19d8edf

Please sign in to comment.