Skip to content

Commit

Permalink
[SWARMS AMRKETPLACE][PROMPTS]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye Gomez authored and Kye Gomez committed Aug 2, 2024
1 parent 166ab2a commit b9088d5
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 184 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AI21_API_KEY="your_api_key_here"
COHERE_API_KEY="your_api_key_here"
ALEPHALPHA_API_KEY="your_api_key_here"
HUGGINFACEHUB_API_KEY="your_api_key_here"
SWARMS_API_KEY=""

EVAL_PORT=8000
MODEL_NAME="gpt-4"
Expand Down
14 changes: 9 additions & 5 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ nav:
- Overview: "swarms_platform/index.md"
- Share & Discover Prompts, Agents, Tools, and more: "swarms_platform/share_discover.md"
- Prompts API:
- Overview: "swarms_platform/prompts_api.md"
- Fetch Prompts: "swarms_platform/fetch_prompts.md"
# - Agents API:
# - Overview: "swarms_platform/agents_api.md"
# - Fetch Agents: "swarms_platform/fetch_agents.md"
- Add Prompts: "swarms_platform/prompts/add_prompt.md"
- Edit Prompts: "swarms_platform/prompts/edit_prompt.md"
- Query Prompts: "swarms_platform/prompts/fetch_prompts.md"
- Agents API:
- Overview: "swarms_platform/agents_api.md"
- Add Agents: "swarms_platform/fetch_agents.md"
# - Tools API:

Check warning on line 221 in docs/mkdocs.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

221:5 [comments-indentation] comment not indented like content
# - Overview: "swarms_platform/tools_api.md"
# - Add Tools: "swarms_platform/fetch_tools.md"
# - Guides:
# - Comparing LLM Provider Pricing A Guide for Enterprises: "guides/pricing.md"
- References:
Expand Down
178 changes: 178 additions & 0 deletions docs/swarms_platform/prompts/add_prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Prompts API Documentation

The `https://swarms.world/api/add-prompt` endpoint allows users to add a new prompt to the Swarms platform. This API accepts a POST request with a JSON body containing details of the prompt, such as its name, description, use cases, and tags. The request must be authenticated using an API key.

## Endpoint: Add Prompt

- **URL:** `https://swarms.world/api/add-prompt`
- **Method:** POST
- **Content-Type:** `application/json`
- **Authorization:** Bearer token required in the header

## Request Parameters

The request body should be a JSON object with the following attributes:

| Attribute | Type | Description | Required |
| ------------- | -------- | --------------------------------------------------------------- | -------- |
| `name` | `string` | The name of the prompt. | Yes |
| `prompt` | `string` | The prompt text. | Yes |
| `description` | `string` | A brief description of the prompt. | Yes |
| `useCases` | `array` | An array of use cases, each containing a title and description. | Yes |
| `tags` | `string` | Comma-separated tags for the prompt. | No |

### `useCases` Structure

Each use case in the `useCases` array should be an object with the following attributes:

| Attribute | Type | Description | Required |
| ------------- | -------- | ------------------------------------ | -------- |
| `title` | `string` | The title of the use case. | Yes |
| `description` | `string` | A brief description of the use case. | Yes |

## Example Usage

### Python

```python
import requests
import json

url = "https://swarms.world/api/add-prompt"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {apiKey}"
}
data = {
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{"title": "Use case 1", "description": "Description of use case 1"},
{"title": "Use case 2", "description": "Description of use case 2"}
],
"tags": "example, prompt"
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
```

### Node.js

```javascript
const fetch = require("node-fetch");

async function addPromptsHandler() {
try {
const response = await fetch("https://swarms.world/api/add-prompt", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer {apiKey}",
},
body: JSON.stringify({
name: "Example Prompt",
prompt: "This is an example prompt from an API route.",
description: "Description of the prompt.",
useCases: [
{ title: "Use case 1", description: "Description of use case 1" },
{ title: "Use case 2", description: "Description of use case 2" },
],
tags: "example, prompt",
}),
});

const result = await response.json();
console.log(result);
} catch (error) {
console.error("An error has occurred", error);
}
}

addPromptsHandler();
```

### Go

```go
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

func main() {
url := "https://swarms.world/api/add-prompt"
payload := map[string]interface{}{
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": []map[string]string{
{"title": "Use case 1", "description": "Description of use case 1"},
{"title": "Use case 2", "description": "Description of use case 2"},
},
"tags": "example, prompt",
}
jsonPayload, _ := json.Marshal(payload)

req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer {apiKey}")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("An error has occurred", err)
return
}
defer resp.Body.Close()

var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
```

### cURL

```bash
curl -X POST https://swarms.world/api/add-prompt \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {apiKey}" \
-d '{
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{ "title": "Use case 1", "description": "Description of use case 1" },
{ "title": "Use case 2", "description": "Description of use case 2" }
],
"tags": "example, prompt"
}'
```

## Response

The response will be a JSON object containing the result of the operation. Example response:

```json
{
"success": true,
"message": "Prompt added successfully",
"data": {
"id": "prompt_id",
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{ "title": "Use case 1", "description": "Description of use case 1" },
{ "title": "Use case 2", "description": "Description of use case 2" }
],
"tags": "example, prompt"
}
}
```
Original file line number Diff line number Diff line change
@@ -1,182 +1,3 @@
# Prompts API Documentation

The `https://swarms.world/api/add-prompt` endpoint allows users to add a new prompt to the Swarms platform. This API accepts a POST request with a JSON body containing details of the prompt, such as its name, description, use cases, and tags. The request must be authenticated using an API key.

## Endpoint: Add Prompt

- **URL:** `https://swarms.world/api/add-prompt`
- **Method:** POST
- **Content-Type:** `application/json`
- **Authorization:** Bearer token required in the header

## Request Parameters

The request body should be a JSON object with the following attributes:

| Attribute | Type | Description | Required |
| ------------- | -------- | --------------------------------------------------------------- | -------- |
| `name` | `string` | The name of the prompt. | Yes |
| `prompt` | `string` | The prompt text. | Yes |
| `description` | `string` | A brief description of the prompt. | Yes |
| `useCases` | `array` | An array of use cases, each containing a title and description. | Yes |
| `tags` | `string` | Comma-separated tags for the prompt. | No |

### `useCases` Structure

Each use case in the `useCases` array should be an object with the following attributes:

| Attribute | Type | Description | Required |
| ------------- | -------- | ------------------------------------ | -------- |
| `title` | `string` | The title of the use case. | Yes |
| `description` | `string` | A brief description of the use case. | Yes |

## Example Usage

### Python

```python
import requests
import json

url = "https://swarms.world/api/add-prompt"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {apiKey}"
}
data = {
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{"title": "Use case 1", "description": "Description of use case 1"},
{"title": "Use case 2", "description": "Description of use case 2"}
],
"tags": "example, prompt"
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
```

### Node.js

```javascript
const fetch = require("node-fetch");

async function addPromptsHandler() {
try {
const response = await fetch("https://swarms.world/api/add-prompt", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer {apiKey}",
},
body: JSON.stringify({
name: "Example Prompt",
prompt: "This is an example prompt from an API route.",
description: "Description of the prompt.",
useCases: [
{ title: "Use case 1", description: "Description of use case 1" },
{ title: "Use case 2", description: "Description of use case 2" },
],
tags: "example, prompt",
}),
});

const result = await response.json();
console.log(result);
} catch (error) {
console.error("An error has occurred", error);
}
}

addPromptsHandler();
```

### Go

```go
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

func main() {
url := "https://swarms.world/api/add-prompt"
payload := map[string]interface{}{
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": []map[string]string{
{"title": "Use case 1", "description": "Description of use case 1"},
{"title": "Use case 2", "description": "Description of use case 2"},
},
"tags": "example, prompt",
}
jsonPayload, _ := json.Marshal(payload)

req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer {apiKey}")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("An error has occurred", err)
return
}
defer resp.Body.Close()

var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
```

### cURL

```bash
curl -X POST https://swarms.world/api/add-prompt \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {apiKey}" \
-d '{
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{ "title": "Use case 1", "description": "Description of use case 1" },
{ "title": "Use case 2", "description": "Description of use case 2" }
],
"tags": "example, prompt"
}'
```

## Response

The response will be a JSON object containing the result of the operation. Example response:

```json
{
"success": true,
"message": "Prompt added successfully",
"data": {
"id": "prompt_id",
"name": "Example Prompt",
"prompt": "This is an example prompt from an API route.",
"description": "Description of the prompt.",
"useCases": [
{ "title": "Use case 1", "description": "Description of use case 1" },
{ "title": "Use case 2", "description": "Description of use case 2" }
],
"tags": "example, prompt"
}
}
```

# Endpoint: Edit Prompt

The `https://swarms.world/api/edit-prompt` endpoint allows users to edit an existing prompt on the Swarms platform. This API accepts a POST request with a JSON body containing the prompt details to be updated, such as its name, description, use cases, and tags. The request must be authenticated using an API key.
Expand Down
File renamed without changes.
Loading

0 comments on commit b9088d5

Please sign in to comment.