github-actions[bot] commited on
Commit
823ce16
·
1 Parent(s): 3826b11

deploy: switch to chatterbox requirements @ 8969a8b

Browse files
Files changed (1) hide show
  1. tools_api/scene_writer.py +28 -14
tools_api/scene_writer.py CHANGED
@@ -9,16 +9,23 @@ the endpoint errors and the frontend falls back to its offline template engine.
9
  """
10
  from __future__ import annotations
11
 
 
12
  import os
 
13
 
14
- from steps.lang._shared import MODEL, bedrock_converse, build_client, log_llm_call
15
 
16
- # Bedrock model for scene drafting. Defaults to qwen.qwen3-next-80b-a3bthe
17
- # same model the backend's translation step uses, so it's known-good on this
18
- # account (works with Converse, no inference-profile requirement). Override via
19
- # env SCENE_BEDROCK_MODEL.
20
  SCENE_MODEL = os.getenv("SCENE_BEDROCK_MODEL", "qwen.qwen3-next-80b-a3b")
21
 
 
 
 
 
 
 
22
  _TEMPERATURE = 0.8
23
 
24
  _SYSTEM_PROMPT = """You are a scriptwriter for DramaBox, a text-to-speech engine that performs short, emotionally directed monologues.
@@ -75,21 +82,28 @@ def _bedrock_scene(user_prompt: str) -> str:
75
 
76
 
77
  def _pollinations_scene(user_prompt: str) -> str:
78
- """Fallback provider — Pollinations (OpenAI-compatible, see _shared.py)."""
79
- client = build_client()
80
- response = client.chat.completions.create(
81
- model=MODEL,
82
- messages=[
83
  {"role": "system", "content": _SYSTEM_PROMPT},
84
  {"role": "user", "content": user_prompt},
85
  ],
86
- temperature=_TEMPERATURE,
 
 
 
 
 
87
  )
88
- raw = (response.choices[0].message.content or "").strip()
 
 
89
  log_llm_call(
90
  step="dramabox_scene",
91
- provider="pollinations",
92
- model=MODEL,
93
  system_prompt=_SYSTEM_PROMPT,
94
  user_prompt=user_prompt,
95
  response=raw,
 
9
  """
10
  from __future__ import annotations
11
 
12
+ import json
13
  import os
14
+ import urllib.request
15
 
16
+ from steps.lang._shared import bedrock_converse, log_llm_call
17
 
18
+ # Bedrock model for scene drafting. Override via env SCENE_BEDROCK_MODEL if
19
+ # Bedrock returns "Operation not allowed", the model needs a cross-region
20
+ # inference profile id (e.g. "us.amazon.nova-micro-v1:0").
 
21
  SCENE_MODEL = os.getenv("SCENE_BEDROCK_MODEL", "qwen.qwen3-next-80b-a3b")
22
 
23
+ # Pollinations fallback uses the keyless anonymous text endpoint. The keyed
24
+ # gen.pollinations.ai route (build_client) blocks the Space's requests; the
25
+ # anonymous text route stays open. Override the model via env POLLEN_TEXT_MODEL.
26
+ POLLEN_TEXT_URL = "https://text.pollinations.ai/openai"
27
+ POLLEN_TEXT_MODEL = os.getenv("POLLEN_TEXT_MODEL", "openai")
28
+
29
  _TEMPERATURE = 0.8
30
 
31
  _SYSTEM_PROMPT = """You are a scriptwriter for DramaBox, a text-to-speech engine that performs short, emotionally directed monologues.
 
82
 
83
 
84
  def _pollinations_scene(user_prompt: str) -> str:
85
+ """Fallback provider — Pollinations' keyless anonymous text endpoint."""
86
+ payload = json.dumps({
87
+ "model": POLLEN_TEXT_MODEL,
88
+ "temperature": _TEMPERATURE,
89
+ "messages": [
90
  {"role": "system", "content": _SYSTEM_PROMPT},
91
  {"role": "user", "content": user_prompt},
92
  ],
93
+ }).encode("utf-8")
94
+ req = urllib.request.Request(
95
+ POLLEN_TEXT_URL,
96
+ data=payload,
97
+ headers={"Content-Type": "application/json"},
98
+ method="POST",
99
  )
100
+ with urllib.request.urlopen(req, timeout=60) as resp:
101
+ data = json.loads(resp.read().decode("utf-8"))
102
+ raw = (data["choices"][0]["message"]["content"] or "").strip()
103
  log_llm_call(
104
  step="dramabox_scene",
105
+ provider="pollinations-text",
106
+ model=POLLEN_TEXT_MODEL,
107
  system_prompt=_SYSTEM_PROMPT,
108
  user_prompt=user_prompt,
109
  response=raw,