diff options
| author | Pablo Fernandez <p@f7z.io> | 2023-11-23 17:52:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-23 17:52:48 +0200 |
| commit | 60256a62675a165c4d4fd9811a19a9cbf6a9e7fd (patch) | |
| tree | 5c450154d373caafc37f324dd01e20338308c9d6 /90.md | |
| parent | 43d50ee42409252a1313928cd437d55fd7bf7bf4 (diff) | |
| parent | 7822a8b12670312aff104ddc03066425882f739d (diff) | |
Merge branch 'master' into nip88
Diffstat (limited to '90.md')
| -rw-r--r-- | 90.md | 141 |
1 files changed, 100 insertions, 41 deletions
| @@ -4,7 +4,7 @@ NIP-90 | |||
| 4 | Data Vending Machine | 4 | Data Vending Machine |
| 5 | -------------------- | 5 | -------------------- |
| 6 | 6 | ||
| 7 | `draft` `optional` `author:pablof7z` `author:dontbelievethehype` | 7 | `draft` `optional` |
| 8 | 8 | ||
| 9 | This NIP defines the interaction between customers and Service Providers for performing on-demand computation. | 9 | This NIP defines the interaction between customers and Service Providers for performing on-demand computation. |
| 10 | 10 | ||
| @@ -13,11 +13,11 @@ Money in, data out. | |||
| 13 | ## Kinds | 13 | ## Kinds |
| 14 | This NIP reserves the range `5000-7000` for data vending machine use. | 14 | This NIP reserves the range `5000-7000` for data vending machine use. |
| 15 | 15 | ||
| 16 | | Kind | Description | | 16 | | Kind | Description | |
| 17 | | ---- | ----------- | | 17 | | ---- | ----------- | |
| 18 | | 5000-5999 | Job request kinds | | 18 | | 5000-5999 | Job request kinds | |
| 19 | | 6000-6999 | Job result | | 19 | | 6000-6999 | Job result | |
| 20 | | 7000 | Job feedback | | 20 | | 7000 | Job feedback | |
| 21 | 21 | ||
| 22 | Job results always use a kind number that is `1000` higher than the job request kind. (e.g. request: `kind:5001` gets a result: `kind:6001`). | 22 | Job results always use a kind number that is `1000` higher than the job request kind. (e.g. request: `kind:5001` gets a result: `kind:6001`). |
| 23 | 23 | ||
| @@ -67,22 +67,54 @@ All tags are optional. | |||
| 67 | * `relays`: List of relays where Service Providers SHOULD publish responses to | 67 | * `relays`: List of relays where Service Providers SHOULD publish responses to |
| 68 | * `p`: Service Providers the customer is interested in. Other SPs MIGHT still choose to process the job | 68 | * `p`: Service Providers the customer is interested in. Other SPs MIGHT still choose to process the job |
| 69 | 69 | ||
| 70 | ## Encrypted Params | ||
| 71 | |||
| 72 | If the user wants to keep the input parameters a secret, they can encrypt the `i` and `param` tags with the service provider's 'p' tag and add it to the content field. Add a tag `encrypted` as tags. Encryption for private tags will use [NIP-04 - Encrypted Direct Message encryption](https://github.com/nostr-protocol/nips/blob/master/04.md), using the user's private and service provider's public key for the shared secret | ||
| 73 | |||
| 74 | ```json | ||
| 75 | [ | ||
| 76 | ["i", "what is the capital of France? ", "text"], | ||
| 77 | ["param", "model", "LLaMA-2"], | ||
| 78 | ["param", "max_tokens", "512"], | ||
| 79 | ["param", "temperature", "0.5"], | ||
| 80 | ["param", "top-k", "50"], | ||
| 81 | ["param", "top-p", "0.7"], | ||
| 82 | ["param", "frequency_penalty", "1"] | ||
| 83 | ] | ||
| 84 | |||
| 85 | ``` | ||
| 86 | |||
| 87 | This param data will be encrypted and added to the `content` field and `p` tag should be present | ||
| 88 | |||
| 89 | ```json | ||
| 90 | { | ||
| 91 | "content": "BE2Y4xvS6HIY7TozIgbEl3sAHkdZoXyLRRkZv4fLPh3R7LtviLKAJM5qpkC7D6VtMbgIt4iNcMpLtpo...", | ||
| 92 | "tags": [ | ||
| 93 | ["p", "04f74530a6ede6b24731b976b8e78fb449ea61f40ff10e3d869a3030c4edc91f"], | ||
| 94 | ["encrypted"] | ||
| 95 | ], | ||
| 96 | ... | ||
| 97 | } | ||
| 98 | ``` | ||
| 99 | |||
| 100 | |||
| 70 | ## Job result (`kind:6000-6999`) | 101 | ## Job result (`kind:6000-6999`) |
| 71 | 102 | ||
| 72 | Service providers publish job results, providing the output of the job result. They should tag the original job request event id as well as the customer's pubkey. | 103 | Service providers publish job results, providing the output of the job result. They should tag the original job request event id as well as the customer's pubkey. |
| 73 | 104 | ||
| 74 | ```json | 105 | ```json |
| 75 | { | 106 | { |
| 76 | "pubkey": "<service-provider pubkey>", | 107 | "pubkey": "<service-provider pubkey>", |
| 77 | "content": "<payload>", | 108 | "content": "<payload>", |
| 78 | "kind": 6xxx, | 109 | "kind": 6xxx, |
| 79 | "tags": [ | 110 | "tags": [ |
| 80 | [ "request", "<job-request>" ], | 111 | ["request", "<job-request>"], |
| 81 | [ "e", "<job-request-id>", "<relay-hint>" ], | 112 | ["e", "<job-request-id>", "<relay-hint>"], |
| 82 | [ "i", "<input-data>" ], | 113 | ["i", "<input-data>"], |
| 83 | [ "p", "<customer's-pubkey>" ], | 114 | ["p", "<customer's-pubkey>"], |
| 84 | [ "amount", "requested-payment-amount", "<optional-bolt11>" ] | 115 | ["amount", "requested-payment-amount", "<optional-bolt11>"] |
| 85 | ] | 116 | ], |
| 117 | ... | ||
| 86 | } | 118 | } |
| 87 | ``` | 119 | ``` |
| 88 | 120 | ||
| @@ -90,19 +122,42 @@ Service providers publish job results, providing the output of the job result. T | |||
| 90 | * `amount`: millisats that the Service Provider is requesting to be paid. An optional third value can be a bolt11 invoice. | 122 | * `amount`: millisats that the Service Provider is requesting to be paid. An optional third value can be a bolt11 invoice. |
| 91 | * `i`: The original input(s) specified in the request. | 123 | * `i`: The original input(s) specified in the request. |
| 92 | 124 | ||
| 125 | ## Encrypted Output | ||
| 126 | |||
| 127 | If the request has encrypted params, then output should be encrypted and placed in `content` field. If the output is encrypted, then avoid including `i` tag with input-data as clear text. | ||
| 128 | Add a tag encrypted to mark the output content as `encrypted` | ||
| 129 | |||
| 130 | ```json | ||
| 131 | { | ||
| 132 | "pubkey": "<service-provider pubkey>", | ||
| 133 | "content": "<encrypted payload>", | ||
| 134 | "kind": 6xxx, | ||
| 135 | "tags": [ | ||
| 136 | ["request", "<job-request>"], | ||
| 137 | ["e", "<job-request-id>", "<relay-hint>"], | ||
| 138 | ["p", "<customer's-pubkey>"], | ||
| 139 | ["amount", "requested-payment-amount", "<optional-bolt11>"], | ||
| 140 | ["encrypted"] | ||
| 141 | ], | ||
| 142 | ... | ||
| 143 | } | ||
| 144 | ``` | ||
| 145 | |||
| 93 | ## Job feedback | 146 | ## Job feedback |
| 147 | |||
| 94 | Service providers can give feedback about a job back to the customer. | 148 | Service providers can give feedback about a job back to the customer. |
| 95 | 149 | ||
| 96 | ```json | 150 | ```json |
| 97 | { | 151 | { |
| 98 | "kind": 7000, | 152 | "kind": 7000, |
| 99 | "content": "<empty-or-payload>", | 153 | "content": "<empty-or-payload>", |
| 100 | "tags": [ | 154 | "tags": [ |
| 101 | [ "status", "<status>", "<extra-info>" ], | 155 | ["status", "<status>", "<extra-info>"], |
| 102 | [ "amount", "requested-payment-amount", "<bolt11>" ], | 156 | ["amount", "requested-payment-amount", "<bolt11>"], |
| 103 | [ "e", "<job-request-id>", "<relay-hint>" ], | 157 | ["e", "<job-request-id>", "<relay-hint>"], |
| 104 | [ "p", "<customer's-pubkey>" ], | 158 | ["p", "<customer's-pubkey>"], |
| 105 | ] | 159 | ], |
| 160 | ... | ||
| 106 | } | 161 | } |
| 107 | ``` | 162 | ``` |
| 108 | 163 | ||
| @@ -110,20 +165,23 @@ Service providers can give feedback about a job back to the customer. | |||
| 110 | * `amount` tag: as defined in the [Job Result](#job-result) section. | 165 | * `amount` tag: as defined in the [Job Result](#job-result) section. |
| 111 | * `status` tag: Service Providers SHOULD indicate what this feedback status refers to. [Appendix 1](#appendix-1-job-feedback-status) defines status. Extra human-readable information can be added as an extra argument. | 166 | * `status` tag: Service Providers SHOULD indicate what this feedback status refers to. [Appendix 1](#appendix-1-job-feedback-status) defines status. Extra human-readable information can be added as an extra argument. |
| 112 | 167 | ||
| 168 | * NOTE: If the input params requires input to be encrypted, then `content` field will have encrypted payload with `p` tag as key. | ||
| 169 | |||
| 113 | ### Job feedback status | 170 | ### Job feedback status |
| 114 | 171 | ||
| 115 | | status | description | | 172 | | status | description | |
| 116 | |--------|-------------| | 173 | | -------- | ------------- | |
| 117 | | `payment-required` | Service Provider requires payment before continuing. | | 174 | | `payment-required` | Service Provider requires payment before continuing. | |
| 118 | | `processing` | Service Provider is processing the job. | | 175 | | `processing` | Service Provider is processing the job. | |
| 119 | | `error` | Service Provider was unable to process the job. | | 176 | | `error` | Service Provider was unable to process the job. | |
| 120 | | `success` | Service Provider successfully processed the job. | | 177 | | `success` | Service Provider successfully processed the job. | |
| 121 | | `partial` | Service Provider partially processed the job. The `.content` might include a sample of the partial results. | | 178 | | `partial` | Service Provider partially processed the job. The `.content` might include a sample of the partial results. | |
| 122 | 179 | ||
| 123 | Any job feedback event MIGHT include results in the `.content` field, as described in the [Job Result](#job-result) section. This is useful for service providers to provide a sample of the results that have been processed so far. | 180 | Any job feedback event MIGHT include results in the `.content` field, as described in the [Job Result](#job-result) section. This is useful for service providers to provide a sample of the results that have been processed so far. |
| 124 | 181 | ||
| 125 | 182 | ||
| 126 | # Protocol Flow | 183 | # Protocol Flow |
| 184 | |||
| 127 | * Customer publishes a job request (e.g. `kind:5000` speech-to-text). | 185 | * Customer publishes a job request (e.g. `kind:5000` speech-to-text). |
| 128 | * Service Providers MAY submit `kind:7000` job-feedback events (e.g. `payment-required`, `processing`, `error`, etc.). | 186 | * Service Providers MAY submit `kind:7000` job-feedback events (e.g. `payment-required`, `processing`, `error`, etc.). |
| 129 | * Upon completion, the service provider publishes the result of the job with a `kind:6000` job-result event. | 187 | * Upon completion, the service provider publishes the result of the job with a `kind:6000` job-result event. |
| @@ -153,18 +211,19 @@ This gives a higher level of flexibility to service providers (which sophisticat | |||
| 153 | # Appendix 2: Service provider discoverability | 211 | # Appendix 2: Service provider discoverability |
| 154 | Service Providers MAY use NIP-89 announcements to advertise their support for job kinds: | 212 | Service Providers MAY use NIP-89 announcements to advertise their support for job kinds: |
| 155 | 213 | ||
| 156 | ```json | 214 | ```js |
| 157 | { | 215 | { |
| 158 | "kind": 31990, | 216 | "kind": 31990, |
| 159 | "pubkey": "<pubkey>", | 217 | "pubkey": "<pubkey>", |
| 160 | "content": "{ | 218 | "content": "{ |
| 161 | \"name\": \"Translating DVM\", | 219 | \"name\": \"Translating DVM\", |
| 162 | \"about\": \"I'm a DVM specialized in translating Bitcoin content.\" | 220 | \"about\": \"I'm a DVM specialized in translating Bitcoin content.\" |
| 163 | }", | 221 | }", |
| 164 | "tags": [ | 222 | "tags": [ |
| 165 | [ "k", "5005" ], // e.g. translation | 223 | ["k", "5005"], // e.g. translation |
| 166 | [ "t", "bitcoin" ] // e.g. optionally advertises it specializes in bitcoin audio transcription that won't confuse "Drivechains" with "Ridechains" | 224 | ["t", "bitcoin"] // e.g. optionally advertises it specializes in bitcoin audio transcription that won't confuse "Drivechains" with "Ridechains" |
| 167 | ] | 225 | ], |
| 226 | ... | ||
| 168 | } | 227 | } |
| 169 | ``` | 228 | ``` |
| 170 | 229 | ||