|
|
||
|---|---|---|
| README.md | ||
| viola.py | ||
README.md
Reverse API for Voila Chat
This Python script provides a reverse API for interacting with the Voila chat API. It allows you to send messages to the Voila chat API and receive the response in a streaming format.
Prerequisites
- Python 3.x
requestslibrary
Installation
- Install the required library:
pip install requests
Usage
- Set the API endpoint URL:
API_ENDPOINT = "https://chat.getvoila.ai/api/v1/prompts/chat"
- Generate UUIDs for the conversation and user:
conversation_id = str(uuid4())
user_uuid = str(uuid4())
- Set the provided details in the
payloaddictionary:
payload = {
"chat": [
{
"role": "user",
"content": "hello", # Change this to the message you want to send
"intent": None
}
],
"email": "Your Email Address for your Voila account",
"model": "gpt-4", # Change this to the model you want to use
"auth_token": "Enter your Auth Token from request headers using the extension/addon",
"context": "",
"conversation": conversation_id,
"user_uuid": user_uuid,
"version": "1.5.4" # Change this to the version of the extension/addon you are using
}
- Set the cookie values:
ph_phc_val = "Enter your Cookie Name for your php_phc cookie"
posthog_val = "Enter your Cookie Value for your php_phc cookie"
ahoy_visitor = "Enter your Cookie Value"
ahoy_visit = "Enter your Cookie Value"
- Set the request headers:
headers = {
"Content-Type": "application/json",
"accept": "text/event-stream",
"accept-language": "en-US,en;q=0.9",
"cookie": f"{ph_phc_val}={posthog_val}; ahoy_visitor={ahoy_visitor}; ahoy_visit={ahoy_visit}",
"origin": "chrome-extension://cakobppopkpmmglabcdcklncbckjpkcl", # Change this to the origin of the extension/addon you are using this might be different in upcoming versions
"priority": "u=1, i",
"sec-ch-ua": '"Chromium";v="124", "Brave";v="124", "Not-A.Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Linux"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"sec-gpc": "1",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
}
- Send the request to the API:
with requests.Session() as session:
try:
response = session.post(API_ENDPOINT, data=json.dumps(payload), headers=headers, stream=True)
for line in response.iter_lines():
if line:
print(line.decode())
except ChunkedEncodingError:
print("Streaming response ended.")
Notes
- You'll need to grab the cookie values from your Voila account at https://www.getvoila.ai/account and enter them accordingly.
- You'll need to grab your auth token when you send a request in the Chrome extension or Firefox addon, and enter that value in the
auth_tokenfield. - The
originfield in the headers might need to be changed if you're using a different extension/addon. - The
versionfield in thepayloadshould be updated to match the version of the extension/addon you're using.