Skip to content

Commit

Permalink
refactor: Replace Hugging Face API calls with Ollama (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-zehnder authored Nov 30, 2024
1 parent 67e92ee commit 3bdde0c
Show file tree
Hide file tree
Showing 21 changed files with 3,101 additions and 365 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ MYSQL_USER=user
MYSQL_PASSWORD=password
MYSQL_ROOT_PASSWORD=password

# Third Party
HUGGING_FACE_API_KEY=
# Ollama
OLLAMA_BASE_URL=http://localhost:11434/api/generate
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ dist
.DS_Store
coverage.out
coverage.html
debug.ts
node_modules/
/blob-report/
coverage/
downloads
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test:
@echo "Running tests for all components..."
$(MAKE) -C frontend test
$(MAKE) -C backend test
$(MAKE) -C hackernews_scraper test

.PHONY: push
push:
Expand Down
19 changes: 5 additions & 14 deletions backend/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@ echo "MySQL is ready."

# Check if the database exists and create it if it does not
echo "Creating database if it doesn't exist..."
mysql -h $MYSQL_HOST -u root -p"$MYSQL_ROOT_PASSWORD" -e "
CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;
USE $MYSQL_DATABASE;
CREATE TABLE IF NOT EXISTS articles (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
link VARCHAR(512) NOT NULL,
content TEXT,
summary VARCHAR(2000),
source VARCHAR(100) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL
);
"
mysql -h $MYSQL_HOST -u root -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE"

# Apply the schema.sql (idempotent operation)
echo "Applying schema..."
mysql -h $MYSQL_HOST -u root -p"$MYSQL_ROOT_PASSWORD" $MYSQL_DATABASE < /app/schema.sql

echo "Database initialization completed."

Expand Down
28 changes: 23 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
- backend
networks:
- app-network
env_file:
- .env

backend:
image: kjzehnder3/gophersignal-backend:latest
Expand All @@ -18,15 +16,32 @@ services:
- app-network
env_file:
- .env
restart: always
depends_on:
mysql:
condition: service_healthy

hackernews_scraper:
image: kjzehnder3/gophersignal-hackernews_scraper:latest
networks:
- app-network
env_file:
- .env
restart: always

mysql:
image: mysql:latest
healthcheck:
test: ['CMD-SHELL', 'mysqladmin ping -h localhost -uroot -p$${MYSQL_ROOT_PASSWORD}']
interval: 10s
timeout: 5s
retries: 5
ports:
- 3306:3306
volumes:
- mysql_gophersignal:/var/lib/mysql
networks:
- app-network
env_file:
- .env

nginx:
image: nginx:latest
Expand All @@ -41,8 +56,11 @@ services:
- ./frontend/out:/usr/share/nginx/html
depends_on:
- backend
restart: always

networks:
app-network:
driver: bridge

volumes:
mysql_gophersignal:
driver: local
2 changes: 1 addition & 1 deletion frontend/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
2 changes: 2 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions hackernews_scraper/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"check-coverage": true,
"per-file": true,
"lines": 0,
"statements": 0,
"functions": 0,
"branches": 0,
"reporter": ["text", "html"],
"include": ["src/**/*.ts"],
"exclude": ["tests/**/*.test.ts", "node_modules"]
}
5 changes: 5 additions & 0 deletions hackernews_scraper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ build:
@echo "Building HackerNews scraper Docker image..."
docker build -t $(HACKERNEWS_SCRAPER_IMAGE_TAG) .

.PHONY: test
test:
@echo "Running tests for HackerNews scraper..."
docker run --rm $(HACKERNEWS_SCRAPER_IMAGE_TAG) npm test

.PHONY: push
push:
@echo "Pushing HackerNews scraper Docker image..."
Expand Down
Loading

0 comments on commit 3bdde0c

Please sign in to comment.