Skip to content

Commit

Permalink
add docstrings to all endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretiveShell committed Sep 29, 2024
1 parent 93203ef commit 3e1ef55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 8 additions & 3 deletions endpoints/Kobold/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@


api_name = "KoboldAI"
router = APIRouter(prefix="/api")
router = APIRouter(prefix="/api", tags=[Tags.Kobold])
urls = {
"Generation": "http://{host}:{port}/api/v1/generate",
"Streaming": "http://{host}:{port}/api/extra/generate/stream",
}

kai_router = APIRouter()
extra_kai_router = APIRouter()
kai_router = APIRouter(tags=[Tags.Kobold])
extra_kai_router = APIRouter(tags=[Tags.Kobold])


def setup():
Expand All @@ -50,6 +50,7 @@ def setup():
tags=[Tags.Kobold],
)
async def generate(request: Request, data: GenerateRequest) -> GenerateResponse:
"""Generate a response to a prompt."""
response = await get_generation(data, request)

return response
Expand All @@ -61,6 +62,7 @@ async def generate(request: Request, data: GenerateRequest) -> GenerateResponse:
tags=[Tags.Kobold],
)
async def generate_stream(request: Request, data: GenerateRequest) -> GenerateResponse:
"""Stream the chat response to a prompt."""
response = EventSourceResponse(stream_generation(data, request), ping=maxsize)

return response
Expand All @@ -72,6 +74,7 @@ async def generate_stream(request: Request, data: GenerateRequest) -> GenerateRe
tags=[Tags.Kobold],
)
async def abort_generate(data: AbortRequest) -> AbortResponse:
"""Aborts a generation from the cache."""
response = await abort_generation(data.genkey)

return response
Expand All @@ -88,6 +91,7 @@ async def abort_generate(data: AbortRequest) -> AbortResponse:
tags=[Tags.Kobold],
)
async def check_generate(data: CheckGenerateRequest) -> GenerateResponse:
"""Fetches the status of a generation from the cache."""
response = await generation_status(data.genkey)

return response
Expand All @@ -111,6 +115,7 @@ async def current_model() -> CurrentModelResponse:
tags=[Tags.Kobold],
)
async def get_tokencount(data: TokenCountRequest) -> TokenCountResponse:
"""Get the number of tokens in a given prompt."""
raw_tokens = model.container.encode_tokens(data.prompt)
tokens = unwrap(raw_tokens, [])
return TokenCountResponse(value=len(tokens), ids=tokens)
Expand Down
6 changes: 5 additions & 1 deletion endpoints/OAI/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


api_name = "OAI"
router = APIRouter()
router = APIRouter(tags=[Tags.OpenAI])
urls = {
"Completions": "http://{host}:{port}/v1/completions",
"Chat completions": "http://{host}:{port}/v1/chat/completions",
Expand Down Expand Up @@ -158,6 +158,10 @@ async def chat_completion_request(
tags=[Tags.OpenAI],
)
async def embeddings(request: Request, data: EmbeddingsRequest) -> EmbeddingsResponse:
"""Generate Text embeddings for a given text input.
Requires Infinity embed to be installed and an embedding model to be loaded.
"""
embeddings_task = asyncio.create_task(get_embeddings(data, request))
response = await run_with_request_disconnect(
request,
Expand Down
2 changes: 2 additions & 0 deletions endpoints/core/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ async def get_embedding_model() -> ModelCard:
async def load_embedding_model(
request: Request, data: EmbeddingModelLoadRequest
) -> ModelLoadResponse:
"""Loads an embedding model."""

# Verify request parameters
if not data.name:
error_message = handle_request_error(
Expand Down

0 comments on commit 3e1ef55

Please sign in to comment.