Spaces:
Sleeping
Sleeping
Added an agent_server module for better compartmentalization.
Browse files- Dockerfile +1 -0
- agent_server/__init__.py +0 -0
- agent_server/openai_schemas.py +14 -0
- proxy.py +2 -20
Dockerfile
CHANGED
|
@@ -56,6 +56,7 @@ COPY --from=base --chown=1000 /app/.env /app/.env
|
|
| 56 |
COPY --chown=1000 .env.local /app/.env.local
|
| 57 |
COPY --chown=1000 proxy.py /app/proxy.py
|
| 58 |
COPY --chown=1000 agents /app/agents
|
|
|
|
| 59 |
COPY --chown=1000 --chmod=0755 entrypoint.sh /app/entrypoint.sh
|
| 60 |
|
| 61 |
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
|
|
| 56 |
COPY --chown=1000 .env.local /app/.env.local
|
| 57 |
COPY --chown=1000 proxy.py /app/proxy.py
|
| 58 |
COPY --chown=1000 agents /app/agents
|
| 59 |
+
COPY --chown=1000 agent_server /app/agent_server
|
| 60 |
COPY --chown=1000 --chmod=0755 entrypoint.sh /app/entrypoint.sh
|
| 61 |
|
| 62 |
ENTRYPOINT ["/app/entrypoint.sh"]
|
agent_server/__init__.py
ADDED
|
File without changes
|
agent_server/openai_schemas.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ChatMessage(typing.TypedDict, total=False):
|
| 5 |
+
role: str
|
| 6 |
+
content: typing.Any # str or multimodal list
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ChatCompletionRequest(typing.TypedDict, total=False):
|
| 10 |
+
model: typing.Optional[str]
|
| 11 |
+
messages: typing.List[ChatMessage]
|
| 12 |
+
temperature: typing.Optional[float]
|
| 13 |
+
stream: typing.Optional[bool]
|
| 14 |
+
max_tokens: typing.Optional[int]
|
proxy.py
CHANGED
|
@@ -19,6 +19,7 @@ import contextlib
|
|
| 19 |
# Upstream pass-through
|
| 20 |
import httpx
|
| 21 |
|
|
|
|
| 22 |
from agents.code_writing_agents import (
|
| 23 |
generate_code_writing_agent_without_tools,
|
| 24 |
generate_code_writing_agent_with_search,
|
|
@@ -36,12 +37,7 @@ log = logging.getLogger(__name__)
|
|
| 36 |
|
| 37 |
# Config from env vars
|
| 38 |
UPSTREAM_BASE = os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/")
|
| 39 |
-
HF_TOKEN = (
|
| 40 |
-
os.getenv("HF_TOKEN")
|
| 41 |
-
or os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 42 |
-
or os.getenv("API_TOKEN")
|
| 43 |
-
or ""
|
| 44 |
-
)
|
| 45 |
AGENT_MODEL = os.getenv("AGENT_MODEL", "Qwen/Qwen3-1.7B")
|
| 46 |
|
| 47 |
if not UPSTREAM_BASE:
|
|
@@ -60,20 +56,6 @@ async def healthz():
|
|
| 60 |
return {"ok": True}
|
| 61 |
|
| 62 |
|
| 63 |
-
# ---------- OpenAI-compatible minimal schemas ----------
|
| 64 |
-
class ChatMessage(typing.TypedDict, total=False):
|
| 65 |
-
role: str
|
| 66 |
-
content: typing.Any # str or multimodal list
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
class ChatCompletionRequest(typing.TypedDict, total=False):
|
| 70 |
-
model: typing.Optional[str]
|
| 71 |
-
messages: typing.List[ChatMessage]
|
| 72 |
-
temperature: typing.Optional[float]
|
| 73 |
-
stream: typing.Optional[bool]
|
| 74 |
-
max_tokens: typing.Optional[int]
|
| 75 |
-
|
| 76 |
-
|
| 77 |
# ---------- Helpers ----------
|
| 78 |
def normalize_content_to_text(content: typing.Any) -> str:
|
| 79 |
if isinstance(content, str):
|
|
|
|
| 19 |
# Upstream pass-through
|
| 20 |
import httpx
|
| 21 |
|
| 22 |
+
from agent_server.openai_schemas import ChatMessage, ChatCompletionRequest
|
| 23 |
from agents.code_writing_agents import (
|
| 24 |
generate_code_writing_agent_without_tools,
|
| 25 |
generate_code_writing_agent_with_search,
|
|
|
|
| 37 |
|
| 38 |
# Config from env vars
|
| 39 |
UPSTREAM_BASE = os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/")
|
| 40 |
+
HF_TOKEN = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
AGENT_MODEL = os.getenv("AGENT_MODEL", "Qwen/Qwen3-1.7B")
|
| 42 |
|
| 43 |
if not UPSTREAM_BASE:
|
|
|
|
| 56 |
return {"ok": True}
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# ---------- Helpers ----------
|
| 60 |
def normalize_content_to_text(content: typing.Any) -> str:
|
| 61 |
if isinstance(content, str):
|