Skip to content

Commit

Permalink
fix no response when no_search is enabled, addressing juzeon#76
Browse files Browse the repository at this point in the history
  • Loading branch information
juzeon committed Aug 5, 2023
1 parent e982436 commit 84b8187
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 7,4 @@ test.py
assets/test.html
saves
cookies*.json
struct.json
23 changes: 22 additions & 1 deletion sydney.py
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
import base64
import json
import os
import pathlib
import random
import urllib.request
import uuid
Expand Down Expand Up @@ -264,6 265,7 @@ async def ask_stream(
conversation_id = conversation["conversationId"]
client_id = conversation["clientId"]
conversation_signature = conversation["conversationSignature"]
message_id = str(uuid.uuid4())

async with session.ws_connect(
wss_url,
Expand All @@ -276,7 278,7 @@ async def ask_stream(
await wss.send_str(_format({"type": 6}))
option_sets = getattr(_OptionSets, conversation_style.upper()).value.copy()
if no_search:
option_sets.append("nosearch")
prompt = prompt ' #no_search'

struct = {
'arguments': [
Expand All @@ -285,7 287,10 @@ async def ask_stream(
'source': 'cib',
'allowedMessageTypes': _ALLOWED_MESSAGE_TYPES,
'sliceIds': _SLICE_IDS,
"verbosity": "verbose",
"scenario": "SERP",
'traceId': os.urandom(16).hex(),
'requestId': message_id,
'isStartOfSession': True,
'message': {
"locale": locale,
Expand All @@ -296,19 301,24 @@ async def ask_stream(
"inputMethod": "Keyboard",
"text": prompt,
"messageType": random.choice(["Chat", "SearchQuery"]),
"requestId": message_id,
"messageId": message_id,
"imageUrl": image_url or None,
},
"tone": conversation_style.capitalize(),
'conversationSignature': conversation_signature,
'participant': {
'id': client_id
},
"spokenTextMode": "None",
'conversationId': conversation_id,
'previousMessages': [
{
"author": "user",
"description": context,
"contextType": "WebPage",
"messageType": "Context",
"messageId": "discover-web--page-ping-mriduna-----",
},
]
}
Expand All @@ -318,6 328,17 @@ async def ask_stream(
'type': 4
}

# struct = json.loads(pathlib.Path('struct.json').read_text())
# struct['arguments'][0]['optionsSets'] = option_sets
# struct['arguments'][0]['sliceIds'] = _SLICE_IDS
# struct['arguments'][0]['traceId'] = struct1['arguments'][0]['traceId']
# struct['arguments'][0]['requestId'] = message_id
# struct['arguments'][0]['message']['requestId'] = message_id
# struct['arguments'][0]['message']['messageId'] = message_id
# struct['arguments'][0]['conversationSignature'] = conversation_signature
# struct['arguments'][0]['conversationId'] = conversation_id
# struct['arguments'][0]['previousMessages'] = struct1['arguments'][0]['previousMessages']

await wss.send_str(_format(struct))
print(f'Sent:\n{json.dumps(struct)}')

Expand Down

0 comments on commit 84b8187

Please sign in to comment.