Write me a py script that sends a post to https://kairo-api.kys.gay/api/gpt with…
- User
user: Write me a py script that sends a post to https://kairo-api.kys.gay/api/gpt with payload: prompt: msg, model: selectedModel, cvid: id, web: (true or false), make it so it asks the user if they want to enabel web after every input, also cvid should be from the json the (conversation_id), also the ai response is "message" assistant: Certainly! Below is a Python script that accomplishes what you've described. Make sure that you have the necessary Python environment and dependencies installed, such as
requests.import json import requests def send_post_request(prompt, model, cvid, web): url = "https://kairo-api.kys.gay/api/gpt" payload = { "prompt": prompt, "model": model, "cvid": cvid, "web": web } headers = { "Content-Type": "application/json" } response = requests.post(url, headers=headers, data=json.dumps(payload)) if response.status_code == 200: return response.json().get("message", "No message key found in the response.") else: return f"Error: {response.status_code} - {response.text}" def main(): while True: # User inputs msg = input("Enter your prompt: ") selected_model = input("Enter the model name: ") # Read conversation_id from a local JSON file or any source you may have # Example JSON structure: {"conversation_id": "some_unique_id"} with open('conversation_id.json', 'r') as file: conversation_data = json.load(file) cvid = conversation_data.get("conversation_id") if not cvid: print("No conversation_id found in JSON.") continue # Ask the user if they want to enable web web_input = input("Do you want to enable web? (yes/no): ").strip().lower() web = web_input == 'yes' # Send POST request ai_response = send_post_request(msg, selected_model, cvid, web) print("AI Response:", ai_response) # Continue or exit cont = input("Do you want to send another message? (yes/no): ").strip().lower() if cont != 'yes': break if __name__ == '__main__': main()Running the Script
- Dependencies: Make sure you have
requestsinstalled. You can install it using pip:pip install requests - Setup: Ensure the
conversation_id.jsonexists and contains a valid JSON structure, for example:{ "conversation_id": "12345" } - Execution: Run the script in your Python environment.
This script will continuously prompt the user for inputs, send them to the specified API, and display the AI's response until the user decides to quit. user: make it use httpx assistant: Certainly! Below is the updated Python script using
httpxfor making HTTP requests. Make sure to install thehttpxlibrary in your Python environment before running the script.import json import httpx def send_post_request(prompt, model, cvid, web): url = "https://kairo-api.kys.gay/api/gpt" payload = { "prompt": prompt, "model": model, "cvid": cvid, "web": web } headers = { "Content-Type": "application/json" } try: response = httpx.post(url, headers=headers, json=payload) response.raise_for_status() return response.json().get("message", "No message key found in the response.") except httpx.HTTPStatusError as e: return f"Error: {e.response.status_code} - {e.response.text}" except Exception as e: return f"An error occurred: {str(e)}" def main(): while True: # User inputs msg = input("Enter your prompt: ") selected_model = input("Enter the model name: ") # Read conversation_id from a local JSON file with open('conversation_id.json', 'r') as file: conversation_data = json.load(file) cvid = conversation_data.get("conversation_id") if not cvid: print("No conversation_id found in JSON.") continue # Ask the user if they want to enable web web_input = input("Do you want to enable web? (yes/no): ").strip().lower() web = web_input == 'yes' # Send POST request ai_response = send_post_request(msg, selected_model, cvid, web) print("AI Response:", ai_response) # Continue or exit cont = input("Do you want to send another message? (yes/no): ").strip().lower() if cont != 'yes': break if __name__ == '__main__': main()Running the Script
- Dependencies: Make sure you have
httpxinstalled. You can install it using pip:pip install httpx - Setup: Ensure the
conversation_id.jsonfile exists and contains a valid JSON structure, for example:{ "conversation_id": "12345" } - Execution: Run the script in your Python environment.
This script will interactively prompt the user for inputs, send them to the specified API, and display the AI's response until the user decides to quit. user: it should not read conversation_id from a file, i tshould read it from the response json PROMPT: user: Write me a py script that sends a post to https://kairo-api.kys.gay/api/gpt with payload: prompt: msg, model: selectedModel, cvid: id, web: (true or false), make it so it asks the user if they want to enabel web after every input, also cvid should be from the json the (conversation_id), also the ai response is "message" assistant: Certainly! Below is a Python script that accomplishes what you've described. Make sure that you have the necessary Python environment and dependencies installed, such as
requests.import json import requests def send_post_request(prompt, model, cvid, web): url = "https://kairo-api.kys.gay/api/gpt" payload = { "prompt": prompt, "model": model, "cvid": cvid, "web": web } headers = { "Content-Type": "application/json" } response = requests.post(url, headers=headers, data=json.dumps(payload)) if response.status_code == 200: return response.json().get("message", "No message key found in the response.") else: return f"Error: {response.status_code} - {response.text}" def main(): while True: # User inputs msg = input("Enter your prompt: ") selected_model = input("Enter the model name: ") # Read conversation_id from a local JSON file or any source you may have # Example JSON structure: {"conversation_id": "some_unique_id"} with open('conversation_id.json', 'r') as file: conversation_data = json.load(file) cvid = conversation_data.get("conversation_id") if not cvid: print("No conversation_id found in JSON.") continue # Ask the user if they want to enable web web_input = input("Do you want to enable web? (yes/no): ").strip().lower() web = web_input == 'yes' # Send POST request ai_response = send_post_request(msg, selected_model, cvid, web) print("AI Response:", ai_response) # Continue or exit cont = input("Do you want to send another message? (yes/no): ").strip().lower() if cont != 'yes': break if __name__ == '__main__': main()Running the Script
- Dependencies: Make sure you have
requestsinstalled. You can install it using pip:pip install requests - Setup: Ensure the
conversation_id.jsonexists and contains a valid JSON structure, for example:{ "conversation_id": "12345" } - Execution: Run the script in your Python environment.
This script will continuously prompt the user for inputs, send them to the specified API, and display the AI's response until the user decides to quit. user: make it use httpx assistant: Certainly! Below is the updated Python script using
httpxfor making HTTP requests. Make sure to install thehttpxlibrary in your Python environment before running the script.import json import httpx def send_post_request(prompt, model, cvid, web): url = "https://kairo-api.kys.gay/api/gpt" payload = { "prompt": prompt, "model": model, "cvid": cvid, "web": web } headers = { "Content-Type": "application/json" } try: response = httpx.post(url, headers=headers, json=payload) response.raise_for_status() return response.json().get("message", "No message key found in the response.") except httpx.HTTPStatusError as e: return f"Error: {e.response.status_code} - {e.response.text}" except Exception as e: return f"An error occurred: {str(e)}" def main(): while True: # User inputs msg = input("Enter your prompt: ") selected_model = input("Enter the model name: ") # Read conversation_id from a local JSON file with open('conversation_id.json', 'r') as file: conversation_data = json.load(file) cvid = conversation_data.get("conversation_id") if not cvid: print("No conversation_id found in JSON.") continue # Ask the user if they want to enable web web_input = input("Do you want to enable web? (yes/no): ").strip().lower() web = web_input == 'yes' # Send POST request ai_response = send_post_request(msg, selected_model, cvid, web) print("AI Response:", ai_response) # Continue or exit cont = input("Do you want to send another message? (yes/no): ").strip().lower() if cont != 'yes': break if __name__ == '__main__': main()Running the Script
- Dependencies: Make sure you have
httpxinstalled. You can install it using pip:pip install httpx - Setup: Ensure the
conversation_id.jsonfile exists and contains a valid JSON structure, for example:{ "conversation_id": "12345" } - Execution: Run the script in your Python environment.
This script will interactively prompt the user for inputs, send them to the specified API, and display the AI's response until the user decides to quit. user: it should not read conversation_id from a file, i tshould read it from the response json
- Dependencies: Make sure you have
- Assistant
Certainly! Below is a Python script using
httpxwhere the conversation ID (cvid) is dynamically obtained from the JSON response of the API. This script will store and reuse the conversation ID from the response for subsequent requests.import httpx def send_post_request(prompt, model, cvid, web): url = "https://kairo-api.kys.gay/api/gpt" payload = { "prompt": prompt, "model": model, "cvid": cvid, "web": web } headers = { "Content-Type": "application/json" } try: response = httpx.post(url, headers=headers, json=payload) response.raise_for_status() response_json = response.json() message = response_json.get("message", "No message key found in the response.") conversation_id = response_json.get("conversation_id", cvid) return message, conversation_id except httpx.HTTPStatusError as e: return f"Error: {e.response.status_code} - {e.response.text}", cvid except Exception as e: return f"An error occurred: {str(e)}", cvid def main(): conversation_id = None while True: # User inputs msg = input("Enter your prompt: ") selected_model = input("Enter the model name: ") # Ask the user if they want to enable web web_input = input("Do you want to enable web? (yes/no): ").strip().lower() web = web_input == 'yes' # Send POST request ai_response, conversation_id = send_post_request(msg, selected_model, conversation_id, web) print("AI Response:", ai_response) # Continue or exit cont = input("Do you want to send another message? (yes/no): ").strip().lower() if cont != 'yes': break if __name__ == '__main__': main()Running the Script
- Dependencies: Make sure you have
httpxinstalled. You can install it using pip:pip install httpx - Execution: Run the script in your Python environment.
The script initiates a session with the API and uses the
conversation_idfetched from the response after the first request to maintain continuity in the conversation. The script will repeatedly prompt the user for inputs and send them to the specified API until the user decides to quit. - Dependencies: Make sure you have