You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importasynciofromtwikit_grokimportClientUSERNAME='example_user'EMAIL='email@example.com'PASSWORD='password0000'client=Client('en-US')
asyncdefmain():
# Login to an accountifos.path.exists('cookies.json'):
client.load_cookies('cookies.json')
else:
awaitclient.login(
auth_info_1=USERNAME,
auth_info_2=EMAIL,
password=PASSWORD
)
client.save_cookies('cookies.json')
# Create a new conversationconversation=awaitclient.create_grok_conversation()
# Generate a responseasyncforchunkinconversation.stream('hello'):
print(chunk)
# Generate a response with imagesattachments= [
awaitclient.upload_grok_attachment('image1.jpg'),
awaitclient.upload_grok_attachment('image2.jpg')
]
asyncforchunkinconversation.stream('please describe these images', attachments):
print(chunk)
# Continue from an existing conversationconversation=awaitclient.get_grok_conversation('123456789') # Get conversation by IDasyncforchunkinconversation.stream('hello'):
print(chunk)
asyncio.run(main())
Non Streaming
conversation=awaitclient.create_grok_conversation()
content=awaitconversation.generate('generate images of cats.')
awaitcontent.attachments[0].download('image.jpg')
content2=awaitconversation.generate('hello')
print(content2.message)