---
# System prepended metadata

title: 2023-07-28 Easy Prompt
tags: [limit-lab, api]

---

The Easy Prompt

# Entity

```typescript
interface Prompt {
  id: UUID
  temperature: number,

  // 系统 prompt
  system: string,

  // AI 说的第一句话（欢迎用户的 prompt）
  greeting?: string,

  // 针对设定，添加一些预定义好的 prompt 到 system message 后面
  gender: "male" | "female",
  age: number,

  // 立绘 通过 stable-diffussion 生成
  cover: URL,
  name: string,
  description?: string,
  tags: Tag[] = []
    
  owner_id: string,
  created_at: DateTime,
  updated_at: DateTime,
}

type Role = "user" | "assistant" | "system"
```

# API

## Create model

`POST /easy-prompt`

### Request Body

```typescript
interface Request {
  temperature?: number = 0.5,
  system: string,
  greeting?: string,
  gender?: "male" | "female",
  age: number,
  name: string,
  description?: string,
  // tags: Tag[] = []
}
```

## Get Model

`GET /easy-prompt/{id}`

### Param

- `id(UUID)`: Easy prompt model ID

### Response Body

```typescript
interface Response {
  id: UUID
  temperature: number,
  system: string,
  greeting?: string,
  gender: "male" | "female" = "female",
  age: number,
  cover: URL,
  name: string,
  description?: string,
  owner_id: string,
  created_at: DateTime,
  updated_at: DateTime,
  tags: Tag[] = []
}
```

## Delete Model

`DELETE /easy-prompt/{id}`

### Param

- `id(UUID)`: Easy prompt model ID

### Response body

204 No Content

## Connect to session

`GET /easy-prompt/{prompt_id}/session/ -> WebSocket`

### Param

- `prompt_id(UUID)`: Easy prompt ID

### Description

- 连接后服务器发送 `SyncMessage` 用于同步历史消息
- 用户与服务器互相发送 `NormalMessage`
- 服务端如果出错，客户端显示相应信息并断开连接

```typescript
type Message =
 | SyncMessage // Server -> Client (todo)
 | NormalMessage // Server <-> Client
 | FinishMessage // Server -> Client
 | ErrorMessage // Server -> Client

interface SyncMessage {
 type: "sync"
 contents: Content[]
}

interface NormalMessage {
 type: "normal"
 content: Content
}

interface ErrorMessage {
 type: "error"
 error: string | string[]
}

interface FinishMessage {
 type: "finish"
}

type Content = AssistantContent | UserContent

interface AssistantContent {
 sender: "assistant",
 content: string
}

interface UserContent {
 sender: "user",
 content: string
}
```
