From 5c9af18aca87e65d0267de4d60e7d4303c398a36 Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Fri, 16 Dec 2022 09:31:42 +0100 Subject: [PATCH 1/2] added docstrings --- .vscode/settings.json | 3 +++ backend/app/schemas/protocol.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b7368caa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.formatting.provider": "black" +} diff --git a/backend/app/schemas/protocol.py b/backend/app/schemas/protocol.py index e72a7388..2a6609d4 100644 --- a/backend/app/schemas/protocol.py +++ b/backend/app/schemas/protocol.py @@ -34,18 +34,22 @@ class Task(BaseModel): class TaskResponse(BaseModel): - """A task response is a message from the frontend to acknowledge the given task.""" + """A task response is a message from the frontend to acknowledge that an initial piece of work has been done on the task.""" type: str status: Literal["success", "failure"] = "success" class PostCreatedTaskResponse(TaskResponse): + """The frontend signals to the backend that a post has been created.""" + type: Literal["post_created"] = "post_created" post_id: str class RatingCreatedTaskResponse(TaskResponse): + """The frontend signals to the backend that a rating input has been created for a given post.""" + type: Literal["rating_created"] = "rating_created" post_id: str @@ -57,6 +61,8 @@ AnyTaskResponse = Union[ class SummarizeStoryTask(Task): + """A task to summarize a story.""" + type: Literal["summarize_story"] = "summarize_story" story: str @@ -67,6 +73,8 @@ class RatingScale(BaseModel): class RateSummaryTask(Task): + """A task to rate a summary.""" + type: Literal["rate_summary"] = "rate_summary" full_text: str summary: str @@ -74,6 +82,8 @@ class RateSummaryTask(Task): class TaskDone(Task): + """Signals to the frontend that the task is done.""" + type: Literal["task_done"] = "task_done" reply_to_post_id: str @@ -102,7 +112,7 @@ class TextReplyToPost(Interaction): class PostRating(Interaction): - """A user has replied to a post with text.""" + """A user has rated a post.""" type: Literal["post_rating"] = "post_rating" post_id: str From 084668294bff7f697f13898ba41e58bd0f15a6e9 Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Fri, 16 Dec 2022 09:40:27 +0100 Subject: [PATCH 2/2] implemented asking for initial prompt --- backend/app/api/v1/tasks.py | 6 ++++++ backend/app/schemas/protocol.py | 11 +++++++++++ text-frontend/__main__.py | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/backend/app/api/v1/tasks.py b/backend/app/api/v1/tasks.py index 92ee9b8e..145ba4af 100644 --- a/backend/app/api/v1/tasks.py +++ b/backend/app/api/v1/tasks.py @@ -33,6 +33,11 @@ def generate_task(request: protocol_schema.TaskRequest) -> protocol_schema.Task: summary="This is a summary.", scale=protocol_schema.RatingScale(min=1, max=5), ) + case protocol_schema.TaskRequestType.initial_prompt: + logger.info("Generating an InitialPromptTask.") + task = protocol_schema.InitialPromptTask( + hint="Ask the assistant about a current event." # this is optional + ) case _: raise HTTPException( status_code=HTTP_400_BAD_REQUEST, @@ -123,6 +128,7 @@ def post_interaction( logger.info( f"Frontend reports rating of {interaction.post_id=} with {interaction.rating=} by {interaction.user=}." ) + # check if rating in range # here we would store the rating in the database return protocol_schema.TaskDone( reply_to_post_id=interaction.post_id, diff --git a/backend/app/schemas/protocol.py b/backend/app/schemas/protocol.py index 2a6609d4..6086bc4a 100644 --- a/backend/app/schemas/protocol.py +++ b/backend/app/schemas/protocol.py @@ -11,6 +11,7 @@ class TaskRequestType(str, enum.Enum): generic = "generic" summarize_story = "summarize_story" rate_summary = "rate_summary" + initial_prompt = "initial_prompt" class User(BaseModel): @@ -81,6 +82,15 @@ class RateSummaryTask(Task): scale: RatingScale = RatingScale(min=1, max=5) +class InitialPromptTask(Task): + """A task to prompt the user to submit an initial prompt to the assistant.""" + + type: Literal["initial_prompt"] = "initial_prompt" + hint: str | None = ( + None # provide a hint to the user to guide them a bit (i.e. "Ask the assistant to summarize something.") + ) + + class TaskDone(Task): """Signals to the frontend that the task is done.""" @@ -91,6 +101,7 @@ class TaskDone(Task): AnyTask = Union[ SummarizeStoryTask, RateSummaryTask, + InitialPromptTask, TaskDone, ] diff --git a/text-frontend/__main__.py b/text-frontend/__main__.py index 0029031f..d912fd60 100644 --- a/text-frontend/__main__.py +++ b/text-frontend/__main__.py @@ -64,6 +64,26 @@ def main(backend_url: str, api_key: str): }, ) tasks.append(new_task) + case "initial_prompt": + typer.echo("Please provide an initial prompt to the assistant.") + if task["hint"]: + typer.echo(f"Hint: {task['hint']}") + # acknowledge task + _post(f"/api/v1/tasks/{task['id']}/ack", {"type": "post_created", "post_id": "1234"}) + prompt = typer.prompt("Enter your prompt") + # send interaction + new_task = _post( + "/api/v1/tasks/interaction", + { + "type": "text_reply_to_post", + "post_id": "1234", + "user_post_id": "5678", + "text": prompt, + "user": {"id": "1234", "name": "John Doe"}, + }, + ) + tasks.append(new_task) + case "task_done": typer.echo("Task done!") case _: