pull/420/head
Kye 10 months ago
parent 0309fc460b
commit f23cd93f31

@ -0,0 +1,138 @@
# Swarm Cloud API Reference
## Overview
The AI Chat Completion API processes text and image inputs to generate conversational responses. It supports various configurations to customize response behavior and manage input content.
## API Endpoints
### Chat Completion
`https://swarms.world`
- **Endpoint:** `/v1/chat/completions`
- **Method:** POST
- **Description:** Generates a response based on the provided conversation history and parameters.
#### Request Parameters
| Parameter | Type | Description | Required |
|---------------|--------------------|-----------------------------------------------------------|----------|
| `model` | string | The AI model identifier. | Yes |
| `messages` | array of objects | A list of chat messages, including the sender's role and content. | Yes |
| `temperature` | float | Controls randomness. Lower values make responses more deterministic. | No |
| `top_p` | float | Controls diversity. Lower values lead to less random completions. | No |
| `max_tokens` | integer | The maximum number of tokens to generate. | No |
| `stream` | boolean | If set to true, responses are streamed back as they're generated. | No |
#### Response Structure
- **Success Response Code:** `200 OK`
```markdown
{
"model": string,
"object": string,
"choices": array of objects,
"usage": object
}
```
### List Models
- **Endpoint:** `/v1/models`
- **Method:** GET
- **Description:** Retrieves a list of available models.
#### Response Structure
- **Success Response Code:** `200 OK`
```markdown
{
"data": array of objects
}
```
## Objects
### ChatMessageInput
| Field | Type | Description | Required |
|-----------|---------------------|-----------------------------------------------|----------|
| `role` | string | The role of the message sender. | Yes |
| `content` | string or array | The content of the message. | Yes |
| `name` | string | An optional name identifier for the sender. | No |
### ChatCompletionResponseChoice
| Field | Type | Description |
|-----------|--------|------------------------------------|
| `index` | integer| The index of the choice. |
| `message` | object | A `ChatMessageResponse` object. |
### UsageInfo
| Field | Type | Description |
|-------------------|---------|-----------------------------------------------|
| `prompt_tokens` | integer | The number of tokens used in the prompt. |
| `total_tokens` | integer | The total number of tokens used. |
| `completion_tokens`| integer| The number of tokens used for the completion. |
## Example Requests
### Text Chat Completion
```json
POST /v1/chat/completions
{
"model": "cogvlm-chat-17b",
"messages": [
{
"role": "user",
"content": "Hello, world!"
}
],
"temperature": 0.8
}
```
### Image and Text Chat Completion
```json
POST /v1/chat/completions
{
"model": "cogvlm-chat-17b",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image"
},
{
"type": "image_url",
"image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..."
}
]
}
],
"temperature": 0.8,
"top_p": 0.9,
"max_tokens": 1024
}
```
## Error Codes
The API uses standard HTTP status codes to indicate the success or failure of an API call.
| Status Code | Description |
|-------------|-----------------------------------|
| 200 | OK - The request has succeeded. |
| 400 | Bad Request - Invalid request format. |
| 500 | Internal Server Error - An error occurred on the server. |
## Conclusion
This API reference provides the necessary details to understand and interact with the AI Chat Completion API. By following the outlined request and response formats, users can integrate this API into their applications to generate dynamic and contextually relevant conversational responses.

@ -61,6 +61,8 @@ nav:
- Limitations of Individual Agents: "limits_of_individual_agents.md"
- Why Swarms: "why_swarms.md"
- The Swarms Bounty System: "swarms_bounty_system.md"
- Swarms Cloud API:
- Overview: "swarms_cloud/main.md"
- Swarms Framework [PY]:
- Overview: "swarms/index.md"
- DIY Build Your Own Agent: "diy_your_own_agent.md"

@ -0,0 +1,21 @@
from swarms import Agent, OpenAIChat
## Initialize the workflow
agent = Agent(
llm=OpenAIChat(),
max_loops="auto",
agent_name = "Amazon Product Scraper",
system_prompt="Create the code in python to scrape amazon product reviews and return csv given a product url",
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
interactive=True,
)
# Run the workflow on a task
agent(
"Create the code to scrape this amazon url and rturn a csv of reviews: https://www.amazon.com/Creative-Act-Way-Being/dp/0593652886/ref=sr_1_1?dib=eyJ2IjoiMSJ9.JVdL3JSDmBVH_jv4eM6YE4npUpG6jO6-ai6lgmax-Ya4nH3oPk8cxkmzKsx9yAMX-Eo4A1ErqipCeY-FhTqMc7hhNTqCoAvNd65rvXH1GnYv7WlfSDYTjMkB_vVrH-iitBXAY6uASm73ff2hPWzqhF3ldGkYr8fA5FtmoYMSOnarvCU11YpoSp3EqdK526XOxkRJqeFlZAoAkXOmYHe9B5sY8-zQlVgkIV3U-7rUQdY.UXen28vr2K-Tbbz9aB7vNLLurAiR2ZSblFOVNjXYaf8&dib_tag=se&hvadid=652633987879&hvdev=c&hvlocphy=9061268&hvnetw=g&hvqmt=e&hvrand=413884426001746223&hvtargid=kwd-1977743614989&hydadcr=8513_13545021&keywords=the+creative+act+rick+rubin+book&qid=1710541252&sr=8-1"
)
Loading…
Cancel
Save