Skip to content

d60/twikit_grok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twikit_grok

Extension for using Grok with Twikit.

Installing

pip install twikit_grok

Quick Example

Streaming

import asyncio
from twikit_grok import Client

USERNAME = 'example_user'
EMAIL = '[email protected]'
PASSWORD = 'password0000'

client = Client('en-US')

async def main():
    # Login to an account
    if os.path.exists('cookies.json'):
        client.load_cookies('cookies.json')
    else:
        await client.login(
            auth_info_1=USERNAME,
            auth_info_2=EMAIL,
            password=PASSWORD
        )
        client.save_cookies('cookies.json')

    # Create a new conversation
    conversation = await client.create_grok_conversation()
    # Generate a response
    async for chunk in conversation.stream('hello'):
        print(chunk)

    # Generate a response with images
    attachments = [
        await client.upload_grok_attachment('image1.jpg'),
        await client.upload_grok_attachment('image2.jpg')
    ]
    async for chunk in conversation.stream('please describe these images', attachments):
        print(chunk)


    # Continue from an existing conversation
    conversation = await client.get_grok_conversation('123456789')  # Get conversation by ID
    async for chunk in conversation.stream('hello'):
        print(chunk)

asyncio.run(main())

Non Streaming

conversation = await client.create_grok_conversation()
content = await conversation.generate('generate images of cats.')
await content.attachments[0].download('image.jpg')

content2 = await conversation.generate('hello')
print(content2.message)

About

Extension for using Grok with Twikit

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages