Sentiment Classifier using Anthropic Claude API or Open AI This repository contains a Python script that classifies the sentiment of text as either positive or negative using Anthropic's Claude language model or Opeo AI. The script allows you to input a piece of text, which is then analyzed by the model, returning a sentiment classification.
Features Sentiment Classification: The model analyzes input text and classifies it as either 'positive' or 'negative.' Command-line Interface: Simple CLI to input text for classification. Anthropic API Integration: Utilizes the Claude language model for natural language understanding and sentiment analysis. Prerequisites Before running the script, make sure you have the following:
Python 3.7 or higher Anthropic API key (replace your_anthropic_api_key_here with your actual key) Installation Clone the repository:
bash Copy code git clone https://github.com/yourusername/sentiment-classifier.git cd sentiment-classifier Install the required dependencies:
bash pip install anthropic argparse Set up your Anthropic API key by replacing the placeholder in the code with your actual key:
python client = anthropic.Client(api_key='your_anthropic_api_key_here') Usage To classify the sentiment of a piece of text, run the following command:
bash python sentiment_classifier.py "Your text to classify here" For example:
bash python sentiment_classifier.py "This is an amazing day!" This will output:
Copy code positive Code Structure create_prompt(text): Prepares the input prompt for the language model with the text to classify. call_llm(prompt): Sends the prompt to Anthropic's Claude model and retrieves the response. argparse: Command-line argument parsing to handle user input.