Update codette_agent.py
Browse files- codette_agent.py +10 -3
codette_agent.py
CHANGED
|
@@ -7,6 +7,7 @@ import aiohttp
|
|
| 7 |
from typing import List, Dict, Any
|
| 8 |
from cryptography.fernet import Fernet
|
| 9 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
|
|
| 10 |
import speech_recognition as sr
|
| 11 |
from PIL import Image
|
| 12 |
|
|
@@ -21,7 +22,7 @@ class CodetteAgent:
|
|
| 21 |
def __init__(self, config):
|
| 22 |
self.config = config
|
| 23 |
self.perspectives = self._init_perspectives()
|
| 24 |
-
self.
|
| 25 |
self.memory = sqlite3.connect(":memory:")
|
| 26 |
self.memory.execute("CREATE TABLE IF NOT EXISTS codette_memory (input TEXT, response TEXT)")
|
| 27 |
self.elements = self._init_elements()
|
|
@@ -53,7 +54,6 @@ class CodetteAgent:
|
|
| 53 |
|
| 54 |
async def generate_response(self, prompt: str) -> str:
|
| 55 |
self.history.append(prompt)
|
| 56 |
-
sentiment = self.sentiment_analyzer.polarity_scores(prompt)
|
| 57 |
responses = []
|
| 58 |
|
| 59 |
for p in self.perspectives:
|
|
@@ -63,7 +63,14 @@ class CodetteAgent:
|
|
| 63 |
except Exception as e:
|
| 64 |
logging.warning(f"{p.__class__.__name__} failed: {e}")
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
final = "\n\n".join(responses)
|
| 68 |
self.memory.execute("INSERT INTO codette_memory VALUES (?, ?)", (prompt, final))
|
| 69 |
self.memory.commit()
|
|
|
|
| 7 |
from typing import List, Dict, Any
|
| 8 |
from cryptography.fernet import Fernet
|
| 9 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
| 10 |
+
from textblob import TextBlob
|
| 11 |
import speech_recognition as sr
|
| 12 |
from PIL import Image
|
| 13 |
|
|
|
|
| 22 |
def __init__(self, config):
|
| 23 |
self.config = config
|
| 24 |
self.perspectives = self._init_perspectives()
|
| 25 |
+
self.vader = SentimentIntensityAnalyzer()
|
| 26 |
self.memory = sqlite3.connect(":memory:")
|
| 27 |
self.memory.execute("CREATE TABLE IF NOT EXISTS codette_memory (input TEXT, response TEXT)")
|
| 28 |
self.elements = self._init_elements()
|
|
|
|
| 54 |
|
| 55 |
async def generate_response(self, prompt: str) -> str:
|
| 56 |
self.history.append(prompt)
|
|
|
|
| 57 |
responses = []
|
| 58 |
|
| 59 |
for p in self.perspectives:
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
logging.warning(f"{p.__class__.__name__} failed: {e}")
|
| 65 |
|
| 66 |
+
# Sentiment analysis (dual engine)
|
| 67 |
+
vader_score = self.vader.polarity_scores(prompt)["compound"]
|
| 68 |
+
blob = TextBlob(prompt)
|
| 69 |
+
blob_polarity = blob.sentiment.polarity
|
| 70 |
+
blob_subjectivity = blob.sentiment.subjectivity
|
| 71 |
+
|
| 72 |
+
responses.append(f"[VADER: {vader_score:+.2f} | TextBlob: polarity={blob_polarity:+.2f}, subjectivity={blob_subjectivity:.2f}]")
|
| 73 |
+
|
| 74 |
final = "\n\n".join(responses)
|
| 75 |
self.memory.execute("INSERT INTO codette_memory VALUES (?, ?)", (prompt, final))
|
| 76 |
self.memory.commit()
|