-
Notifications
You must be signed in to change notification settings - Fork 0
Ae/dev - Dev push #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add authentication checks to CourseMap component to handle logged-in/out states, disabling features and preventing API calls for logged-out users. - Replace navigation Links with styled Buttons in App and AgreementViewerPage. - Introduce CustomCourseNode for React Flow and apply it in CourseMap. - Overhaul application styling in App.css for a modern look and feel. fix: Correct major/dept fetching and API category code - Fix bug in AgreementViewerPage where 'dept' category was not fetched correctly if 'major' returned empty. - Fix bug in college_transfer_API.py where category_code was sometimes hardcoded instead of using the provided parameter. refactor: Improve caching, state management, and logging - Refine caching logic for majors and images in AgreementViewerPage. - Improve state management and cache updates in CourseMap for map creation, loading, saving, and deletion. - Add console logs to PdfViewer for debugging.
- Implemented correct history processing in the backend /chat endpoint for Gemini. - Passed specific agreement context (institutions, year, major) from frontend page to chat component. - Enhanced the initial AI prompt to utilize the provided context and maintain conversational memory.
- Allow selecting multiple sending institutions on the form. - Find common receiving institutions & years via intersection. - Display multiple agreements with tabs on AgreementViewerPage. - Integrate user authentication (Google Login) for chat & status. - Send auth token with relevant API calls. - Implement user tiers (free/paid) fetched from backend. - Add Stripe checkout flow for upgrades. - Display user tier, usage limits, and upgrade options. - Enhance chat prompt for multi-agreement context. - Add Stripe, Tailwind, PostCSS, Autoprefixer dependencies.
…pe & Gemini Refactored backend into a structured Flask application: - Uses app factory pattern (`create_app`) - Organizes routes into Blueprints (`agreement`, `user`, `course_map`, `stripe`) with `/api` prefix - Centralized config loading (`config.py`) and DB/GridFS setup (`database.py`) - Added utility functions for Google Auth, user management, and usage tracking (`utils.py`) Implemented Core API Endpoints: - Agreements: Fetch institutions, years, majors; download PDFs; generate/serve PDF images. - Chat: Integrated Gemini 1.5 Pro for analysis and conversation, including image processing, history, auth, and rate limiting. - User: `/user-status` endpoint to provide tier and usage info. - Course Maps: Full CRUD operations for user-specific course maps. - Stripe: `/create-checkout-session` and `/stripe-webhook` for subscription management and tier updates. Frontend Enhancements: - Improved user tier fetching and display logic in App.jsx. - Enhanced ChatInterface UX based on login status and context. - Fixed API parameters and countdown timer in AgreementViewerPage. - Corrected Vite proxy configuration. - Minor UI text updates and cleanups.
- Updated backend Gemini model name to 'gemini-2.5-flash-preview-04-17' to resolve initialization errors. - Refactored frontend countdown timer in AgreementViewerPage to prevent interruptions from unrelated state changes (e.g., PDF loading), ensuring it runs continuously until reset.
…rontend Backend: - Created llm_service.py abstracting Gemini API calls. - Refactored /chat route to use llm_service, always passing image context (majors + IGETC). - Added /igetc-agreement route to fetch IGETC PDF filenames. - Improved /pdf-images route with metadata-based checking and sorting by page number. - Implemented caching in CollegeTransferAPI for institutions, years, majors. - Enhanced error handling, filename sanitization, and client closing in API methods. Frontend (AgreementViewerPage & ChatInterface): - Added IGETC tab with dedicated PDF/image fetching logic. - Combined major and IGETC image filenames (`allContextImageFilenames`). - Passed combined image list to ChatInterface for all messages. - Updated initial chat prompt for detailed analysis, comparison, and education plan offer. - Refactored tab switching and data/image loading logic for agreements and IGETC. - Improved usage countdown timer display logic.
Backend (llm_service.py):
- Defined `find_course_prerequisites` function declaration and tool for Gemini.
- Initialized Gemini model with the search tool.
- Implemented `perform_web_search` using Google Custom Search API to fetch prerequisite information.
- Modified `generate_chat_response` to handle the full function calling flow:
- Detect function call requests from Gemini.
- Execute `perform_web_search` with extracted arguments.
- Send search results back to Gemini as a function response.
- Process the final LLM response incorporating search results.
- Added checks for search API keys and engine ID in `init_llm`.
Frontend (ChatInterface.jsx):
- Updated initial system prompt to inform the LLM it can use web search for prerequisites when generating the education plan.
Environment (.env):
- Added GOOGLE_SEARCH_API_KEY and GOOGLE_SEARCH_ENGINE_ID variables.
…ously" This reverts commit 34b5d16.
…ously" This reverts commit 34b5d16.
Major refactoring of AgreementViewerPage and ChatInterface components to improve modularity and maintainability. - Extracted UI sections into dedicated components: - AgreementViewerPage: MajorsList, AgreementTabs, UsageStatusDisplay - ChatInterface: ChatHeader, MessageList, MessageInput, ChatMessage, SignInPrompt - Extracted state management and logic into custom hooks: - useAgreementData: Manages majors, agreement details, PDF/image fetching & caching. - useChat: Handles chat messages, loading state, API calls. - useResizeHandler: Encapsulates draggable divider logic. - useUsageStatus: Fetches and displays user tier/usage/reset time. - (Also includes hooks for institution/year data) - Created utility function `formatText` for chat message formatting. - Simplified PdfViewer loading display. refactor(backend): Adjust user routes and utils - Replaced `@verify_google_token` decorator in `user_routes.py` with manual token verification. - Simplified `check_and_update_usage` return value in `utils.py`. - Removed unused decorator code from `utils.py`. chore: Minor code formatting (trailing newlines)
This commit introduces major backend services and refactors frontend data handling for improved performance, caching, and functionality.
**Backend:**
- **New Services:**
- `AssistApiClient`: Centralizes interaction with the Assist.org API, including in-memory caching.
- `PdfService`: Handles fetching/generating PDFs (articulation agreements, IGETC) using Playwright and storing/retrieving from GridFS.
- `mongo_helper`: Basic MongoDB connection utility.
- **New Routes (Blueprints):**
- `api_info_routes`: Exposes Assist API data (institutions, receiving inst., academic years, majors), performing intersection logic server-side for receiving institutions and years. Includes caching headers.
- `agreement_pdf_routes`: Handles POST requests to fetch/generate agreement PDFs, GET requests to generate/retrieve PDF page images (using PyMuPDF), and GET requests to serve images from GridFS with cache headers. Supports partial success (207 status).
- `igetc_routes`: Provides authenticated endpoint to fetch/generate IGETC PDF filenames.
- `chat_routes`: Implements the core `/chat` endpoint:
- Handles authentication (Google JWT verification).
- Performs user lookup/creation and rate limiting/usage checks against MongoDB.
- Initializes Gemini model and Perplexity API key.
- Accepts message history and image filenames (read from GridFS).
- Implements Gemini Function Calling loop for `search_web` tool, using Perplexity API for prerequisite lookups.
- Handles safety blocking and response parsing.
- **Structure:** Organized backend code using Flask Blueprints.
**Frontend:**
- **Data Fetching & Caching:**
- Refactored `CollegeTransferForm` data fetching for receiving institutions and academic years into custom hooks (`useReceivingInstitutions`, `useAcademicYears`).
- Implemented 3-tier caching (memory -> localStorage -> API) in `useReceivingInstitutions`, `useAcademicYears`, `useAgreementData` (majors, availability), and `CollegeTransferForm` (institutions).
- Optimized `useAgreementData` to fetch all agreement details/images in parallel upon major selection, cache them, and display the active tab's images from cache.
- Improved context change cleanup in `useAgreementData` to clear caches.
- **Authentication & Session:**
- Implemented automatic JWT attachment to API requests (`api.js`).
- Added global 401 handling in `api.js` to dispatch `auth-expired` event.
- Implemented listener in `App.jsx` to handle `auth-expired` event for automatic logout.
- Refactored logout logic using `useCallback`.
- **Chat (`useChat`):**
- Integrated Gemini Function Calling for web search (prerequisites) via Perplexity.
- Added detailed prompt for education plan generation.
- Ensured all relevant agreement image filenames are consistently passed to the backend.
- Improved initial analysis prompt and triggering logic.
- **UI (`AgreementViewerPage`):**
- Improved chat/PDF column resizing when toggling majors list visibility.
- Optimized prop passing using `useMemo`.
**Fixes:**
- Corrected API endpoint paths in frontend fetch calls (removed leading slashes).
- Ensured MongoDB client connections are properly managed/closed in `PdfService`.
- `useAgreementData` now manages `allAgreementsImageFilenamesState`, updated after all image fetches. - `AgreementViewerPage` consumes this state directly, removing its `useMemo` derivation for the full image list. This ensures `useChat` receives the correct `imageFilenames` prop. - Temporarily disable initial analysis sending in `useChat` for further testing. - Improve user object debug logging in `useChat`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.