Prerequisites

Obtain a Gray Swan API key

Navigate to your profile at https://app.grayswan.ai/profile and under the “API Keys” section, click “New API Key”.

Installation

Install our Gray Swan API client library with the following command:

pip install grayswan-api

Example usage for text completion

import os
from gray_swan import GraySwan
GRAYSWAN_API_KEY = os.environ.get("GRAYSWAN_API_KEY")

client = GraySwan(
    api_key=GRAYSWAN_API_KEY,
)

completion_create_response = client.chat.completion.create(
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "What is a large language model?"}],
    model="cygnet",
)

print(completion_create_response.choices[0].message.content)

Streaming example

completion_create_response = client.chat.completion.create(
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "What is a large language model?"}],
    model="cygnet",
    stream=True
)
for r in completion_create_response:
    delta_content = r.choices[0].delta.content
    print(delta_content, end="")