Swiftask
  • Quick start
  • Key concepts
    • AI Tools Hub
    • Agents
    • Knowledge base
    • Skills
    • Projects
    • Automation
  • AI tools hub
    • Introduction
    • Chat interface
    • Tokens
    • List of AI features
    • AI suggestions
    • FAQ
  • Agents
    • Introduction
    • Create an agent step by step
    • How to evaluate your agent
    • Multi-agents
    • Widget
    • Share agent
    • FAQ
  • Knowledge base
    • Introduction
    • Data connectors
      • Rich text
      • PDF File
      • Azure Document Loader
      • YouTube
      • Apify Dataset
      • PowerPoint File
      • Excel File
      • DOCX File
      • SQL Database
      • REST API
      • JSON File
      • CSV File
      • SQL Database Query
      • Website
      • Webpage
      • Sitemap
      • Dropbox files
      • Google drive files
    • Create a knowledge base
    • Attach Knowledge base to your agent
    • Share knowledge base
    • FAQ
  • Skills
    • Introduction
    • Skills library
      • Webpage Content Parsing
      • GitLab File Creation
      • Browsing with Perplexity
      • Open API
      • Retriever data from external sources
      • GitHub pull request diff retriever
      • GitHub pull request comment
      • Export table to Excel
      • Export text to PDF
      • GitHub file content
      • GitHub pull request info
      • OpenDataSoft
      • Agent as Skill
      • Swiftask AI recommandation
      • LinkedIn Share
      • Prismic migration create
      • Github create file
    • Create a new skill
    • Attach skill to your agent
    • FAQ
  • Projects
    • Introduction
    • Create a project
    • Generate task
    • Task AI chat
    • Organize chat in project
    • Project agent
    • FAQ
  • Automation
    • Introduction
    • Create an automation
  • Workspace admin
    • Introduction
    • Invite collaborators to join your workspace
    • Referral
    • Subscription renewal and Credit explanation
    • Purchase credits
    • Share agent
    • Subscription Pro plan/Team plan & token distribution
    • Create a project
    • Cancel subscription /Manage payment method
    • Personnal data security
    • SSO For enterprise
  • Use cases & Tutorials
    • Chat with multi-AI
    • Chat with PDF file
    • Import data - Webpage
    • How to generate an image on Swiftask
    • Import data (Azure Document Loader) - PDF
    • How to generate videos on Swiftask
    • Transform your ideas into videos with LUMA AI
    • Upgrade subscription plan
    • How to create an agent? step by step
    • Create AI agents for your business
    • Integrate external API in your agent
    • Create a professional landing page in 5 minutes
    • How to automate your blog content creation with an AI agent
    • How to evaluate your AI agent
    • How to create a Community Manager agent
  • Developer
    • List of AI and agents accessible via API
    • Access AI and agent through API
    • OpenAI SDK
  • Support & Social network
  • Changelog
Powered by GitBook
On this page
  • Swiftask AI Integration with OpenAI SDK
  • Prerequisites
  • Installation
  • Integration Steps
  • Example Code
  1. Developer

OpenAI SDK

Swiftask AI Integration with OpenAI SDK

This documentation provides a step-by-step guide for developers to integrate AI capabilities into their Swiftask application using the OpenAI SDK.

Prerequisites

  • Swiftask Account: Ensure you have a Swiftask account.

  • API Key: You need an API key from your Swiftask account. Follow these steps to create one:

    1. Log in to your Swiftask account.

    2. Navigate to the API settings or developer section.

    3. Generate a new API key and keep it secure.

  • Node.js Environment: Ensure Node.js is installed on your machine.

  • OpenAI SDK: Access to the OpenAI SDK.

Installation

First, you need to install the OpenAI SDK. You can do this using npm:

npm install openai

Integration Steps

1. Import the OpenAI SDK

Start by importing the OpenAI SDK into your project:

import OpenAI from 'openai';

2. Initialize the OpenAI Client

Create an instance of the OpenAI client with your Swiftask API key and the appropriate base URL:

const openai = new OpenAI({
    apiKey: 'swiftask-api-key', // Replace with your actual Swiftask API key
    baseURL: 'https://graphql.swiftask.ai/v1',
});

3. Create a Chat Completion Request

To interact with the AI, create a chat completion request. Specify the model and the messages you want to send:

const completion = openai.chat.completions.create({
    model: 'gpt-4o', // Specify the model you want to use
    messages: [
        { role: 'system', content: 'You are a helpful assistant.' },
        { role: 'user', content: 'Hello, how are you?' },
    ],
});

4. Handle the Response

Use a promise to handle the response from the AI. You can access the AI's reply through the response.choices array:

completion.then((response) => {
    console.log(response.choices[0].message.content);
});

Example Code

Here is the complete example code:

import OpenAI from 'openai';

const openai = new OpenAI({
    apiKey: 'swiftask-api-key', // Replace with your actual Swiftask API key
    baseURL: 'https://graphql.swiftask.ai/v1',
});

const completion = openai.chat.completions.create({
    model: 'gpt-4o', // Specify the model slug you want to use
    messages: [
        { role: 'system', content: 'You are a helpful assistant.' },
        { role: 'user', content: 'Hello, how are you?' },
    ],
}).then((response) => {
    console.log(response.choices[0].message.content);
});

You can refer to List of AI and agents accessible via API to get ai slug

PreviousAccess AI and agent through APINextSupport & Social network

Last updated 2 months ago