Skip to content

Commit

Permalink
Adapt config. Replace None unions with Optional. Remove unnecessary f…
Browse files Browse the repository at this point in the history
…iles.
  • Loading branch information
kaancayli committed Mar 11, 2024
1 parent bb32775 commit f683132
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 140 deletions.
2 changes: 1 addition & 1 deletion app/common/custom_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self):
super().__init__(
status_code=status.HTTP_404_NOT_FOUND,
detail={
"type": "not_found",
"type": "pipeline_not_found",
"errorMessage": "Pipeline not found",
},
)
5 changes: 1 addition & 4 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ class APIKeyConfig(BaseModel):


class Settings(BaseModel):
class PyrisSettings(BaseModel):
api_keys: list[APIKeyConfig]

pyris: PyrisSettings
api_keys: list[APIKeyConfig]

@classmethod
def get_settings(cls):
Expand Down
2 changes: 1 addition & 1 deletion app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _get_api_key(request: Request) -> str:

class TokenValidator:
async def __call__(self, api_key: str = Depends(_get_api_key)) -> APIKeyConfig:
for key in settings.pyris.api_keys:
for key in settings.api_keys:
if key.token == api_key:
return key
raise PermissionDeniedException
6 changes: 4 additions & 2 deletions app/domain/data/course_dto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from pydantic import BaseModel


class CourseDTO(BaseModel):
id: int
name: str | None = None
description: str | None = None
name: Optional[str] = None
description: Optional[str] = None
4 changes: 3 additions & 1 deletion app/domain/data/feedback_dto.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Optional

from pydantic import BaseModel, Field


class FeedbackDTO(BaseModel):
text: str | None = None
text: Optional[str] = None
test_case_name: str = Field(alias="testCaseName")
credits: float

Expand Down
4 changes: 3 additions & 1 deletion app/domain/data/image_message_content_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

from pydantic import BaseModel, Field


class ImageMessageContentDTO(BaseModel):
image_data: str | None = Field(alias="imageData", default=None)
image_data: Optional[str] = Field(alias="imageData", default=None)
4 changes: 2 additions & 2 deletions app/domain/data/json_message_content_dto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, Field, Json
from typing import Any
from typing import Any, Optional


class JsonMessageContentDTO(BaseModel):
json_content: Json[Any] | None = Field(alias="jsonContent", default=None)
json_content: Optional[Json[Any]] = Field(alias="jsonContent", default=None)
5 changes: 3 additions & 2 deletions app/domain/data/lecture_unit_dto.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class LectureUnitDTO(BaseModel):
id: int
lecture_id: int = Field(alias="lectureId")
release_date: datetime | None = Field(alias="releaseDate", default=None)
name: str | None = None
release_date: Optional[datetime] = Field(alias="releaseDate", default=None)
name: Optional[str] = None
attachment_version: int = Field(alias="attachmentVersion")
6 changes: 3 additions & 3 deletions app/domain/data/programming_exercise_dto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Optional

from pydantic import BaseModel, Field
from datetime import datetime
Expand Down Expand Up @@ -26,5 +26,5 @@ class ProgrammingExerciseDTO(BaseModel):
solution_repository: Dict[str, str] = Field(alias="solutionRepository")
test_repository: Dict[str, str] = Field(alias="testRepository")
problem_statement: str = Field(alias="problemStatement")
start_date: datetime | None = Field(alias="startDate", default=None)
end_date: datetime | None = Field(alias="endDate", default=None)
start_date: Optional[datetime] = Field(alias="startDate", default=None)
end_date: Optional[datetime] = Field(alias="endDate", default=None)
6 changes: 3 additions & 3 deletions app/domain/data/submission_dto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict
from typing import List, Dict, Optional

from pydantic import BaseModel, Field

Expand All @@ -9,11 +9,11 @@

class SubmissionDTO(BaseModel):
id: int
date: datetime | None = None
date: Optional[datetime] = None
repository: Dict[str, str]
is_practice: bool = Field(alias="isPractice")
build_failed: bool = Field(alias="buildFailed")
build_log_entries: List[BuildLogEntryDTO] = Field(
alias="buildLogEntries", default=[]
)
latest_result: ResultDTO | None = Field(alias="latestResult", default=None)
latest_result: Optional[ResultDTO] = Field(alias="latestResult", default=None)
4 changes: 3 additions & 1 deletion app/domain/data/text_message_content_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

from pydantic import BaseModel, Field


class TextMessageContentDTO(BaseModel):
text_content: str | None = Field(alias="textContent", default=None)
text_content: Optional[str] = Field(alias="textContent", default=None)
6 changes: 4 additions & 2 deletions app/domain/data/user_dto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from pydantic import BaseModel, Field


class UserDTO(BaseModel):
id: int
first_name: str | None = Field(alias="firstName", default=None)
last_name: str | None = Field(alias="lastName", default=None)
first_name: Optional[str] = Field(alias="firstName", default=None)
last_name: Optional[str] = Field(alias="lastName", default=None)
13 changes: 0 additions & 13 deletions app/domain/health_status_dto.py

This file was deleted.

4 changes: 1 addition & 3 deletions app/domain/iris_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class IrisMessageRole(str, Enum):

class IrisMessage(BaseModel):
text: str = ""
role: Literal[
IrisMessageRole.USER, IrisMessageRole.ASSISTANT, IrisMessageRole.SYSTEM
]
role: IrisMessageRole

def __str__(self):
return f"{self.role.lower()}: {self.text}"
4 changes: 3 additions & 1 deletion app/domain/model_dto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from pydantic import BaseModel


class PyrisModelDTO(BaseModel):
id: str
name: str
description: str | None = None
description: Optional[str] = None
16 changes: 5 additions & 11 deletions app/domain/status/stage_dto.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from typing import Literal
from typing import Literal, Optional

from pydantic import BaseModel

from app.domain.status.stage_state_dto import StageStateDTO
from app.domain.status.stage_state_dto import StageStateEnum


class StageDTO(BaseModel):
name: str | None = None
name: Optional[str] = None
weight: int
state: Literal[
StageStateDTO.NOT_STARTED,
StageStateDTO.IN_PROGRESS,
StageStateDTO.DONE,
StageStateDTO.SKIPPED,
StageStateDTO.ERROR,
]
message: str | None = None
state: StageStateEnum
message: Optional[str] = None
2 changes: 1 addition & 1 deletion app/domain/status/stage_state_dto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum


class StageStateDTO(str, Enum):
class StageStateEnum(str, Enum):
NOT_STARTED = "NOT_STARTED"
IN_PROGRESS = "IN_PROGRESS"
DONE = "DONE"
Expand Down
6 changes: 3 additions & 3 deletions app/domain/tutor_chat/tutor_chat_pipeline_execution_dto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from pydantic import Field

Expand All @@ -11,8 +11,8 @@


class TutorChatPipelineExecutionDTO(PipelineExecutionDTO):
submission: SubmissionDTO | None = None
submission: Optional[SubmissionDTO] = None
exercise: ProgrammingExerciseDTO
course: CourseDTO
chat_history: List[MessageDTO] = Field(alias="chatHistory", default=[])
user: UserDTO | None = None
user: Optional[UserDTO] = None
4 changes: 3 additions & 1 deletion app/domain/tutor_chat/tutor_chat_status_update_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

from ...domain.status.status_update_dto import StatusUpdateDTO


class TutorChatStatusUpdateDTO(StatusUpdateDTO):
result: str | None = None
result: Optional[str] = None
2 changes: 0 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
from fastapi import FastAPI

from app.web.routers.health import router as health_router
from app.web.routers.models import router as models_router
from app.web.routers.pipelines import router as pipelines_router
from app.web.routers.webhooks import router as webhooks_router

app = FastAPI(default_response_class=ORJSONResponse)

app.include_router(health_router)
app.include_router(models_router)
app.include_router(pipelines_router)
app.include_router(webhooks_router)
14 changes: 7 additions & 7 deletions app/pipeline/chat/tutor_chat_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final_system_prompt,
guide_system_prompt,
)
from ...domain.status.stage_state_dto import StageStateDTO
from ...domain.status.stage_state_dto import StageStateEnum
from ...domain import TutorChatPipelineExecutionDTO
from ...domain.data.submission_dto import SubmissionDTO
from ...domain.data.message_dto import MessageDTO
Expand Down Expand Up @@ -104,7 +104,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="File lookup",
weight=10,
state=StageStateDTO.IN_PROGRESS,
state=StageStateEnum.IN_PROGRESS,
message="Looking up files in the repository...",
)
)
Expand All @@ -123,7 +123,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="File lookup",
weight=10,
state=StageStateDTO.DONE,
state=StageStateEnum.DONE,
message="Looked up files in the repository.",
)
)
Expand All @@ -133,7 +133,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="File lookup",
weight=10,
state=StageStateDTO.SKIPPED,
state=StageStateEnum.SKIPPED,
message=f"Failed to look up files in the repository: {e}",
)
)
Expand All @@ -152,7 +152,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="Response generation",
weight=10,
state=StageStateDTO.IN_PROGRESS,
state=StageStateEnum.IN_PROGRESS,
message="Generating response...",
)
)
Expand All @@ -178,7 +178,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="Response generation",
weight=10,
state=StageStateDTO.DONE,
state=StageStateEnum.DONE,
message="Generated response",
)
)
Expand All @@ -188,7 +188,7 @@ def __call__(self, dto: TutorChatPipelineExecutionDTO, **kwargs):
StageDTO(
name="Response generation",
weight=10,
state=StageStateDTO.ERROR,
state=StageStateEnum.ERROR,
message=f"Failed to generate response: {e}",
)
)
Expand Down
60 changes: 0 additions & 60 deletions app/web/data/repository_fetch.py

This file was deleted.

1 change: 0 additions & 1 deletion app/web/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ..routers.health import router as health_router
from ..routers.models import router as models_router
from ..routers.pipelines import router as pipelines_router
from ..routers.webhooks import router as webhooks_router
11 changes: 8 additions & 3 deletions app/web/routers/health.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from fastapi import APIRouter, status, Response
from fastapi import APIRouter, status, Response, Depends

from app.dependencies import TokenValidator

router = APIRouter(prefix="/api/v1/health", tags=["health"])


@router.get("/")
@router.get(
"/",
dependencies=[Depends(TokenValidator())],
)
def health_check():
return Response(status_code=status.HTTP_501_NOT_IMPLEMENTED)
return Response(status_code=status.HTTP_200_OK)
Loading

0 comments on commit f683132

Please sign in to comment.