programmersd commited on
Commit
aa1c07c
·
1 Parent(s): e0b1f47
Files changed (1) hide show
  1. utils.py +17 -7
utils.py CHANGED
@@ -33,25 +33,35 @@ def extract_pdf_text(pdf_path: str) -> str:
33
 
34
  # ── Gemini LLM ────────────────────────────────────────────────────────────────
35
 
36
- def generate_manim_code(prompt_text: str, api_key: str) -> str:
37
- """Stream Manim code from Gemini."""
38
  client = genai.Client(api_key=api_key)
39
- model = "gemini-2.5-flash-preview-05-20" # latest stable flash model
 
40
  contents = [
41
- types.Content(role="user", parts=[types.Part.from_text(prompt_text)])
 
 
 
42
  ]
 
43
  config = types.GenerateContentConfig(
44
- thinking_config=types.ThinkingConfig(thinking_budget=8192)
 
 
45
  )
46
 
47
  code = ""
48
  for chunk in client.models.generate_content_stream(
49
- model=model, contents=contents, config=config
 
 
50
  ):
51
  if chunk.text:
52
  code += chunk.text
53
- return code
54
 
 
55
 
56
  def sanitize_manim_code(raw: str, job_id: str) -> str:
57
  """
 
33
 
34
  # ── Gemini LLM ────────────────────────────────────────────────────────────────
35
 
36
+ def generate_manim_code(prompt_text: str, api_key: str):
37
+ """Stream Manim code from Gemini 3 Flash Preview and return it as a string."""
38
  client = genai.Client(api_key=api_key)
39
+ model = "gemini-3-flash-preview"
40
+
41
  contents = [
42
+ types.Content(
43
+ role="user",
44
+ parts=[types.Part.from_text(text=prompt_text)]
45
+ )
46
  ]
47
+
48
  config = types.GenerateContentConfig(
49
+ thinking_config=types.ThinkingConfig(
50
+ thinking_level="HIGH"
51
+ )
52
  )
53
 
54
  code = ""
55
  for chunk in client.models.generate_content_stream(
56
+ model=model,
57
+ contents=contents,
58
+ config=config
59
  ):
60
  if chunk.text:
61
  code += chunk.text
62
+ print(chunk.text, end="") # optional live streaming output
63
 
64
+ return code
65
 
66
  def sanitize_manim_code(raw: str, job_id: str) -> str:
67
  """