import os import requests from dotenv import load_dotenv def main(): # 1. Load the environment file with your API key home_dir = os.path.expanduser("~") env_file = os.path.join(home_dir, ".secretlab.env") load_dotenv(env_file) api_key = os.getenv("SECRETLAB_API_KEY") if not api_key: raise ValueError("SECRETLAB_API_KEY not found in ~/.secretlab.env") # 2. The correct endpoint url = "https://chat.secretlab.page/api/chat/completions" # 3. Sentences to classify sentences = [ "I love sunny days!", "This is a bland sandwich.", "I really hate waiting in long lines.", "The meeting was okay, nothing special.", "I am so excited about the upcoming holidays!" ] # 4. For each sentence, send a separate request for index, sentence in enumerate(sentences, start=1): # Prepare the request payload # We use Chat Completion format, but the system message strictly instructs the assistant # to return only "Positive" or "Negative" with no extra explanation. payload = { "model": "deepseek-r1:32b", "messages": [ { "role": "system", "content": ( "You are a helpful text classifier. You must respond with only " "'Positive' or 'Negative' for the given text. No other words or punctuation." ) }, { "role": "user", "content": f"Classify this sentence as Positive or Negative:\n{sentence}" } ], "temperature": 0.0 } # Set the headers, including authorization headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } # POST the request response = requests.post(url, headers=headers, json=payload) # Check for success if response.status_code == 200: completion = response.json() # Extract the assistant's response text result_text = completion["choices"][0]["message"]["content"].strip() # Print the classification result for each sentence print(f"Sentence {index}: {sentence}") print(f"Classification: {result_text}") print("---------") else: print(f"Request for sentence {index} failed with status code: {response.status_code}") print("Response:", response.text) print("---------") if __name__ == "__main__": main()