Skip to content

Commit

Permalink
fixed: character loss issue
Browse files Browse the repository at this point in the history
chore: remove tests
  • Loading branch information
xingty committed Apr 20, 2024
1 parent 4790b7c commit d2274c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 48 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/tests.yml

This file was deleted.

26 changes: 11 additions & 15 deletions src/EdgeGPT/chathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ async def ask_stream(
await wss.asend(append_identifier(self.request.struct).encode("utf-8"))
resp_txt = ""
generate = None
new_line = "\n"
search_hint = "Searching the web for:\n"
search_refs = []
search_keywords = ""
offset = 0
search_keywords = []
async for obj in self._receive_messages(wss):
if int(time()) % 6 == 0:
await wss.asend(append_identifier({"type": 6}).encode("utf-8"))
Expand Down Expand Up @@ -170,8 +167,7 @@ async def ask_stream(
hidden_text = message.get("hiddenText")
text = message.get("text")
if msg_type == "InternalSearchQuery":
search_keywords = f"{search_keywords}\n{search_hint}{hidden_text}\n"
resp_txt = search_keywords
search_keywords.append(hidden_text)
elif msg_type == "InternalSearchResult":
search_refs += parse_search_result(message)
elif msg_type == "GenerateContentQuery":
Expand All @@ -183,15 +179,14 @@ async def ask_stream(
if message.get("contentOrigin") == "Apology":
print('message has been revoked')
print(message)
result = f"{message.get('text')} -end- (message has been revoked)"
resp_txt = f"{resp_txt}\n{result}"
resp_txt = f"{resp_txt}{text} -end- (message has been revoked)"

text = new_line + text
resp_txt = f"{resp_txt}{text[offset:]}"
offset = len(text)
new_line = ""
if len(search_keywords) > 0:
keywords = "\n* ".join(search_keywords)
resp_txt = f"{resp_txt}Searching the web for:\n* {keywords}\n\n"
search_keywords = []

yield False, resp_txt
yield False, f"{resp_txt}{text}"
elif response.get("type") == 2:
if response["item"]["result"].get("error"):
raise Exception(
Expand All @@ -200,6 +195,7 @@ async def ask_stream(

response["media"] = {}
message = response["item"]["messages"][-1]
text = message.get("text")
if generate:
if generate["content_type"] == "IMAGE":
async with ImageGenAsync(
Expand All @@ -215,14 +211,14 @@ async def ask_stream(
except Exception as e:
print(str(e))
hint = "Your prompt has been prohibited by third-service. Please modify it."
resp_txt = f"{resp_txt}\n{e}\n{hint}"
resp_txt = f"{resp_txt}{text}\n{e}\n{hint}"

if len(search_refs) > 0:
refs_str = ""
for index, item in enumerate(search_refs):
refs_str += f'- [^{index}^] [{item["title"]}]({item["url"]})\n'

resp_txt = f"{resp_txt}\n{refs_str}"
resp_txt = f"{resp_txt}{text}\n{refs_str}"

message["text"] = resp_txt
if "media" not in response:
Expand Down
1 change: 0 additions & 1 deletion src/EdgeGPT/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(
client_id: str,
conversation_id: str,
invocation_id: int = 3,
sec_access_token: str = None,
) -> None:
self.struct: dict = {}

Expand Down

0 comments on commit d2274c5

Please sign in to comment.