Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install ruff
- run: pip install ruff==0.16.0
- run: ruff check nlp-service
10 changes: 5 additions & 5 deletions nlp-service/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

import httpx
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import Optional

load_dotenv(dotenv_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".env"))

Expand Down Expand Up @@ -44,9 +44,9 @@ def detect_abuse(req: AbuseRequest):

class ChatRequest(BaseModel):
messages: list
system_instruction: Optional[str] = None
generation_config: Optional[dict] = None
lessons_context: Optional[str] = None
system_instruction: str | None = None
generation_config: dict | None = None
lessons_context: str | None = None

class ChatResponse(BaseModel):
reply: str
Expand Down Expand Up @@ -86,7 +86,7 @@ async def call_gemini(prompt: str, system_instruction: str = "") -> str:
print(f"Gemini API error: {res.status_code} - {res.text[:200]}")
return ""

except Exception as e:
except (httpx.HTTPError, KeyError, ValueError, IndexError) as e:
print(f"Gemini API exception: {e}")
return ""

Expand Down
9 changes: 5 additions & 4 deletions nlp-service/test_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import importlib.util
import os
import traceback
import importlib.util

import spacy

nlp_spacy = spacy.load("xx_ent_wiki_sm")

spec = importlib.util.spec_from_file_location("nlp_main", os.path.join(os.path.dirname(__file__), "main.py"))
Expand All @@ -20,21 +21,21 @@
try:
cleaned = mod.normalize_arabic(text)
print(f"\nCleaned: {cleaned}")
except Exception as e:
except Exception as e: # noqa: BLE001 -- diagnostic script must survive any step failure to run the rest
print(f"\nClean error: {e}")
traceback.print_exc()

try:
s = mod.ml_sentiment(text)
print(f"Sentiment: {s}")
except Exception as e:
except Exception as e: # noqa: BLE001 -- diagnostic script must survive any step failure to run the rest
print(f"Sentiment error: {e}")
traceback.print_exc()

try:
e = mod.spacy_entities(text)
print(f"Entities: {e}")
except Exception as e:
except Exception as e: # noqa: BLE001 -- diagnostic script must survive any step failure to run the rest
print(f"Entities error: {e}")
traceback.print_exc()

Expand Down
Loading