Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need hep stuck with problem for 4 weeks 😭😭😭 #110

Open
heyeanne34 opened this issue Jun 27, 2024 · 1 comment
Open

need hep stuck with problem for 4 weeks 😭😭😭 #110

heyeanne34 opened this issue Jun 27, 2024 · 1 comment

Comments

@heyeanne34
Copy link

Can i ask what would be the full code to prompt character ai through command prompt by batch using their api? 🥺🥺 what i want is to ask a question to all characters i picked and all their responses (their names included in responses so i can track them) will be in a file saved in my folderpath ive been stuck with this for 4 weeks and never figured it out 😭😭😭

@IsiraUdaththa
Copy link

I can write a Python script for that if you want. It's straightforward and easy. Using only a batch script seems unnecessary in this context as batch scripts are primarily for Windows automation.

import asyncio  
from characterai import aiocai  
  
# Configuration  
token = 'your_character_ai_token'  
character_ids = ['XD3dOm5OMlHVhdqN-PPoR9KtWKkd9Y4CzZIjYEQfaLw',   
                 '6HhWfeDjetnxESEcThlBQtEUo0O8YHcXyHqCgN7b2hY',  
                 'qtEICpGfFS8f5Zr5kCHR1EsGsHlawNutYSZJq_IEZDY']  # List of character IDs  
question = "Your question here"  
output_file_path = 'responses.txt'  
  
  
async def get_response(client, char, me_id, question):  
    async with await client.connect() as chat:  
        new, answer = await chat.new_chat(char, me_id)  
        message = await chat.send_message(char, new.chat_id, question)  
        return message.name, message.text  
  
  
async def main():  
    client = aiocai.Client(token)  
    me = await client.get_me()  
  
    responses = []  
  
    for char in character_ids:  
        try:  
            name, response_text = await get_response(client, char, me.id, question)  
            responses.append(f"Character: {name}\nResponse: {response_text}\n")  
        except Exception as e:  
            responses.append(f"Character ID: {char}\nError: {str(e)}\n")  
  
    # Save responses to file  
    with open(output_file_path, 'w', encoding='utf-8') as file:  
        file.writelines(responses)  
  
    print("Responses saved successfully.")  
  
  
asyncio.run(main())

You can use batch script to calls the Python script if you want.

@echo off 
python path\to\your\script.py 
pause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants