mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-12 00:40:07 +08:00
implemented asking for initial prompt
This commit is contained in:
@@ -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):
|
||||
@@ -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,
|
||||
]
|
||||
|
||||
|
||||
@@ -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