Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
chore(docs): Add documentation to types (#680)
Browse files Browse the repository at this point in the history
Adds documentation to the request endpoint types that can be seen at the `/redoc` endpoint
  • Loading branch information
CollectiveUnicorn authored Jul 3, 2024
1 parent ef7e098 commit 9f7f68b
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 113 deletions.
6 changes: 4 additions & 2 deletions src/leapfrogai_api/backend/grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def stream_completion(model: Model, request: lfai.CompletionRequest):

await stream.wait_for_connection()
return StreamingResponse(
recv_completion(stream), media_type="text/event-stream"
recv_completion(stream, model.name), media_type="text/event-stream"
)


Expand Down Expand Up @@ -66,7 +66,9 @@ async def stream_chat_completion(model: Model, request: lfai.ChatCompletionReque
stream = stub.ChatCompleteStream(request)

await stream.wait_for_connection()
return StreamingResponse(recv_chat(stream), media_type="text/event-stream")
return StreamingResponse(
recv_chat(stream, model.name), media_type="text/event-stream"
)


async def stream_chat_completion_raw(
Expand Down
16 changes: 10 additions & 6 deletions src/leapfrogai_api/backend/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Helper functions for the OpenAI backend."""

import time
import uuid
from typing import BinaryIO, Iterator, AsyncGenerator, Any
import grpc
import leapfrogai_sdk as lfai
Expand All @@ -15,15 +17,16 @@

async def recv_completion(
stream: grpc.aio.UnaryStreamCall[lfai.CompletionRequest, lfai.CompletionResponse],
model: str,
):
async for c in stream:
yield (
"data: "
+ CompletionResponse(
id="foo",
id=str(uuid.uuid4()),
object="completion.chunk",
created=55,
model="mpt-7b-8k-chat",
created=int(time.time()),
model=model,
choices=[
CompletionChoice(
index=0,
Expand All @@ -48,16 +51,17 @@ async def recv_chat(
stream: grpc.aio.UnaryStreamCall[
lfai.ChatCompletionRequest, lfai.ChatCompletionResponse
],
model: str,
) -> AsyncGenerator[str, Any]:
"""Generator that yields chat completion responses as Server-Sent Events."""
async for c in stream:
yield (
"data: "
+ ChatCompletionResponse(
id="foo",
id=str(uuid.uuid4()),
object="chat.completion.chunk",
created=55,
model="mpt-7b-8k-chat",
created=int(time.time()),
model=model,
choices=[
ChatStreamChoice(
index=0,
Expand Down
Loading

0 comments on commit 9f7f68b

Please sign in to comment.