Spaces:
Running
Running
details.wes commited on
Commit ·
3d60a43
1
Parent(s): 9b7c591
used hugging face model
Browse files- README.md +2 -2
- __pycache__/crew.cpython-313.pyc +0 -0
- crew.py +30 -31
- requirements.txt +4 -3
README.md
CHANGED
|
@@ -8,14 +8,14 @@ app_port: 7860
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Agents service (CrewAI +
|
| 12 |
|
| 13 |
FastAPI app that exposes:
|
| 14 |
|
| 15 |
- `GET /health` — liveness check
|
| 16 |
- `POST /generate` — body: `topic`, optional `feedback`, `memory_context`, `tone_instruction`; returns `{"post": "..."}`
|
| 17 |
|
| 18 |
-
Set **`
|
| 19 |
|
| 20 |
**Port:** the container listens on `$PORT` when the platform sets it, otherwise **7860** (Hugging Face Spaces default).
|
| 21 |
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Agents service (CrewAI + LiteLLM + Hugging Face)
|
| 12 |
|
| 13 |
FastAPI app that exposes:
|
| 14 |
|
| 15 |
- `GET /health` — liveness check
|
| 16 |
- `POST /generate` — body: `topic`, optional `feedback`, `memory_context`, `tone_instruction`; returns `{"post": "..."}`
|
| 17 |
|
| 18 |
+
Set **`HF_TOKEN`** (or **`HUGGINGFACE_HUB_TOKEN`**) as a [Space secret](https://huggingface.co/docs/hub/spaces-overview#managing-secrets) (required). Optionally set **`AGENTS_LLM_MODEL`** (default: `huggingface/Qwen/WebWorld-32B`), **`AGENTS_LLM_TEMPERATURE`**, or **`AGENTS_LLM_BASE_URL`** for an OpenAI-compatible endpoint (see `crew.py`).
|
| 19 |
|
| 20 |
**Port:** the container listens on `$PORT` when the platform sets it, otherwise **7860** (Hugging Face Spaces default).
|
| 21 |
|
__pycache__/crew.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/crew.cpython-313.pyc and b/__pycache__/crew.cpython-313.pyc differ
|
|
|
crew.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
"""
|
| 2 |
Crew definition for the agents service.
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
from __future__ import annotations
|
| 15 |
|
|
@@ -21,37 +24,33 @@ from crewai.agents.agent_builder.base_agent import BaseAgent
|
|
| 21 |
from crewai.project import CrewBase, agent, crew, task
|
| 22 |
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def _resolve_nvidia_key() -> str:
|
| 29 |
-
"""Return the NVIDIA NIM key, accepting either env var name. Hard-fail if missing."""
|
| 30 |
-
key = (os.getenv("NVIDIA_NIM_API_KEY") or os.getenv("NVIDIA_API_KEY") or "").strip()
|
| 31 |
-
if not key:
|
| 32 |
raise RuntimeError(
|
| 33 |
-
"Missing
|
| 34 |
"agents service environment."
|
| 35 |
)
|
| 36 |
-
return
|
| 37 |
|
| 38 |
|
| 39 |
def _build_llm() -> LLM:
|
| 40 |
-
model = (os.getenv("AGENTS_LLM_MODEL") or
|
| 41 |
-
if not model.startswith("nvidia_nim/"):
|
| 42 |
-
raise RuntimeError(
|
| 43 |
-
f"This service only supports NVIDIA NIM models. Got model={model!r}; "
|
| 44 |
-
f"expected a value starting with 'nvidia_nim/'."
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
base_url = (os.getenv("AGENTS_LLM_BASE_URL") or _NVIDIA_DEFAULT_BASE).strip().rstrip("/")
|
| 48 |
temperature = float(os.getenv("AGENTS_LLM_TEMPERATURE", "0.5"))
|
| 49 |
|
| 50 |
-
|
| 51 |
-
os.environ["
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
return LLM(model=model,
|
| 55 |
|
| 56 |
|
| 57 |
@CrewBase
|
|
|
|
| 1 |
"""
|
| 2 |
Crew definition for the agents service.
|
| 3 |
|
| 4 |
+
LLM is provided via LiteLLM. Default Hugging Face Hub model id:
|
| 5 |
+
huggingface/Qwen/WebWorld-32B
|
| 6 |
+
|
| 7 |
+
If that route fails, LiteLLM supports a Hub inference-provider prefix (only if the model's Hub page lists the
|
| 8 |
+
provider for this model — do not guess the provider):
|
| 9 |
+
huggingface/<provider>/Qwen/WebWorld-32B
|
| 10 |
+
Example shape (valid only when listed on the model card): huggingface/together/Qwen/WebWorld-32B
|
| 11 |
+
|
| 12 |
+
Set HF_TOKEN (Hugging Face access token). Optional:
|
| 13 |
+
AGENTS_LLM_MODEL default: huggingface/Qwen/WebWorld-32B
|
| 14 |
+
AGENTS_LLM_TEMPERATURE float, default 0.5
|
| 15 |
+
AGENTS_LLM_BASE_URL optional OpenAI-compatible base URL (e.g. HF Inference Endpoint)
|
| 16 |
"""
|
| 17 |
from __future__ import annotations
|
| 18 |
|
|
|
|
| 24 |
from crewai.project import CrewBase, agent, crew, task
|
| 25 |
|
| 26 |
|
| 27 |
+
def _resolve_hf_token() -> str:
|
| 28 |
+
token = (os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN") or "").strip()
|
| 29 |
+
if not token:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
raise RuntimeError(
|
| 31 |
+
"Missing Hugging Face token. Set HF_TOKEN (or HUGGINGFACE_HUB_TOKEN) in the "
|
| 32 |
"agents service environment."
|
| 33 |
)
|
| 34 |
+
return token
|
| 35 |
|
| 36 |
|
| 37 |
def _build_llm() -> LLM:
|
| 38 |
+
model = (os.getenv("AGENTS_LLM_MODEL") or "huggingface/Qwen/WebWorld-32B").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
temperature = float(os.getenv("AGENTS_LLM_TEMPERATURE", "0.5"))
|
| 40 |
|
| 41 |
+
hf_token = _resolve_hf_token()
|
| 42 |
+
os.environ["HF_TOKEN"] = hf_token
|
| 43 |
+
|
| 44 |
+
base_url = (os.getenv("AGENTS_LLM_BASE_URL") or "").strip().rstrip("/")
|
| 45 |
+
if base_url:
|
| 46 |
+
return LLM(
|
| 47 |
+
model=model,
|
| 48 |
+
base_url=base_url,
|
| 49 |
+
api_key=hf_token,
|
| 50 |
+
temperature=temperature,
|
| 51 |
+
)
|
| 52 |
|
| 53 |
+
return LLM(model=model, api_key=hf_token, temperature=temperature)
|
| 54 |
|
| 55 |
|
| 56 |
@CrewBase
|
requirements.txt
CHANGED
|
@@ -2,13 +2,14 @@ fastapi
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-dotenv
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
#
|
|
|
|
| 7 |
crewai
|
| 8 |
crewai-tools
|
| 9 |
litellm
|
| 10 |
|
| 11 |
-
# Transitively required by litellm/crewai
|
| 12 |
openai
|
| 13 |
tiktoken
|
| 14 |
|
|
|
|
| 2 |
uvicorn[standard]
|
| 3 |
python-dotenv
|
| 4 |
|
| 5 |
+
# LLM: set HF_TOKEN (or HUGGINGFACE_HUB_TOKEN). LiteLLM model ids use huggingface/<org>/<model> (see crew.py).
|
| 6 |
+
# If plain huggingface/Qwen/WebWorld-32B fails, try huggingface/<provider>/Qwen/WebWorld-32B only when the Hub
|
| 7 |
+
# model page lists that inference provider for this model (e.g. a listed provider, not guessed).
|
| 8 |
crewai
|
| 9 |
crewai-tools
|
| 10 |
litellm
|
| 11 |
|
| 12 |
+
# Transitively required by litellm/crewai (OpenAI-compatible client + tokenizer).
|
| 13 |
openai
|
| 14 |
tiktoken
|
| 15 |
|