jira-webhook-llm/api/handlers.py
Ireneusz Bachanowicz 8c1ab79eeb
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run
Refactor LLM analysis chain and models; remove deprecated prompt files
- Updated `chains.py` to streamline imports and improve error handling for LLM initialization.
- Modified `models.py` to enhance the `AnalysisFlags` model with field aliases and added datetime import.
- Deleted outdated prompt files (`jira_analysis_v1.0.0.txt`, `jira_analysis_v1.1.0.txt`, `jira_analysis_v1.2.0.txt`) to clean up the repository.
- Introduced a new prompt file `jira_analysis_v1.2.0.txt` with updated instructions for analysis.
- Removed `logging_config.py` and test files to simplify the codebase.
- Updated webhook handler to improve error handling and logging.
- Added a new shared store for managing processing requests in a thread-safe manner.
2025-07-21 01:06:45 +02:00

45 lines
1.7 KiB
Python

from datetime import datetime, timezone
from fastapi import APIRouter, Request, HTTPException, Depends
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from llm.models import JiraWebhookPayload
from shared_store import requests_queue, ProcessingRequest
router = APIRouter(
prefix="/api",
tags=["API"]
)
@router.post("/jira_webhook", status_code=201)
async def receive_jira_webhook(payload: JiraWebhookPayload):
"""Handle incoming Jira webhook and store request"""
request_id = requests_queue.add_request(payload.model_dump())
return {"request_id": request_id}
@router.get("/pending_requests")
async def get_pending_requests():
"""Return all pending requests"""
all_requests = requests_queue.get_all_requests()
pending = [req for req in all_requests if req.status == "pending"]
return {"requests": pending}
@router.delete("/requests/{request_id}")
async def delete_specific_request(request_id: int):
"""Delete specific request by ID"""
if requests_queue.delete_request_by_id(request_id):
return {"deleted": True}
raise HTTPException(status_code=404, detail="Request not found")
@router.delete("/requests")
async def delete_all_requests():
"""Clear all requests"""
requests_queue.clear_all_requests()
return {"status": "cleared"}
@router.get("/requests/{request_id}/response")
async def get_request_response(request_id: int):
"""Get response for specific request"""
matched_request = requests_queue.get_request_by_id(request_id)
if not matched_request:
raise HTTPException(status_code=404, detail="Request not found")
return matched_request.response if matched_request.response else "No response yet"