Code Monkey home page Code Monkey logo

ai-engine-sdk-js's Introduction

AI Engine SDK JS/TS

A library to enable users to build custom AI Engine Applications
npm version latest commit Build Status Publish Status

⭐️ Features

  • Access to latest AI Engine features
  • Simple and intuitive API
  • Support for TypeScript and JavaScript
  • Can run in the browser or via node

📦 Getting Started

npm install @fetchai/ai-engine-sdk

Using the Chat API

Before you start to integrate the AI Engine into your app, you might want to get familiar with agent functions.

Creating the AIEngine client object

To find out how to generate an apiKey check out the documentation regarding Agentverse API keys.

import { AiEngine } from "@fetchai/ai-engine-sdk";

const aiEngine = new AiEngine(apiKey);

Querying the id of the function group where our to-be-used function(s) belong

const functionGroups = await aiEngine.getFunctionGroups();
const functionGroupId = functionGroups.find((g) => g.name === "Fetch Verified");

If you would like to use the functions in your own My Functions function group instead then you can use this filter instead:

const functionGroupId = functionGroups.find((g) => g.name === "My Functions");

Creating a session with the AI Engine using the functionGroupId fetched before

const session = await aiEngine.createSession(functionGroupId);

Starting the conversation with an arbitrary objective

await session.start("Find a holiday destination");

Querying new messages

You might want to query new messages regularly with a setTimeout or setInterval to check for new Message (Check out examples/simple.ts for a complete example use case of the SDK):

const messages = await session.getMessages();

Checking the type of the new message

There are 5 different types of messages which are generated by the AI Engine and the SDK implements methods for checking the type of the respective new Message:

  • task selection message: isTaskSelectionMessage - this message is generated for example in the case when the AI engine recommends functions based on the initial objective or in the case when the AI Engine finds multiple options to provide as an input for a function.
  • AI Engine message: isAiEngineMessage - this message type doesn't expect the user to reply to, this is for notifying the user about something
  • confirmation message: isConfirmationMessage - when the AI Engine has managed to acquire all the inputs for the agent belonging to the to-be-executed function (= it has managed to build the context), it sends this type of message to the user
  • agent message: isAgentMessage - this is a regular question that the user has to reply to with a string
  • stop message: isStopMessage - this is the message which is sent when the session has stopped and the AI Engine doesn't wait for any replies from the user

Replying to the different type of messages

All message types (expect for the AI engine message and stop message) expect a response from the user and the SDK implements methods for sending reply in response to those different type of messages respectively. The first argument of all these reply methods is the Message object to which we want to send back the response. The SDK methods you can use to reply to:

  • task selection message: session.submitTaskSelection
  • agent message: session.submitResponse
  • confirmation message: session.submitConfirmation or session.rejectConfirmation - depending on if the user wants to confirm or reject the context generated by the AI engine respectively

Deleting session with AI engine

After finishing the conversation with AI Engine you can delete the session like this:

await session.delete();

If you would like to check out a complete example on how to integrate AI Engine into your app, feel free to checkout examples/simple.ts.

✨ Contributing

All contributions are welcome! Remember, contribution includes not only code, but any help with docs or issues raised by other developers. See our contribution guidelines for more details.

❓ Issues, Questions, and Discussions

We use GitHub Issues for tracking requests and bugs, and GitHub Discussions for general questions and discussion.

ai-engine-sdk-js's People

Contributors

ejfitzgerald avatar zmezei avatar 5a11 avatar

Watchers

 avatar void* avatar Kamal Ved avatar Simon Rowland avatar Lokman Rahmani avatar Gokhun Guneyhan avatar Jayesh Jawale avatar

ai-engine-sdk-js's Issues

Add tests with tox (for different versions)

Prerequisites

  • I checked the documentation and made sure this feature does not already exist
  • I checked the existing issues to make sure this feature has not already been requested

Feature

Provide some test that can be executed in CI.

  • AiEngine API should be mocked.
  • Define what python version should be supported.

Additional Information (Optional)

No response

agent_json with type "options" is not supported

Prerequisites

  • I checked the documentation and found no answer to my problem
  • I checked the existing issues and made sure there are no similar bug reports

Category

Bug (unexpected behavior)

Expected Behavior

No response

Observed Behavior

I was working on a react app using the SDK and the app would crash and print and UNKOWN JSON error that I have traced back to ai-engine-sdk-js/src/index.ts line 218. And by checking the network reponse I see it is because our agent sends a agent-json of type "options" which isn't supported by the SDK

looking at network tab and realised this issue

  • but it also occurs with example
  • send options but it doesnt take it

To Reproduce

No response

Version

0.1.0

Environment Details (Optional)

No response

Failure Logs (Optional)

No response

Additional Information (Optional)

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.