Git Product home page Git Product logo

hubapi-example-langchain's Introduction

Hub API - LangChain, OpenAI and Node.js Example

In this example repository we will focus on building a simple agent that can consume and use the functions definitions provided by Superface using the LangChain.js library, OpenAI and Node.js.

Run this example

Clone the repository, and run:

npm install

This will install the LangChain dependencies, as well as Axios for making HTTP requests to the Hub API.

Add API Keys

After everything is installed you will need to add two API keys in src/index.js:

const OPENAI_API_KEY = "<your-openai-api-key>";
const SUPERFACE_AUTH_TOKEN = "<your-superface-auth-token>";

Change the prompt

By default, there is a prompt that will make two calls to Superface's Hub API to get the weather details for two different cities. You can edit this to add more if you like, or change the cities to those nearer to you.

const PROMPT = "What's the weather like in Prague and in Kosice?";

Run it

npm run example

After a moment you will see responses from the Hub API, followed by the final result. Something like this:

SUPERFACE RESPONSE: {"status":"success","assistant_hint":"Format the result in 'result' field to the user. If the user asked for a specific format, respect it","result":{"description":"Partly cloudy","feelsLike":17,"temperature":17}}
SUPERFACE RESPONSE: {"status":"success","assistant_hint":"Format the result in 'result' field to the user. If the user asked for a specific format, respect it","result":{"description":"Partly cloudy","feelsLike":15,"temperature":15}}
The current weather in Prague is partly cloudy with a temperature of 15°C, and in Kosice, it is also partly cloudy with a temperature of 17°C.

For more information

The full breakdown can be found here: https://superface.ai/docs/api/examples/langchain

hubapi-example-langchain's People

Contributors

martyndavies avatar

Watchers

Ondrej Musil avatar

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.