GoodLuckChuck commited on
Commit
ac8dee4
·
verified ·
1 Parent(s): b5cd157

updated with HF Space Secrets

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -11,7 +11,6 @@ import logging
11
  import operator
12
  import aiohttp
13
  from typing import Optional, Dict, Any, List, Union
14
- from dotenv import load_dotenv
15
 
16
  # Import necessary components from smolagents
17
  try:
@@ -86,12 +85,12 @@ class WebSearchTool(Tool):
86
  output_type = "string"
87
 
88
  async def forward(self, query: str) -> str:
89
- if not os.getenv('SERPER_API_KEY'):
90
  return "Error: Serper API key not found"
91
 
92
  url = "https://google.serper.dev/search"
93
  headers = {
94
- 'X-API-KEY': os.getenv('SERPER_API_KEY'),
95
  'Content-Type': 'application/json'
96
  }
97
  payload = {
@@ -276,14 +275,13 @@ class QuestionAnsweringAgent(CodeAgent):
276
  # Adapter to fit interface with original app.py
277
  class ChuckAgent:
278
  def __init__(self):
279
- load_dotenv()
280
- # Check for required environment variables
281
  required_env_vars = [
282
  'OPENAI_API_KEY',
283
  'SERPER_API_KEY'
284
  ]
285
 
286
- missing_vars = [var for var in required_env_vars if not os.getenv(var)]
287
  if missing_vars:
288
  raise EnvironmentError(f"Missing required environment variables: {', '.join(missing_vars)}")
289
 
@@ -291,7 +289,7 @@ class ChuckAgent:
291
 
292
  self.model = OpenAIServerModel(
293
  model_id="gpt-4",
294
- api_key=os.getenv('OPENAI_API_KEY')
295
  )
296
 
297
  self.agent = QuestionAnsweringAgent(model=self.model)
 
11
  import operator
12
  import aiohttp
13
  from typing import Optional, Dict, Any, List, Union
 
14
 
15
  # Import necessary components from smolagents
16
  try:
 
85
  output_type = "string"
86
 
87
  async def forward(self, query: str) -> str:
88
+ if not os.environ.get('SERPER_API_KEY'):
89
  return "Error: Serper API key not found"
90
 
91
  url = "https://google.serper.dev/search"
92
  headers = {
93
+ 'X-API-KEY': os.environ.get('SERPER_API_KEY'),
94
  'Content-Type': 'application/json'
95
  }
96
  payload = {
 
275
  # Adapter to fit interface with original app.py
276
  class ChuckAgent:
277
  def __init__(self):
278
+ # Check for required environment variables directly from os.environ
 
279
  required_env_vars = [
280
  'OPENAI_API_KEY',
281
  'SERPER_API_KEY'
282
  ]
283
 
284
+ missing_vars = [var for var in required_env_vars if not os.environ.get(var)]
285
  if missing_vars:
286
  raise EnvironmentError(f"Missing required environment variables: {', '.join(missing_vars)}")
287
 
 
289
 
290
  self.model = OpenAIServerModel(
291
  model_id="gpt-4",
292
+ api_key=os.environ.get('OPENAI_API_KEY')
293
  )
294
 
295
  self.agent = QuestionAnsweringAgent(model=self.model)