https://github.com/superfaceai/hubapi-example-langchain
An example of using Superface's Hub API with LangChain, OpenAI and Node.js
https://github.com/superfaceai/hubapi-example-langchain
Last synced: 4 months ago
JSON representation
An example of using Superface's Hub API with LangChain, OpenAI and Node.js
- Host: GitHub
- URL: https://github.com/superfaceai/hubapi-example-langchain
- Owner: superfaceai
- Created: 2024-04-04T14:41:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-09T08:42:03.000Z (9 months ago)
- Last Synced: 2024-10-16T07:04:44.487Z (6 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- jimsghstars - superfaceai/hubapi-example-langchain - An example of using Superface's Hub API with LangChain, OpenAI and Node.js (JavaScript)
README
# 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 = "";
const 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](https://superface.ai/docs/api/examples/langchain)