-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
147 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
# app/__init__.py | ||
from .main import app | ||
|
||
from fastapi import FastAPI | ||
from .routers.upload import router as upload_router | ||
from .routers.questionGenerate import router as questionGenerate_router | ||
|
||
|
||
from .main import app | ||
|
||
# Include routers with appropriate API version prefix | ||
app.include_router(upload_router, prefix="/api/v1") | ||
app.include_router(questionGenerate_router, prefix="/api/v1") | ||
|
||
|
||
# app/routers/upload.py | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from fastapi import FastAPI | ||
|
||
# Initialize the FastAPI app with a custom title | ||
# Create an instance of the FastAPI application with a custom title | ||
app = FastAPI(title="Testify AI") | ||
|
||
@app.get("/api/assistant", response_model=dict) | ||
async def read_root() -> dict: | ||
""" | ||
Root GET endpoint to return a simple greeting. | ||
Returns a JSON object with a greeting message. | ||
Root GET endpoint that provides a simple greeting message. | ||
Returns: | ||
dict: A dictionary containing a greeting message. | ||
""" | ||
return {"message": "Welcome to the Testify AI Assistant!"} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from fastapi import APIRouter, Query | ||
from fastapi import APIRouter, HTTPException, Query | ||
from ..services.prompt import prompt | ||
|
||
|
||
router = APIRouter() | ||
|
||
@router.get("/generate-question/", response_model=dict) | ||
async def generate_question(text: str = Query(..., description="The text to generate a question for"), | ||
examid: str = Query(..., description="The ID of the exam related to the text")) -> any: | ||
examid: str = Query(..., description="The ID of the exam related to the text")) -> dict: | ||
"""Endpoint to generate a question for a given text using OpenAI's model.""" | ||
|
||
return prompt(text, examid) | ||
try: | ||
# Assuming 'prompt' function is synchronous; if it's async, use 'await prompt(text, examid)' | ||
question_response = prompt(text, examid) | ||
return question_response | ||
except Exception as e: | ||
# Catching a broad exception is not best practice; adjust according to specific exceptions expected from 'prompt' | ||
raise HTTPException(status_code=500, detail=f"An error occurred while generating the question: {str(e)}") |
This file contains 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
This file contains 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
This file contains 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