importosfromnotecastimportdb,pipelinefromnotecast.llmimportOllamaconn=db.connect(os.environ.get("NOTECAST_DB","notecast.db"))db.init_db(conn)# creates or migrates the schemallm=Ollama(base_url=os.environ.get("OLLAMA_URL","http://localhost:11434"))assertllm.ping()andnotllm.missing_models()db.add_theme(conn,"Tech",is_base=True)db.add_theme(conn,"Cooking",is_base=True)db.upsert_note_from_source(conn,"Pods","Tech notes: Kubernetes pods and services.","mem:pods")db.upsert_note_from_source(conn,"Bread","Cooking notes: sourdough and starters.","mem:bread")assertpipeline.process_notes(conn,llm)==2assertpipeline.classify_notes(conn,llm)==2fornoteindb.list_notes(conn):print(note.title,note.status,db.note_theme_names(conn,[note.id])[note.id])
upsert_note_from_source is what add uses: the third argument
identifies where the note came from, so calling it again with the same
content does nothing, and with new content updates the note.
fromnotecast.llmimportOllama,OllamaError,OllamaUnavailablellm=Ollama(base_url="http://127.0.0.1:9")# nothing listens heretry:llm.generate("hello")exceptOllamaUnavailablease:# unreachable, or model not pulled (HTTP 404)print("stop and retry later:",e)exceptOllamaErrorase:# any other failed requestprint("this request failed:",e)
The pipeline functions raise OllamaUnavailable and leave the notes they
had not reached untouched; every other model failure is handled per note,
batch or theme, as described in The pipeline.