Schmitz005 commited on
Commit
09e4227
Β·
verified Β·
1 Parent(s): 1951ac3

Update whale_core/agents.py

Browse files
Files changed (1) hide show
  1. whale_core/agents.py +4 -9
whale_core/agents.py CHANGED
@@ -2,17 +2,12 @@ import yaml
2
  import openai
3
  import os
4
 
5
- # βœ… Set your OpenAI API key β€” use one of the two options below:
6
-
7
- # πŸ”’ Option 1: Load from environment variable (recommended)
8
- openai.api_key = os.environ["OPENAI_API_KEY"]
9
 
10
  # πŸ§ͺ Optional: fail early if key not set
11
  if not openai.api_key:
12
- raise ValueError("❌ No OpenAI API key found. Set the environment variable OPENAI_API_KEY.")
13
-
14
- # πŸ”“ Option 2 (for development only): Hardcode the key
15
- # openai.api_key = "sk-...your full key..."
16
 
17
  # βœ… Load agent configurations from YAML
18
  def load_agents(path="agents/config.yaml"):
@@ -27,7 +22,7 @@ def run_agents_on_text(agent_cfgs, doc):
27
  name = agent.get("name", "UnnamedAgent")
28
  system_msg = agent.get("persona", "You are a helpful assistant.")
29
  instructions = agent.get("instructions", "Please analyze this document.")
30
- user_prompt = f"{instructions}\n\nDocument:\n{doc[:4000]}" # Use full text or chunk
31
 
32
  try:
33
  completion = openai.ChatCompletion.create(
 
2
  import openai
3
  import os
4
 
5
+ # βœ… Set your OpenAI API key from environment variable (Hugging Face Secrets)
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
7
 
8
  # πŸ§ͺ Optional: fail early if key not set
9
  if not openai.api_key:
10
+ raise ValueError("❌ No OpenAI API key found. Set the environment variable OPENAI_API_KEY in your Hugging Face Space settings under 'Secrets'.")
 
 
 
11
 
12
  # βœ… Load agent configurations from YAML
13
  def load_agents(path="agents/config.yaml"):
 
22
  name = agent.get("name", "UnnamedAgent")
23
  system_msg = agent.get("persona", "You are a helpful assistant.")
24
  instructions = agent.get("instructions", "Please analyze this document.")
25
+ user_prompt = f"{instructions}\n\nDocument:\n{doc[:4000]}" # Truncate if needed
26
 
27
  try:
28
  completion = openai.ChatCompletion.create(