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.pythonimport 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() - Assistant
Certainly! Below is the updated Python script using
httpxfor making HTTP requests. Make sure to install the library in your Python environment before running the script.