Skip to content

Commit

Permalink
[#145] Create health endpoint in eppo-librarian
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 2, 2025
1 parent e0d78fc commit 5ec17ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eppo-librarian/eppo-librarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import chromadb
import pandas as pd
import hashlib
import threading

from lxml import html
from time import sleep
from openai import OpenAI
from lxml.html import HtmlElement
from nltk.tokenize import sent_tokenize
from deep_translator import GoogleTranslator
from health_check_handler import run

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -472,6 +474,10 @@ def add_chunks_to_chromadb(
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)

# Start the HTTP server in a separate thread
server_thread = threading.Thread(target=run, kwargs={"port": 9002})
server_thread.start()

# download the NLTK sentence splitter
nltk.download("punkt_tab")

Expand Down
24 changes: 24 additions & 0 deletions eppo-librarian/health_check_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
from http.server import BaseHTTPRequestHandler, HTTPServer


logger = logging.getLogger(__name__)


class HealthCheckHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/health":
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(b'{"status": "ok"}')
else:
self.send_response(404)
self.end_headers()


def run(server_class=HTTPServer, handler_class=HealthCheckHandler, port=9001):
server_address = ("", port)
httpd = server_class(server_address, handler_class)
logger.info(f"Starting httpd server on port {port}")
httpd.serve_forever()

0 comments on commit 5ec17ed

Please sign in to comment.