mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-16 01:10:06 +08:00
Merge branch 'main' of github.com:LAION-AI/Open-Chat-GPT into main
This commit is contained in:
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.formatting.provider": "black"
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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):
|
||||
@@ -34,18 +35,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 +62,8 @@ AnyTaskResponse = Union[
|
||||
|
||||
|
||||
class SummarizeStoryTask(Task):
|
||||
"""A task to summarize a story."""
|
||||
|
||||
type: Literal["summarize_story"] = "summarize_story"
|
||||
story: str
|
||||
|
||||
@@ -67,13 +74,26 @@ class RatingScale(BaseModel):
|
||||
|
||||
|
||||
class RateSummaryTask(Task):
|
||||
"""A task to rate a summary."""
|
||||
|
||||
type: Literal["rate_summary"] = "rate_summary"
|
||||
full_text: str
|
||||
summary: str
|
||||
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."""
|
||||
|
||||
type: Literal["task_done"] = "task_done"
|
||||
reply_to_post_id: str
|
||||
|
||||
@@ -81,6 +101,7 @@ class TaskDone(Task):
|
||||
AnyTask = Union[
|
||||
SummarizeStoryTask,
|
||||
RateSummaryTask,
|
||||
InitialPromptTask,
|
||||
TaskDone,
|
||||
]
|
||||
|
||||
@@ -102,7 +123,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
|
||||
|
||||
@@ -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 _:
|
||||
|
||||
Reference in New Issue
Block a user