PropulsionAI
  • Introduction
    • What is PropulsionAI?
    • Key Concepts at a Glance
    • Getting Started
    • Installing the SDK
    • Foundational Models
  • Quick Start
    • Creating Datasets
    • Fine-tuning a Model
    • Deploying Models
    • Generate API Key
    • Using the SDK
    • Function Calling
    • Using Knowledge Base
  • Reference
    • FAQs
    • Understanding Usage Costs
    • Community & Support
    • Our Commitment
Powered by GitBook
On this page
  1. Quick Start

Using the SDK

Basic examples and walkthroughs to get you using the SDK immediately.

PreviousGenerate API KeyNextFunction Calling

Last updated 9 months ago

Initialize the client

import PropulsionAI from 'propulsionai';

const client = new PropulsionAI({
  bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'],
});
from propulsionai import PropulsionAI

client = PropulsionAI(
    # This is the default and can be omitted
    bearer_token=os.environ.get("PROPULSIONAI_BEARER_TOKEN"),
)

Chat

async function main() {
    const completionCreateResponse = await client.chat.completions.create({
        deployment: '<deployment_id>',
        messages=[
            {
                "role": "user",
                "content": "Hello, How are you?",
            }
        ],
        stream: false
    });
    
    console.log(completionCreateResponse.choices);
}
main();
def sync_main() -> None:
    response = client.chat.completions.create(
        deployment="<deployment_id>",
        messages=[
            {
                "role": "user",
                "content": "Hello, How are you?",
            }
        ],
        stream=False,
    )

    print(response)

sync_main()

Streaming Chat

async function main() {
    const completionCreateResponse = await client.chat.completions.create({
        deployment: '<deployment_id>',
        messages=[
            {
                "role": "user",
                "content": "Hello, How are you?",
            }
        ],
        stream: true
    });
    
    for await (const part of stream) {
        process.stdout.write(part.choices[0]?.delta?.content || '');
    }
}
main();
def sync_main() -> None:
    response = client.chat.completions.create(
        deployment="<deployment_id>",
        messages=[
            {
                "role": "user",
                "content": "Hello, How are you?",
            }
        ],
        stream=True,
    )

    for data in response:
      if data:
          chunk = data.to_json()
          chunk_json = json.loads(chunk)
          
          if chunk_json["choices"] and chunk_json["choices"][0]["delta"] is not None:
              delta = chunk_json["choices"][0]["delta"]
              if "content" in delta and delta["content"] is not None:
                  sys.stdout.write(delta["content"])
                  sys.stdout.flush() # Ensure content is displayed immediately

sync_main()

Installing the SDK
Generate API Key