diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 69e5034f..9519ad1c 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -159,14 +159,9 @@ nav: - HuggingFaceLLM: "swarms/models/huggingface.md" - Anthropic: "swarms/models/anthropic.md" - OpenAIChat: "swarms/models/openai.md" + # - TogetherAI: "swarms/models/togetherai.md" - MultiModal Models: - BaseMultiModalModel: "swarms/models/base_multimodal_model.md" - - Fuyu: "swarms/models/fuyu.md" - - Vilt: "swarms/models/vilt.md" - - Idefics: "swarms/models/idefics.md" - - Kosmos: "swarms/models/kosmos.md" - - Nougat: "swarms/models/nougat.md" - - Dalle3: "swarms/models/dalle3.md" - GPT4VisionAPI: "swarms/models/gpt4v.md" - Agents: - Agent: "swarms/structs/agent.md" @@ -203,8 +198,6 @@ nav: - Agent API: "swarms_cloud/agent_api.md" - Migrate from OpenAI to Swarms in 3 lines of code: "swarms_cloud/migrate_openai.md" - Getting Started with SOTA Vision Language Models VLM: "swarms_cloud/getting_started.md" - - Enterprise Guide to High-Performance Multi-Agent LLM Deployments: "swarms_cloud/production_deployment.md" - - Under The Hood The Swarm Cloud Serving Infrastructure: "swarms_cloud/architecture.md" - Swarms Memory: - Overview: "swarms_memory/index.md" - Memory Systems: @@ -213,7 +206,12 @@ nav: - Faiss: "swarms_memory/faiss.md" - Swarms Platform: - Overview: "swarms_platform/index.md" - - Prompts API: "swarms_platform/prompts_api.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" - Guides: - Comparing LLM Provider Pricing A Guide for Enterprises: "guides/pricing.md" - References: diff --git a/docs/swarms_platform/fetch_prompts.md b/docs/swarms_platform/fetch_prompts.md new file mode 100644 index 00000000..90e853b3 --- /dev/null +++ b/docs/swarms_platform/fetch_prompts.md @@ -0,0 +1,205 @@ +# Documentation for `getAllPrompts` API Endpoint + +The `getAllPrompts` API endpoint is a part of the `swarms.world` application, designed to fetch all prompt records from the database. This endpoint is crucial for retrieving various prompts stored in the `swarms_cloud_prompts` table, including their metadata such as name, description, use cases, and tags. It provides an authenticated way to access this data, ensuring that only authorized users can retrieve the information. + +## Purpose + +The primary purpose of this API endpoint is to provide a secure method for clients to fetch a list of prompts stored in the `swarms_cloud_prompts` table. It ensures data integrity and security by using an authentication guard and handles various HTTP methods and errors gracefully. + +## API Endpoint Definition + +### Endpoint URL + +``` +https://swarms.world/get-prompt +``` + +### HTTP Method + +``` +GET +``` + +### Request Headers + +| Header | Type | Required | Description | +|----------------|--------|----------|-----------------------------| +| Authorization | String | Yes | Bearer token for API access | + +### Response + +#### Success Response (200) + +Returns an array of prompts. + +```json +[ + { + "id": "string", + "name": "string", + "description": "string", + "prompt": "string", + "use_cases": "string", + "tags": "string" + }, + ... +] +``` + +#### Error Responses + +- **405 Method Not Allowed** + + ```json + { + "error": "Method Not Allowed" + } + ``` + +- **401 Unauthorized** + + ```json + { + "error": "API Key is missing" + } + ``` + +- **500 Internal Server Error** + + ```json + { + "error": "Could not fetch prompts" + } + ``` + +## Request Handling + +1. **Method Validation**: The endpoint only supports the `GET` method. If a different HTTP method is used, it responds with a `405 Method Not Allowed` status. +2. **Authentication**: The request must include a valid Bearer token in the `Authorization` header. If the token is missing, a `401 Unauthorized` status is returned. +3. **Authorization Check**: The token is validated using the `AuthApiGuard` class. If the token is invalid, an appropriate error response is returned based on the status received from the guard. +4. **Database Query**: The endpoint queries the `swarms_cloud_prompts` table using the `supabaseAdmin` client to fetch prompt data. +5. **Response**: On success, it returns the prompt data in JSON format. In case of an error during the database query, a `500 Internal Server Error` status is returned. + +## Code Example + +### JavaScript (Node.js) + +```javascript +import fetch from 'node-fetch'; + +const getPrompts = async () => { + const response = await fetch('https://swarms.world/get-prompt', { + method: 'GET', + headers: { + 'Authorization': 'Bearer YOUR_API_KEY' + } + }); + + if (!response.ok) { + throw new Error(`Error: ${response.statusText}`); + } + + const data = await response.json(); + console.log(data); +}; + +getPrompts().catch(console.error); +``` + +### Python + +```python +import requests + +def get_prompts(): + headers = { + 'Authorization': 'Bearer YOUR_API_KEY' + } + response = requests.get('https://swarms.world/get-prompt', headers=headers) + + if response.status_code != 200: + raise Exception(f'Error: {response.status_code}, {response.text}') + + data = response.json() + print(data) + +get_prompts() +``` + +### cURL + +```sh +curl -X GET https://swarms.world/get-prompt \ +-H "Authorization: Bearer YOUR_API_KEY" +``` + +### Go + +```go +package main + +import ( + "fmt" + "io/ioutil" + "net/http" +) + +func getPrompts() { + client := &http.Client{} + req, err := http.NewRequest("GET", "https://swarms.world/get-prompt", nil) + if err != nil { + panic(err) + } + + req.Header.Add("Authorization", "Bearer YOUR_API_KEY") + + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + body, _ := ioutil.ReadAll(resp.Body) + panic(fmt.Sprintf("Error: %d, %s", resp.StatusCode, string(body))) + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + } + + fmt.Println(string(body)) +} + +func main() { + getPrompts() +} +``` + +### Attributes Table + +| Attribute | Type | Description | +|---------------|--------|------------------------------------------------------------| +| id | String | Unique identifier for the prompt | +| name | String | Name of the prompt | +| description | String | Description of the prompt | +| prompt | String | The actual prompt text | +| use_cases | String | Use cases for the prompt | +| tags | String | Tags associated with the prompt | + +## Additional Information and Tips + +- Ensure your API key is kept secure and not exposed in client-side code. +- Handle different error statuses appropriately to provide clear feedback to users. +- Consider implementing rate limiting and logging for better security and monitoring. + +## References and Resources + +- [Next.js API Routes](https://nextjs.org/docs/api-routes/introduction) +- [Supabase Documentation](https://supabase.com/docs) +- [Node Fetch](https://www.npmjs.com/package/node-fetch) +- [Requests Library (Python)](https://docs.python-requests.org/en/latest/) +- [Go net/http Package](https://pkg.go.dev/net/http) + +This documentation provides a comprehensive guide to the `getAllPrompts` API endpoint, including usage examples in multiple programming languages and detailed attribute descriptions. \ No newline at end of file diff --git a/scripts/docker_files/docker-compose.yaml b/scripts/docker_files/docker-compose.yaml new file mode 100644 index 00000000..e69de29b