homanp / superagent-js

Superagent Javascript SDK

Home Page:https://docs.superagent.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Superagent Javascript SDK šŸ„·

This is the offical Javascript SDK for superagent.sh.

GitHub Contributors GitHub Last Commit GitHub Issues GitHub Pull Requests Github License Discord

Getting started

1. Installation

Install the superagentai-js package.

npm i superagentai-js

2. Usage

import SuperagentSDK from "superagentai-js";

const superagent = new SuperagentSDK(process.env.SUPERAGENT_API_TOKEN);

Examples

API Reference

The SDK exposes the following three resources: Prompts, Documents and Agents. Below you will find a schematic overivew of each resource:

Agents

// List all agents
await superagent.agents().list();

// Retuns a specific agent
await superagent.agents().get("<AGENT_ID>");

// Delete agent
await superagent.agents().delete("<AGENT_ID>");

// Create agent
await superagent.agents().create({
  name: "Ny agent",
  llm: {
    provider: "openai-chat",
    model: "gpt-4",
    api_key: process.env.OPENAI_API_KEY,
  },
  has_memory: true,
  promptId: "<PROMPT_ID>",
  documentId: "<DOCUMENT_ID>",
  toolId: "<TOOL_ID>",
});

// Run an agent
await superagent.agents().predict({
  input: { human_input: "Hello" },
  has_streaming: true,
});

Tools

// List all tools
await superagent.tools().list();

// Retuns a specific tool
await superagent.tools().get("<TOOL_ID>");

// Delete tool
await superagent.tools().delete("<TOOL_ID>");

// Create tool
await superagent.tools().create({
  name: "My tool",
  type: "SEARCH",
});

Documents

// List all documents
await superagent.documents().list();

// Retuns a specific document
await superagent.documents().get("<DOCUMENT_ID>");

// Delete document
await superagent.documents().delete("<DOCUMENT_ID>");

// Create document
await superagent.documents().create({
  name: "Ny agent",
  url: "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update",
  type: "PDF",
  authorization: null,
  splitter: { type: "character", chunk_size: 1000, chunk_overlap: 0 },
});

Prompts

  // List all prompts
  await superagent.prompts().list();

  // Retuns a specific prompt
  await superagent.prompts().get("<PROMPT_ID>");

  // Update a specific prompt
  await superagent.prompts().update("<PROMPT_ID>", {name: "Some updated name"});

  // Delete prompt
  await superagent.prompts().delete("<PROMPT_ID>");

  // Create prompt
  await superagent.prompts().create({
    name: "My prompt",
    input_variables: ["human_input", "chat_history"],
    template="You are an AI assistant that should answer a humans question. \n {chat_history} \n\n Human input: {human_input} \n Answer:"
  });

About

Superagent Javascript SDK

https://docs.superagent.sh

License:MIT License


Languages

Language:TypeScript 100.0%