Skip to content

Latest commit

 

History

History
107 lines (83 loc) · 4.85 KB

README.md

File metadata and controls

107 lines (83 loc) · 4.85 KB

NeurOllama AI

Ollama 3.2 - AI Chat with Memories and Sentiment Analysis

Powered by Ollama License GitHub Issues GitHub Last Commit GitHub Forks GitHub Stars

NeuroLlama AI

This Python script enables an interactive chat with an AI that adjusts its responses based on the sentiment of the user's input. It uses text-to-speech (TTS) to speak the AI's responses and maintains conversation history in a file for continuity. The conversation history is saved, allowing the AI to recall memories from previous sessions and maintain context across interactions. The AI's responses are generated using Ollama 3.2, and sentiment analysis is performed with TextBlob to gauge the emotional tone of user input, allowing the AI to respond appropriately to frustration or positivity.

Table of Contents

Features

  • Text-to-Speech: The AI's responses are read aloud using pyttsx3.
  • Conversation History: The script keeps track of the last few exchanges for more context in responses.
  • Sentiment Analysis: User input is analyzed for sentiment to guide the AI's tone in replies.
  • File Persistence: Conversation history is saved to and loaded from a JSON file (conversation_history.json).
  • Customizable Configuration: Configuration options like voice selection, interaction memory size, and timeout duration can be set in a config.json file.

Requirements

  • Python 3.x
  • Required Python libraries:
    • pyttsx3
    • subprocess
    • json
    • textblob

You can install the necessary dependencies by running:

pip install pyttsx3 textblob

Configuration

The script loads configuration from a config.json file. If the file is not found, default settings are used. The configuration file can specify the following settings:

{
    "voice": "com.apple.voice.compact.en-US.Samantha",
    "history_file": "conversation_history.json",
    "interaction_memory": 10,
    "timeout": 30
}
  • voice: The voice to use for text-to-speech (default: com.apple.voice.compact.en-US.Samantha).
  • history_file: The file where conversation history is saved (default: conversation_history.json).
  • interaction_memory: The number of past exchanges the AI remembers to use as context (default: 10).
  • timeout: Time in seconds to wait before considering the conversation as timed out (default: 30).

How It Works

  1. Initialization: The script initializes the TTS engine (pyttsx3) and loads the configuration and conversation history.
  2. Chat Loop:
    • The script prompts the user for input.
    • It analyzes the sentiment of the input using TextBlob.
    • If the sentiment is negative, the AI offers a reassuring response. If positive, the AI responds with encouragement. Otherwise, it generates a normal response using Ollama 3.2.
    • The conversation history is updated and saved after every interaction.
    • The AI’s response is printed to the console and spoken aloud using TTS.
  3. Exit: The conversation can be ended by typing exit.

Example

Chat with AI. Type 'exit' to end the conversation.

You: Hello, AI!
AI: I'm glad to hear your positivity! Let's continue.
You: I'm frustrated with this project.
AI: I sense some frustration. I'm here to assist you.
You: exit

Notes

  • Ollama: This script assumes you have the ollama CLI tool installed and accessible from the terminal. The AI’s responses are generated by running ollama run llama3.2. You can download Ollama from here.
  • TextBlob: The sentiment analysis uses TextBlob’s polarity, with values ranging from -1 (negative) to 1 (positive).

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This script is open-source and has an MIT license. Feel free to use and modify it for your personal or professional projects.

GitHub Repository Visit Counter