Skip to content

Instantly share code, notes, and snippets.

@lavafrai
Created April 17, 2024 12:43
Show Gist options
  • Select an option

  • Save lavafrai/088b71ab2c30c9527c7fcf8c878a79e4 to your computer and use it in GitHub Desktop.

Select an option

Save lavafrai/088b71ab2c30c9527c7fcf8c878a79e4 to your computer and use it in GitHub Desktop.
Working on the reverse engineering of Yandex Neuro
import requests
import time
SESSION_ID = "..."
def req(endpoint, body):
resp = requests.post(
url=f"https://ya.ru{endpoint}",
headers={"Host": "ya.ru", "Content-Type": "application/json"},
json=body,
verify=True,
cookies={"Session_id": SESSION_ID}
)
return resp.json()
question = input("Ask question > ")
dialog = req("/neuralsearch/api/send_to_dialog", {"UserRequest":question})
attempts_less = dialog["ResponseStatus"]["LimitsInfo"]["SubmissionsLeft"]
responce_message_id = dialog["ResponseMessageId"]
responce_dialog_id = dialog["DialogId"]
# print(attempts_less, responce_message_id, responce_dialog_id)
for _ in range(10):
upadte = req("/neuralsearch/api/get_fresh_message", {"ResponseMessageId": responce_message_id})
if upadte["IsCompleteResults"]:
message = upadte["TargetMarkdownText"]
links = upadte["LinksData"]
print("\n\nAnswer:")
print(message)
print("\n\nLinks:")
for link in links:
print(f"{link['Num']}: {link['DocumentTitle']} ({link['FullUrl']})")
break
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment