Skip to content

Commit

Permalink
More cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem committed Nov 13, 2024
1 parent 208f732 commit 3d6ebe9
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 176 deletions.
40 changes: 20 additions & 20 deletions py/compose.full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ services:
image: pgvector/pgvector:pg16
profiles: [postgres]
environment:
- POSTGRES_USER=${R2R_POSTGRES_USER:-${POSTGRES_USER:-postgres}} # Eventually get rid of POSTGRES_USER, but for now keep it for backwards compatibility
- POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-${POSTGRES_PASSWORD:-postgres}} # Eventually get rid of POSTGRES_PASSWORD, but for now keep it for backwards compatibility
- POSTGRES_HOST=${R2R_POSTGRES_HOST:-${POSTGRES_HOST:-postgres}} # Eventually get rid of POSTGRES_HOST, but for now keep it for backwards compatibility
- POSTGRES_PORT=${R2R_POSTGRES_PORT:-${POSTGRES_PORT:-5432}} # Eventually get rid of POSTGRES_PORT, but for now keep it for backwards compatibility
- POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-${POSTGRES_MAX_CONNECTIONS:-1024}} # Eventually get rid of POSTGRES_MAX_CONNECTIONS, but for now keep it for backwards compatibility
- POSTGRES_USER=${R2R_POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-postgres}
- POSTGRES_HOST=${R2R_POSTGRES_HOST:-postgres}
- POSTGRES_PORT=${R2R_POSTGRES_PORT:-5432}
- POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-1024}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
Expand Down Expand Up @@ -274,30 +274,30 @@ services:
build:
context: .
args:
PORT: ${R2R_PORT:-${PORT:-7272}} # Eventually get rid of PORT, but for now keep it for backwards compatibility
PORT: ${R2R_PORT:-7272}
R2R_PORT: ${R2R_PORT:-${PORT:-7272}}
HOST: ${R2R_HOST:-${HOST:-0.0.0.0}} # Eventually get rid of HOST, but for now keep it for backwards compatibility
R2R_HOST: ${R2R_HOST:-${HOST:-0.0.0.0}}
HOST: ${R2R_HOST:-0.0.0.0}
R2R_HOST: ${R2R_HOST:-0.0.0.0}
ports:
- "${R2R_PORT:-${PORT:-7272}}:${R2R_PORT:-${PORT:-7272}}"
- "${R2R_PORT:-7272}:${R2R_PORT:-7272}"
environment:
- PYTHONUNBUFFERED=1
- R2R_PORT=${R2R_PORT:-${PORT:-7272}} # Eventually get rid of PORT, but for now keep it for backwards compatibility
- R2R_HOST=${R2R_HOST:-${HOST:-0.0.0.0}} # Eventually get rid of HOST, but for now keep it for backwards compatibility
- R2R_PORT=${R2R_PORT:-7272}
- R2R_HOST=${R2R_HOST:-0.0.0.0}

# R2R
- R2R_CONFIG_NAME=${R2R_CONFIG_NAME:-${CONFIG_NAME:-}} # Eventually get rid of CONFIG_NAME, but for now keep it for backwards compatibility
- R2R_CONFIG_PATH=${R2R_CONFIG_PATH:-${CONFIG_PATH:-}} # Eventually get rid of CONFIG_PATH, but for now keep it for backwards compatibility
- R2R_CONFIG_NAME=${R2R_CONFIG_NAME:-}
- R2R_CONFIG_PATH=${R2R_CONFIG_PATH:-}
- R2R_PROJECT_NAME=${R2R_PROJECT_NAME:-r2r_default}

# Postgres
- R2R_POSTGRES_USER=${R2R_POSTGRES_USER:-${POSTGRES_USER:-postgres}} # Eventually get rid of POSTGRES_USER, but for now keep it for backwards compatibility
- R2R_POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-${POSTGRES_PASSWORD:-postgres}} # Eventually get rid of POSTGRES_PASSWORD, but for now keep it for backwards compatibility
- R2R_POSTGRES_HOST=${R2R_POSTGRES_HOST:-${POSTGRES_HOST:-postgres}} # Eventually get rid of POSTGRES_HOST, but for now keep it for backwards compatibility
- R2R_POSTGRES_PORT=${R2R_POSTGRES_PORT:-${POSTGRES_PORT:-5432}} # Eventually get rid of POSTGRES_PORT, but for now keep it for backwards compatibility
- R2R_POSTGRES_DBNAME=${R2R_POSTGRES_DBNAME:-${POSTGRES_DBNAME:-postgres}} # Eventually get rid of POSTGRES_DBNAME, but for now keep it for backwards compatibility
- R2R_POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-${POSTGRES_MAX_CONNECTIONS:-1024}} # Eventually get rid of POSTGRES_MAX_CONNECTIONS, but for now keep it for backwards compatibility
- R2R_POSTGRES_PROJECT_NAME=${R2R_POSTGRES_PROJECT_NAME:-${POSTGRES_PROJECT_NAME:-r2r_default}} # Eventually get rid of POSTGRES_PROJECT_NAME, but for now keep it for backwards compatibility
- R2R_POSTGRES_USER=${R2R_POSTGRES_USER:-postgres}
- R2R_POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-postgres}
- R2R_POSTGRES_HOST=${R2R_POSTGRES_HOST:-postgres}
- R2R_POSTGRES_PORT=${R2R_POSTGRES_PORT:-5432}
- R2R_POSTGRES_DBNAME=${R2R_POSTGRES_DBNAME:-postgres}
- R2R_POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-1024}
- R2R_POSTGRES_PROJECT_NAME=${R2R_POSTGRES_PROJECT_NAME:-r2r_default}

# OpenAI
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
Expand Down
42 changes: 21 additions & 21 deletions py/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ services:
image: pgvector/pgvector:pg16
profiles: [postgres]
environment:
- POSTGRES_USER=${R2R_POSTGRES_USER:-${POSTGRES_USER:-postgres}} # Eventually get rid of POSTGRES_USER, but for now keep it for backwards compatibility
- POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-${POSTGRES_PASSWORD:-postgres}} # Eventually get rid of POSTGRES_PASSWORD, but for now keep it for backwards compatibility
- POSTGRES_HOST=${R2R_POSTGRES_HOST:-${POSTGRES_HOST:-postgres}} # Eventually get rid of POSTGRES_HOST, but for now keep it for backwards compatibility
- POSTGRES_PORT=${R2R_POSTGRES_PORT:-${POSTGRES_PORT:-5432}} # Eventually get rid of POSTGRES_PORT, but for now keep it for backwards compatibility
- POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-${POSTGRES_MAX_CONNECTIONS:-1024}} # Eventually get rid of POSTGRES_MAX_CONNECTIONS, but for now keep it for backwards compatibility
- POSTGRES_USER=${R2R_POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-postgres}
- POSTGRES_HOST=${R2R_POSTGRES_HOST:-postgres}
- POSTGRES_PORT=${R2R_POSTGRES_PORT:-5432}
- POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-1024}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
Expand All @@ -40,30 +40,30 @@ services:
build:
context: .
args:
PORT: ${R2R_PORT:-${PORT:-7272}} # Eventually get rid of PORT, but for now keep it for backwards compatibility
R2R_PORT: ${R2R_PORT:-${PORT:-7272}}
HOST: ${R2R_HOST:-${HOST:-0.0.0.0}} # Eventually get rid of HOST, but for now keep it for backwards compatibility
R2R_HOST: ${R2R_HOST:-${HOST:-0.0.0.0}}
PORT: ${R2R_PORT:-7272}
R2R_PORT: ${R2R_PORT:-7272}
HOST: ${R2R_HOST:-0.0.0.0}
R2R_HOST: ${R2R_HOST:-0.0.0.0}
ports:
- "${R2R_PORT:-${PORT:-7272}}:${R2R_PORT:-${PORT:-7272}}"
- "${R2R_PORT:-7272}:${R2R_PORT:-7272}"
environment:
- PYTHONUNBUFFERED=1
- R2R_PORT=${R2R_PORT:-${PORT:-7272}} # Eventually get rid of PORT, but for now keep it for backwards compatibility
- R2R_HOST=${R2R_HOST:-${HOST:-0.0.0.0}} # Eventually get rid of HOST, but for now keep it for backwards compatibility
- R2R_PORT=${R2R_PORT:-7272}
- R2R_HOST=${R2R_HOST:-0.0.0.0}

# R2R
- R2R_CONFIG_NAME=${R2R_CONFIG_NAME:-${CONFIG_NAME:-}} # Eventually get rid of CONFIG_NAME, but for now keep it for backwards compatibility
- R2R_CONFIG_PATH=${R2R_CONFIG_PATH:-${CONFIG_PATH:-}} # Eventually get rid of CONFIG_PATH, but for now keep it for backwards compatibility
- R2R_CONFIG_NAME=${R2R_CONFIG_NAME:--}
- R2R_CONFIG_PATH=${R2R_CONFIG_PATH:--}
- R2R_PROJECT_NAME=${R2R_PROJECT_NAME:-r2r_default}

# Postgres
- R2R_POSTGRES_USER=${R2R_POSTGRES_USER:-${POSTGRES_USER:-postgres}} # Eventually get rid of POSTGRES_USER, but for now keep it for backwards compatibility
- R2R_POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-${POSTGRES_PASSWORD:-postgres}} # Eventually get rid of POSTGRES_PASSWORD, but for now keep it for backwards compatibility
- R2R_POSTGRES_HOST=${R2R_POSTGRES_HOST:-${POSTGRES_HOST:-postgres}} # Eventually get rid of POSTGRES_HOST, but for now keep it for backwards compatibility
- R2R_POSTGRES_PORT=${R2R_POSTGRES_PORT:-${POSTGRES_PORT:-5432}} # Eventually get rid of POSTGRES_PORT, but for now keep it for backwards compatibility
- R2R_POSTGRES_DBNAME=${R2R_POSTGRES_DBNAME:-${POSTGRES_DBNAME:-postgres}} # Eventually get rid of POSTGRES_DBNAME, but for now keep it for backwards compatibility
- R2R_POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-${POSTGRES_MAX_CONNECTIONS:-1024}} # Eventually get rid of POSTGRES_MAX_CONNECTIONS, but for now keep it for backwards compatibility
- R2R_POSTGRES_PROJECT_NAME=${R2R_POSTGRES_PROJECT_NAME:-${POSTGRES_PROJECT_NAME:-r2r_default}} # Eventually get rid of POSTGRES_PROJECT_NAME, but for now keep it for backwards compatibility
- R2R_POSTGRES_USER=${R2R_POSTGRES_USER:-postgres}
- R2R_POSTGRES_PASSWORD=${R2R_POSTGRES_PASSWORD:-postgres}
- R2R_POSTGRES_HOST=${R2R_POSTGRES_HOST:-postgres}
- R2R_POSTGRES_PORT=${R2R_POSTGRES_PORT:-5432}
- R2R_POSTGRES_DBNAME=${R2R_POSTGRES_DBNAME:-postgres}
- R2R_POSTGRES_MAX_CONNECTIONS=${R2R_POSTGRES_MAX_CONNECTIONS:-1024}
- R2R_POSTGRES_PROJECT_NAME=${R2R_POSTGRES_PROJECT_NAME:-r2r_default}

# OpenAI
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
Expand Down
33 changes: 13 additions & 20 deletions py/core/base/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
)
from shared.api.models.auth.responses import (
TokenResponse,
UserResponse,
WrappedTokenResponse,
WrappedUserResponse,
)
from shared.api.models.ingestion.responses import (
IngestionResponse,
Expand Down Expand Up @@ -40,13 +38,12 @@
AppSettingsResponse,
CollectionResponse,
ConversationResponse,
DocumentChunkResponse,
ChunkResponse,
UserResponse,
LogResponse,
PromptResponse,
ScoreCompletionResponse,
ServerStats,
UserOverviewResponse,
WrappedAddUserResponse,
WrappedAnalyticsResponse,
WrappedAppSettingsResponse,
WrappedCollectionResponse,
Expand All @@ -61,18 +58,18 @@
WrappedPromptResponse,
WrappedPromptsResponse,
WrappedLogResponse,
WrappedPromptMessageResponse,
# Chunk Responses
WrappedDocumentChunkResponse,
WrappedDocumentChunksResponse,
WrappedChunkResponse,
WrappedChunksResponse,
# Conversation Responses
WrappedMessageResponse,
WrappedMessagesResponse,
WrappedBranchResponse,
WrappedBranchesResponse,
# User Responses
WrappedUserOverviewResponse,
WrappedUsersOverviewResponse,
WrappedUserResponse,
WrappedUsersResponse,
# TODO: anything below this hasn't been reviewed
WrappedServerStatsResponse,
WrappedUserCollectionResponse,
WrappedUsersInCollectionResponse,
Expand All @@ -93,9 +90,7 @@
__all__ = [
# Auth Responses
"TokenResponse",
"UserResponse",
"WrappedTokenResponse",
"WrappedUserResponse",
"WrappedVerificationResult",
"WrappedGenericMessageResponse",
# Ingestion Responses
Expand Down Expand Up @@ -123,10 +118,8 @@
"AnalyticsResponse",
"AppSettingsResponse",
"ScoreCompletionResponse",
"UserOverviewResponse",
"DocumentChunkResponse",
"ChunkResponse",
"CollectionResponse",
"WrappedPromptMessageResponse",
"WrappedServerStatsResponse",
"WrappedLogResponse",
"WrappedAnalyticsResponse",
Expand All @@ -135,7 +128,6 @@
"WrappedDocumentsResponse",
"WrappedCollectionResponse",
"WrappedCollectionsResponse",
"WrappedAddUserResponse",
"WrappedUsersInCollectionResponse",
# Conversation Responses
"ConversationResponse",
Expand All @@ -150,11 +142,12 @@
"WrappedBranchResponse",
"WrappedBranchesResponse",
# Chunk Responses
"WrappedDocumentChunkResponse",
"WrappedDocumentChunksResponse",
"WrappedChunkResponse",
"WrappedChunksResponse",
# User Responses
"WrappedUserOverviewResponse",
"WrappedUsersOverviewResponse",
"UserResponse",
"WrappedUserResponse",
"WrappedUsersResponse",
# Base Responses
"PaginatedResultsWrapper",
"ResultsWrapper",
Expand Down
32 changes: 17 additions & 15 deletions py/core/main/api/v2/management_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@

from core.base import Message, R2RException
from core.base.api.models import (
WrappedAddUserResponse,
WrappedBooleanResponse,
GenericMessageResponse,
WrappedAnalyticsResponse,
WrappedAppSettingsResponse,
WrappedCollectionResponse,
WrappedCollectionsResponse,
WrappedConversationResponse,
WrappedConversationsResponse,
WrappedDeleteResponse,
WrappedDocumentChunksResponse,
WrappedChunksResponse,
WrappedGenericMessageResponse,
WrappedBooleanResponse,
WrappedDocumentsResponse,
WrappedPromptsResponse,
WrappedLogResponse,
WrappedPromptMessageResponse,
WrappedServerStatsResponse,
WrappedUserCollectionResponse,
WrappedUsersOverviewResponse,
WrappedUsersResponse,
WrappedUsersInCollectionResponse,
)
from core.base.logger import AnalysisTypes, LogFilterCriteria
Expand Down Expand Up @@ -91,7 +93,7 @@ async def update_prompt_app(
{}, description="Input types"
),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedPromptMessageResponse:
) -> WrappedGenericMessageResponse:
if not auth_user.is_superuser:
raise R2RException(
"Only a superuser can call the `update_prompt` endpoint.",
Expand All @@ -101,7 +103,7 @@ async def update_prompt_app(
result = await self.service.update_prompt(
name, template, input_types
)
return result # type: ignore
return GenericMessageResponse(message=result)

@self.router.post("/add_prompt")
@self.base_endpoint
Expand All @@ -110,14 +112,14 @@ async def add_prompt_app(
template: str = Body(..., description="Prompt template"),
input_types: dict[str, str] = Body({}, description="Input types"),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedPromptMessageResponse:
) -> WrappedGenericMessageResponse:
if not auth_user.is_superuser:
raise R2RException(
"Only a superuser can call the `add_prompt` endpoint.",
403,
)
result = await self.service.add_prompt(name, template, input_types)
return result # type: ignore
return GenericMessageResponse(message=result)

@self.router.get("/get_prompt/{prompt_name}")
@self.base_endpoint
Expand All @@ -130,7 +132,7 @@ async def get_prompt_app(
None, description="Prompt override"
),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedPromptMessageResponse:
) -> WrappedGenericMessageResponse:
if not auth_user.is_superuser:
raise R2RException(
"Only a superuser can call the `get_prompt` endpoint.",
Expand All @@ -139,7 +141,7 @@ async def get_prompt_app(
result = await self.service.get_cached_prompt(
prompt_name, inputs, prompt_override
)
return result # type: ignore
return GenericMessageResponse(message=result)

@self.router.get("/get_all_prompts")
@self.base_endpoint
Expand Down Expand Up @@ -236,7 +238,7 @@ async def users_overview_app(
offset: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedUsersOverviewResponse:
) -> WrappedUsersResponse:
if not auth_user.is_superuser:
raise R2RException(
"Only a superuser can call the `users_overview` endpoint.",
Expand Down Expand Up @@ -373,7 +375,7 @@ async def document_chunks_app(
limit: Optional[int] = Query(100, ge=0),
include_vectors: Optional[bool] = Query(False),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedDocumentChunksResponse:
) -> WrappedChunksResponse:
document_uuid = UUID(document_id)

document_chunks = await self.service.list_document_chunks(
Expand Down Expand Up @@ -431,7 +433,7 @@ async def document_chunks_app(
limit: Optional[int] = Query(100, ge=0),
include_vectors: Optional[bool] = Query(False),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedDocumentChunksResponse:
) -> WrappedChunksResponse:
document_uuid = UUID(document_id)

list_document_chunks = await self.service.list_document_chunks(
Expand Down Expand Up @@ -627,7 +629,7 @@ async def add_user_to_collection_app(
user_id: str = Body(..., description="User ID"),
collection_id: str = Body(..., description="Collection ID"),
auth_user=Depends(self.service.providers.auth.auth_wrapper),
) -> WrappedAddUserResponse:
) -> WrappedBooleanResponse:
collection_uuid = UUID(collection_id)
user_uuid = UUID(user_id)
if (
Expand All @@ -642,7 +644,7 @@ async def add_user_to_collection_app(
result = await self.service.add_user_to_collection(
user_uuid, collection_uuid
)
return result # type: ignore
return WrappedBooleanResponse(result=result)

@self.router.post("/remove_user_from_collection")
@self.base_endpoint
Expand Down
Loading

0 comments on commit 3d6ebe9

Please sign in to comment.