-
Notifications
You must be signed in to change notification settings - Fork 0
codepushed for review by korbit #4
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Missing field examples in Pydantic models ▹ view | ||
| Missing UUID field example and description ▹ view | ||
| Missing examples in Character model ▹ view | ||
| Singleton pattern violates FastAPI session scoping policy ▹ view | ||
| Missing type annotation for _instances attribute ▹ view | ||
| Missing type annotations for call method parameters and return type ▹ view | ||
| Missing type annotations for call method parameter and return type ▹ view | ||
| Dependency function bypasses FastAPI injection ▹ view | ||
| Heavy dependencies loaded at module scope ▹ view | ||
| Missing traceparent header in HTTP request ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| korbit_review/app/models/init.py | ✅ |
| korbit_review/app/redis.py | ✅ |
| korbit_review/app/api/ml.py | ✅ |
| korbit_review/app/api/shakespeare.py | ✅ |
| korbit_review/app/schemas/shakespeare.py | ✅ |
| korbit_review/app/utils/singleton.py | ✅ |
| korbit_review/app/database.py | ✅ |
| korbit_review/app/schemas/nnonsense.py | ✅ |
| korbit_review/app/models/nonsense.py | ✅ |
| korbit_review/app/schemas/stuff.py | ✅ |
| korbit_review/app/models/user.py | ✅ |
| korbit_review/app/utils/decorators.py | ✅ |
| korbit_review/app/services/scheduler.py | ✅ |
| korbit_review/app/exceptions.py | ✅ |
| korbit_review/app/api/user.py | ✅ |
| korbit_review/app/schemas/user.py | ✅ |
| korbit_review/app/models/stuff.py | ✅ |
| korbit_review/app/services/llm.py | ✅ |
| korbit_review/app/services/auth.py | ✅ |
| korbit_review/app/models/base.py | ✅ |
| korbit_review/app/utils/logging.py | ✅ |
| korbit_review/app/main.py | ✅ |
| korbit_review/app/api/health.py | ✅ |
| korbit_review/app/config.py | ✅ |
| korbit_review/app/api/stuff.py | ✅ |
| korbit_review/app/api/nonsense.py | ✅ |
| korbit_review/app/services/smtp.py | ✅ |
| korbit_review/app/models/shakespeare.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| name: str = Field( | ||
| title="", | ||
| description="", | ||
| ) | ||
| description: str = Field( | ||
| title="", | ||
| description="", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing field examples in Pydantic models 
Tell me more
What is the issue?
Pydantic model fields lack examples in both NonsenseSchema and NonsenseResponse classes.
View the policy behind this issue
Why this matters
Without examples, API consumers cannot understand expected data formats, and mock server generation becomes inaccurate, reducing API adoption speed.
Suggested change ∙ Feature Preview
Add examples to Field definitions or use Config.schema_extra. For instance:
name: str = Field(
title="Name",
description="The name of the nonsense item",
example="Example Nonsense Name"
)Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| id: UUID = Field( | ||
| title="Id", | ||
| description="", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing UUID field example and description 
Tell me more
What is the issue?
The id field in NonsenseResponse has an empty description parameter and lacks an example.
View the policy behind this issue
Why this matters
Empty field metadata fails to demonstrate valid UUID formats to API consumers, which is required by the policy for all Pydantic models.
Suggested change ∙ Feature Preview
Provide a meaningful description and example for the UUID field:
id: UUID = Field(
title="Id",
description="Unique identifier for the nonsense item",
example="3fa85f64-5717-4562-b3fc-2c963f66afa6"
)Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| class Character(BaseModel): | ||
| id: str | ||
| abbrev: str | ||
| speech_count: int | ||
| name: str | ||
| description: Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing examples in Character model 
Tell me more
What is the issue?
The Character model lacks examples for its fields using Field(example=...) or Config.schema_extra.
View the policy behind this issue
Why this matters
Without examples, API documentation will not provide sample values, making it harder for developers to understand expected data formats and hindering mock server generation.
Suggested change ∙ Feature Preview
Add Field examples or Config.schema_extra to provide sample values:
class Character(BaseModel):
id: str = Field(example="hamlet")
abbrev: str = Field(example="HAM")
speech_count: int = Field(example=42)
name: str = Field(example="Hamlet")
description: Any = Field(example="Prince of Denmark")Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| class SingletonMetaNoArgs(type): | ||
| """ | ||
| Singleton metaclass for classes without parameters on constructor, | ||
| for compatibility with FastApi Depends() function. | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Singleton pattern violates FastAPI session scoping policy 
Tell me more
What is the issue?
The singleton metaclass is designed to create global singletons that would be used with FastAPI's Depends() function, which violates the requirement that database sessions must never be global singletons.
View the policy behind this issue
Why this matters
Using singletons for database sessions in FastAPI creates connection leaks and race conditions since sessions would be shared across requests instead of being request-scoped with proper cleanup.
Suggested change ∙ Feature Preview
Remove the singleton metaclasses and use yield-based dependencies with Depends() that create request-scoped sessions with proper cleanup instead of global singletons.
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| This is a thread-safe implementation of Singleton. | ||
| """ | ||
|
|
||
| _instances = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing type annotation for _instances attribute 
Tell me more
What is the issue?
Class attribute _instances in both singleton metaclasses lacks explicit type annotation.
View the policy behind this issue
Why this matters
Missing type annotations reduce code maintainability, readability, and prevent effective static analysis. The policy requires all class attributes to have explicit type annotations.
Suggested change ∙ Feature Preview
Add type annotation: _instances: Dict[type, Any] = {} and import the required types from typing module.
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
|
|
||
| _lock: Lock = Lock() | ||
|
|
||
| def __call__(cls, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing type annotations for call method parameters and return type 
Tell me more
What is the issue?
Method __call__ in SingletonMeta lacks type annotations for parameters and return type.
View the policy behind this issue
Why this matters
Missing type annotations reduce code maintainability, readability, and prevent effective static analysis. The policy requires all methods to have explicit type annotations for parameters and return types.
Suggested change ∙ Feature Preview
Add type annotations: def __call__(cls: Type[T], *args: Any, **kwargs: Any) -> T: with appropriate imports for Type, T (TypeVar), and Any.
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
|
|
||
| _lock: Lock = Lock() | ||
|
|
||
| def __call__(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing type annotations for call method parameter and return type 
Tell me more
What is the issue?
Method __call__ in SingletonMetaNoArgs lacks type annotations for parameter and return type.
View the policy behind this issue
Why this matters
Missing type annotations reduce code maintainability, readability, and prevent effective static analysis. The policy requires all methods to have explicit type annotations for parameters and return types.
Suggested change ∙ Feature Preview
Add type annotations: def __call__(cls: Type[T]) -> T: with appropriate imports for Type and T (TypeVar).
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| def get_llm_service(base_url: str | None = None) -> StreamLLMService: | ||
| return StreamLLMService(base_url=base_url or "http://localhost:11434/v1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependency function bypasses FastAPI injection 
Tell me more
What is the issue?
The dependency function accepts parameters directly instead of using FastAPI's Depends mechanism for injection.
View the policy behind this issue
Why this matters
This approach prevents proper dependency injection and makes the code less modular and testable. Dependencies should be injected through FastAPI's Depends system rather than passed as direct parameters.
Suggested change ∙ Feature Preview
Refactor to use proper dependency injection pattern. Create separate functions for configuration injection:
from fastapi import Depends
def get_base_url() -> str:
return "http://localhost:11434/v1"
def get_llm_service(base_url: str = Depends(get_base_url)) -> StreamLLMService:
return StreamLLMService(base_url=base_url)Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| import httpx | ||
| import orjson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heavy dependencies loaded at module scope 
Tell me more
What is the issue?
Heavy dependencies httpx and orjson are imported at module scope instead of being loaded lazily within functions or dependency providers.
View the policy behind this issue
Why this matters
Loading these dependencies at module import time increases container image loading overhead and may cause unnecessary initialization side effects even when the LLM service is not used.
Suggested change ∙ Feature Preview
Move the imports inside the methods or dependency functions where they are actually used:
async def stream_chat(self, prompt: str) -> AsyncGenerator[bytes]:
import httpx
import orjson
# ... rest of method
def get_llm_service(base_url: str | None = None) -> StreamLLMService:
import httpx
import orjson
return StreamLLMService(base_url=base_url or "http://localhost:11434/v1")Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| async with httpx.AsyncClient(base_url=self.base_url) as client: | ||
| async with client.stream( | ||
| "POST", | ||
| "/chat/completions", | ||
| json={ | ||
| "model": self.model, | ||
| "messages": [{"role": "user", "content": prompt}], | ||
| "stream": True, | ||
| }, | ||
| timeout=60.0, | ||
| ) as response: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing traceparent header in HTTP request 
Tell me more
What is the issue?
The HTTP request to the LLM service does not include the W3C "traceparent" header with current trace and span IDs.
View the policy behind this issue
Why this matters
Without the traceparent header, distributed tracing tools cannot link this outbound HTTP request to its originating trace, breaking the observability chain across services.
Suggested change ∙ Feature Preview
Accept trace context as a parameter and include the traceparent header in the HTTP request:
async def stream_chat(self, prompt: str, trace_ctx: dict) -> AsyncGenerator[bytes]:
traceparent = f"00-{trace_ctx['trace_id']}-{trace_ctx['span_id']}-01"
async with httpx.AsyncClient(base_url=self.base_url) as client:
async with client.stream(
"POST",
"/chat/completions",
json={...},
headers={"traceparent": traceparent},
timeout=60.0,
) as response:Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
Description by Korbit AI
What change is being made?
Add comprehensive FastAPI endpoints for various services including health checks, email functionalities via SMTP, LLM streaming responses, user authentication, Shakespeare dataset retrieval, and handling "stuff" and "nonsense" data operations, along with configuration and utility enhancements.
Why are these changes being made?
These changes are being introduced to build a robust API that provides multiple functionalities including health and email check endpoints, database operations on "stuff" and "nonsense" data, conversational AI capabilities, and secure user management. This approach leverages FastAPI's asynchronous features for better performance and scalability in handling concurrent requests, particularly for resource-intensive operations like SMTP and database interactions. Additionally, configurations and utility functions are included to foster easier management and enhance modularity, maintainability, and ease of integrating future features.