cryogenic22 commited on
Commit
b6624e5
·
verified ·
1 Parent(s): 9364921

Update src/services/ai_service.py

Browse files
Files changed (1) hide show
  1. src/services/ai_service.py +3 -21
src/services/ai_service.py CHANGED
@@ -22,18 +22,9 @@ class AITutorService:
22
  def initialize_client(self):
23
  """Initialize Anthropic client with better error handling"""
24
  try:
25
- # First try getting API key from Streamlit secrets
26
- api_key = None
27
- if hasattr(st, 'secrets') and 'ANTHROPIC_API_KEY' in st.secrets:
28
- api_key = st.secrets['ANTHROPIC_API_KEY']
29
-
30
- # If not in secrets, try environment variable
31
- if not api_key:
32
- api_key = os.getenv('ANTHROPIC_API_KEY')
33
-
34
  if not api_key:
35
- st.error("Anthropic API key not found. Please set ANTHROPIC_API_KEY in .streamlit/secrets.toml or environment variables.")
36
- st.info("For testing, you can set this up locally by creating a .streamlit/secrets.toml file with:\nANTHROPIC_API_KEY='your-key-here'")
37
  return
38
 
39
  self._client = anthropic.Anthropic(api_key=api_key)
@@ -144,13 +135,4 @@ class AITutorService:
144
  'timestamp': datetime.now().isoformat(),
145
  'sentiment_score': min(1.0, len(user_input) / 100.0),
146
  'interaction_length': len(user_input)
147
- })
148
-
149
- def get_tutor_context() -> dict:
150
- """Get or initialize tutor context"""
151
- if 'tutor_context' not in st.session_state:
152
- st.session_state.tutor_context = {
153
- 'current_topic': None,
154
- 'chat_history': []
155
- }
156
- return st.session_state.tutor_context
 
22
  def initialize_client(self):
23
  """Initialize Anthropic client with better error handling"""
24
  try:
25
+ api_key = st.secrets.get("ANTHROPIC_API_KEY") or os.getenv('ANTHROPIC_API_KEY')
 
 
 
 
 
 
 
 
26
  if not api_key:
27
+ st.error("ANTHROPIC_API_KEY not found in secrets or environment variables")
 
28
  return
29
 
30
  self._client = anthropic.Anthropic(api_key=api_key)
 
135
  'timestamp': datetime.now().isoformat(),
136
  'sentiment_score': min(1.0, len(user_input) / 100.0),
137
  'interaction_length': len(user_input)
138
+ })