playing with tril api

This commit is contained in:
Andrew Ridgway 2024-11-12 15:59:59 +10:00
parent bf40e4a3ca
commit 72a8428271
7 changed files with 73 additions and 13 deletions

View File

@ -1,15 +1,20 @@
FROM python:slim
FROM debian:trixie-slim
WORKDIR /blog_creator
COPY requirements.txt requirements.txt
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ADD src/ /blog_creator
RUN apt-get update && apt-get install -y rustc cargo python-is-python3 pip python3.12-venv libmagic-dev
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
#RUN apt-get update && apt-get install -y make
#RUN make html
ENTRYPOINT ["python", "main.py"]

View File

@ -1,5 +1,14 @@
## BLOG CREATOR
This creator requires you to use a working Trilium Instance and create a .env file with the following
```
TRILIUM_HOST
TRILIUM_PORT
TRILIUM_PROTOCOL
TRILIUM_PASS
```
This container is going to be what I use to trigger a blog creation event
To do this we will

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
services:
blog_creator:
build:
context: .
dockerfile: Dockerfile
container_name: blog_creator
env_file:
- .env

View File

@ -1 +1,2 @@
ollama
trilium-py

View File

@ -1,5 +1,13 @@
from ollama import Client
import trilium.notes as tn
tril = tn.TrilumNotes()
tril_notes = tril.get_new_notes()
for note in tril_notes:
print(note)
client = Client(host='http://192.168.178.45:11434')
user_prompt = input("Ask mistral-nemo a question: ")

View File

@ -1,8 +0,0 @@
from trilium_py.client import ETAPI
import os
server_url = f'{os.environ['TRILIUM_PROTOCOL']}://{os.environ['TRILIUM_HOST']}:{os.environ['TRILIUM_PORT']}'
password = os.environ['TRILIUM_PASS']
ea = ETAPI(server_url)
token = ea.login(password)
print(token)

36
src/trilium/notes.py Normal file
View File

@ -0,0 +1,36 @@
from trilium_py.client import ETAPI
import os
class TrilumNotes:
def __init__(self):
self.protocol = os.environ.get('TRILUM_PROTOCOL')
self.host = os.environ.get('TRILIUM_HOST')
self.port = os.environ.get('TRILIUM_PORT')
self.tril_pass = os.environ.get('TRILIUM_PASS')
self.token = os.environ.get('TRILIUM_TOKEN')
if not all([self.protocol, self.host, self.port, self.tril_pass]):
print("One or more required environment variables not found. Have you set a .env?")
self.server_url = f'{self.protocol}://{self.host}:{self.port}'
if not self.token:
print("Please run get_token and set your token")
else:
self.ea = ETAPI(self.server_url, self.token)
def get_token(self):
ea = ETAPI(self.server_url)
token = ea.login(self.tril_pass)
print(token)
print("I would recomend you update the env file with this tootsweet!")
def get_new_notes(self):
notes = self.ea.search_note(
search="#ai_blog #blog_written=false",
ancestorNoteId="kYZXOUVabB7s",
fastSearch=False,
limit=10
)
self.new_notes = notes
return notes