Skip to content

Latest commit

 

History

History
89 lines (70 loc) · 2.55 KB

README.md

File metadata and controls

89 lines (70 loc) · 2.55 KB

SwiftChat Backend API

The SwiftChat backend API is implemented using Python language and the FastAPI framework. It is packaged as a Docker image using aws-lambda-adapter and deployed to AWS App Runner or AWS Lambda for execution.

API Reference

API Schema

First, please configure you API URL and API Key like:

export API_URL=<API URL>
export API_KEY=<API Key>
  1. /api/converse

    curl -N "${API_URL}/api/converse" \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "text": "Hi"
            }
          ]
        }
      ],
      "modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
      "region": "us-west-2"
    }'

    This API is used to implement streaming conversations, and it only returns the text and token usage for display.

    The messages under body fully complies with the messages structure specification in Amazon Bedrock converse stream API. You can also add image or document according to the specification to support multimodal conversations.

  2. /api/image

    curl "${API_URL}/api/image" \
    --header 'Content-Type: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "prompt": "Beautiful countryside",
      "modelId": "stability.stable-image-core-v1:0",
      "region": "us-west-2",
      "width": "1024",
      "height": "1024"
    }'

    This API is used to generate images and returns a base64 encoded string of the image.

  3. /api/models

    curl "${API_URL}/api/models" \
    --header 'Content-Type: application/json' \
    --header 'accept: application/json' \
    --header "Authorization: Bearer ${API_KEY}" \
    --data '{
      "region": "us-west-2"
    }'

    This API is used to get a list of all streaming-supported text models and image generation models in the specified region.

  4. /api/upgrade

    curl "${API_URL}/api/upgrade" \
    --header 'Content-Type: application/json' \
    --header 'accept: application/json' \
    --header "Authorization: Bearer ${API_KEY}"

    This API is used to get the new version of SwiftChat for Android and macOS App updates.

API Code Reference