3030# Set cache directory for models
3131os .environ ["HF_HOME" ] = "/cortex/.cache/"
3232
33- def setup_ollama ():
34- """Start Ollama service (binary installed during build)."""
35- try :
36- logger .info ("Starting Ollama service..." )
37-
38- # Start Ollama service in background (binary pre-installed)
39- ollama_process = subprocess .Popen (
40- ["ollama" , "serve" ],
41- stdout = subprocess .PIPE ,
42- stderr = subprocess .PIPE ,
43- text = True
44- )
45-
46- logger .info ("✓ Ollama service started" )
47- return ollama_process
48-
49- except Exception as e :
50- logger .error (f"Failed to start Ollama: { e } " )
51- return None
52-
53- def wait_for_ollama ():
54- """Wait for Ollama to be ready."""
55- max_attempts = 30
33+ def check_ollama_ready ():
34+ """Check if Ollama is ready (should be started by Docker container)."""
35+ max_attempts = 10
5636 for attempt in range (max_attempts ):
5737 try :
5838 result = subprocess .run (
@@ -70,7 +50,7 @@ def wait_for_ollama():
7050 logger .info (f"Waiting for Ollama... ({ attempt + 1 } /{ max_attempts } )" )
7151 time .sleep (2 )
7252
73- logger .error ("✗ Ollama failed to start within timeout " )
53+ logger .error ("✗ Ollama not available " )
7454 return False
7555
7656class GmailAssistant (Agent ):
@@ -205,18 +185,16 @@ async def log_usage():
205185 logger .info ("✓ Build phase complete" )
206186
207187 else :
208- # Start Ollama service first
188+ # Check if Ollama is ready (should be started by Docker container)
209189 logger .info ("🚀 Starting Gmail Voice Assistant Agent..." )
210- logger .info ("Setting up Ollama..." )
211-
212- ollama_process = setup_ollama ()
190+ logger .info ("Checking Ollama availability..." )
213191
214- if ollama_process and wait_for_ollama ():
215- logger .info ("✓ Ollama is ready , starting LiveKit agent worker" )
192+ if check_ollama_ready ():
193+ logger .info ("✓ Ollama is available , starting LiveKit agent worker" )
216194 else :
217- logger .error ("❌ Ollama setup failed - agent cannot function without LLM" )
218- logger .error ("Please check Ollama installation and model availability " )
219- # Don't start agent if Ollama failed - it will definitely fail
195+ logger .error ("❌ Ollama not available - agent cannot function without LLM" )
196+ logger .error ("Make sure Ollama is running in the Docker container " )
197+ # Don't start agent if Ollama not available - it will definitely fail
220198 sys .exit (1 )
221199
222200 # Start the LiveKit agent worker
@@ -229,10 +207,6 @@ async def log_usage():
229207 ))
230208 except KeyboardInterrupt :
231209 logger .info ("Shutting down..." )
232- if ollama_process :
233- ollama_process .terminate ()
234210 except Exception as e :
235211 logger .error (f"Agent failed: { e } " )
236- if ollama_process :
237- ollama_process .terminate ()
238212 raise
0 commit comments