-
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.
* feat:question template added * feat:mcq generate * docs:readme * ci:Create pylint.yml * Update pylint.yml * refactor:remove unused imports * refactor:lint fix * fix:response json format
- Loading branch information
Showing
10 changed files
with
250 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Pylint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ "3.12"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install pylint | ||
- name: Analysing the code with pylint | ||
run: | | ||
pylint $(git ls-files '*.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Testify - AI Assistant | ||
|
||
## Setup | ||
1. Clone the repository | ||
2. Install the required packages using `pip install -r requirements.txt` | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
3. Run the app using `uvicorn app.main:app --reload` | ||
|
||
```bash | ||
uvicorn app.main:app --reload --port 7401 | ||
``` | ||
|
||
4. Open API documentation at `http://localhost:7401/docs` |
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,14 +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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from langchain_core.pydantic_v1 import BaseModel, Field | ||
from langchain_core.output_parsers import JsonOutputParser | ||
|
||
|
||
|
||
# Define a Pydantic model for a standard question and answer format. | ||
class QuestionParser(BaseModel): | ||
question: str = Field(description="The question generated from the text.") | ||
answer: str = Field(description="The answer to the generated question.") | ||
|
||
# Define a Pydantic model for multiple-choice questions. | ||
class Answer(BaseModel): | ||
char: str = Field(description="The character representing the answer, e.g., 'A', 'B', 'C', 'D'.") | ||
text: str = Field(description="The text of the answer.") | ||
|
||
class MultipleChoiceQuestionParser(BaseModel): | ||
question: str = Field(description="The multiple choice question generated from the text.") | ||
options: list[Answer] = Field(description="The options for the multiple choice question, should be a list of Answer objects.") | ||
answer: str = Field(description="The character representing the correct answer, e.g., 'A', 'B', 'C', 'D'.") | ||
|
||
# Function to generate a prompt and corresponding parser for creating multiple-choice questions. | ||
def mcq_prompt(options: int) -> tuple[str, JsonOutputParser]: | ||
""" | ||
Generates a prompt for creating multiple-choice questions along with a JSON output parser. | ||
Args: | ||
options_count (int): The number of options for the multiple-choice question. | ||
Returns: | ||
tuple[str, JsonOutputParser]: A tuple containing the prompt and the JSON output parser. | ||
""" | ||
prompt_text = f"Generate a multiple choice question with {options} options and indicate the correct answer." | ||
parser = JsonOutputParser(pydantic_object=MultipleChoiceQuestionParser) | ||
return (prompt_text, parser) | ||
|
||
# Function to generate a prompt and corresponding parser for creating essay-type questions. | ||
def essay_prompt() -> tuple[str, JsonOutputParser]: | ||
""" | ||
Generates a prompt for creating essay questions along with a JSON output parser. | ||
Returns: | ||
tuple[str, JsonOutputParser]: A tuple containing the prompt and the JSON output parser. | ||
""" | ||
prompt_text = "Generate an essay question." | ||
parser = JsonOutputParser(pydantic_object=QuestionParser) | ||
return (prompt_text, parser) |
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("/", response_model=dict) | ||
@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 {"Hello": "World"} | ||
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,14 +1,16 @@ | ||
from fastapi import APIRouter, Query, HTTPException | ||
from typing import List | ||
|
||
from fastapi import APIRouter, HTTPException, Query | ||
from ..services.prompt import prompt | ||
|
||
|
||
router = APIRouter() | ||
|
||
@router.get("/generate-question/", response_model=str) | ||
@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")) -> str: | ||
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
Oops, something went wrong.