44from requests .exceptions import Timeout , RequestException
55
66from app .core .config import OLLAMA_HOST , OLLAMA_MODEL
7+ from app .core .logging import get_logger
8+
9+ logger = get_logger (__name__ )
710
811
912class LLM :
@@ -51,9 +54,9 @@ def main_loop(self):
5154 json_data = response .json ()
5255 break
5356 except Timeout :
54- print ( f"[LOG]: Ollama request timed out (attempt { attempt + 1 } ) for field '{ field } '. Retrying..." )
57+ logger . warning ( " Ollama request timed out (attempt %d ) for field '%s '. Retrying...", attempt + 1 , field )
5558 except RequestException as e :
56- print ( f"[LOG]: Ollama request failed: { e } " )
59+ logger . error ( " Ollama request failed: %s" , e )
5760 except requests .exceptions .ConnectionError :
5861 raise ConnectionError (
5962 f"Could not connect to Ollama at { ollama_url } . "
@@ -67,12 +70,9 @@ def main_loop(self):
6770 else :
6871 parsed_response = json_data ["response" ]
6972 self .add_response_to_json (field , parsed_response )
70- print ( f"[ { i } / { total_fields } ] Extracted data for field '{ field } ' successfully." )
73+ logger . info ( "[%d/%d ] Extracted data for field '%s ' successfully.", i , total_fields , field )
7174
72- print ("----------------------------------" )
73- print ("\t [LOG] Resulting JSON created from the input text:" )
74- print (json .dumps (self ._json , indent = 2 ))
75- print ("--------- extracted data ---------" )
75+ logger .info ("Resulting JSON created from the input text:\n %s" , json .dumps (self ._json , indent = 2 ))
7676
7777 return self
7878
0 commit comments