Spaces:
Sleeping
Sleeping
Update whale_core/agents.py
Browse files- 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
|
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]}" #
|
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(
|