##################### # Scayle Chat API Client # This script allows users to interact with the Scayle Chat API. ##### IMPORTANT ##### # - Run in the console previously to execute the script -> unset https_proxy ##################### import requests ##################### print("\nWelcome to the Scayle Chat API Client!") print("\nBefore you start, please ensure you have done the following:") print("\nUnset the https_proxy environment variable, if not write in your console : unset https_proxy") print("\nHave you done it? (yes/no)") response = input().strip().lower() if response != 'yes': print("Please unset the https_proxy environment variable and try again.") exit() print("\nGreat! Let's proceed with the Scayle Chat API Client setup.") ##################### SCAYLE_USERNAME = input("\nEnter your Scayle username: ") SCAYLE_PASSWORD = input("Enter your Scayle password: ") ##################### # Function to get the authentication token def get_token(): url = 'https://chat.scayle.es/api/v1/auths/ldap' headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' } data = { "user": SCAYLE_USERNAME, "password": SCAYLE_PASSWORD } response = requests.post(url, headers=headers, json=data) if response.status_code != 200: print("\nFailed to authenticate. Please check your credentials and try again.") exit() return response.json()["token"] token = get_token() # Function to get the list of available models def get_models(token): url = 'https://chat.scayle.es/api/models' headers = { 'Authorization': f'Bearer {token}' } response = requests.get(url, headers=headers) return [model["id"] for model in response.json()["data"]] models = get_models(token) # Select the model to use if not models: print("\nNo models available. Leaving the script.") exit() print("\nAvailable models:") for i, model in enumerate(models): print(f"{i + 1}: {model}") input_choice = input("\nEnter the number of the model you want to use:") if not input_choice.isdigit() or int(input_choice) < 1 or int(input_choice) > len(models): print("\nInvalid choice. Please run the script again and select a valid model.") exit() print(f"\nSelected model: {models[int(input_choice) - 1]}") # Function to send a message to the model def send_message(token, model, message): url = 'https://chat.scayle.es/api/chat/completions' headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json' } data = { "model": model, "messages": [ { "role": "user", "content": message } ] } response = requests.post(url, headers=headers, json=data) return response.json() # Main loop to interact with the model while True: user_input = input("\nEnter your message (or 'exit' to quit): ") if user_input.lower() == 'exit': break response = send_message(token, model, user_input) print(f"Response from model: {response['choices'][0]['message']['content']}") # End of script