Bridge & Chat API
Overview
This project provides two core APIs that power the GenLayer Intelligent Oracle:
- A Bridge API for deploying Intelligent Oracles to the GenLayer blockchain
- A Chat API that integrates OpenAI's GPT models to provide natural language assistance in the UI wizard component
Features
Bridge API
- Handles deployment of Intelligent Oracles to GenLayer
- Manages transaction signing and blockchain interactions
- Provides status updates during deployment process
Chat API
- Integrates with OpenAI's GPT models
- Streams AI responses in real-time
- Processes natural language inputs for the wizard interface
- Maintains conversation context for multi-step configurations
Technologies Used
- Node.js
- OpenAI API
- GenLayer SDK
- Edge Functions (Vercel/Cloudflare)
Setup
-
Clone the repository
-
Set up environment variables by copying the
.env.example
file in the root directory to.env
and adding your own values.
Usage
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000
Note: the port may vary depending on the configuration of your local machine and other running services. For example, if you are running the ui-wizard project, it will use port 3001 by default.
API Reference
Bridge API Endpoints
POST /api/bridge/deploy-intelligent-oracle
: Deploy a new Intelligent Oracle
The following schema describes the required fields when creating a new oracle:
{
predictionMarketId?: string; // Optional, defaults to "0"
title: string; // Title of the prediction market
description: string; // Detailed description of the market
potentialOutcomes: string[]; // Array of possible outcomes
rules: string[]; // Array of resolution rules
dataSourceDomains: string[]; // Array of allowed data source domains. If set, `resolutionURLs` need to be empty.
resolutionURLs: string[]; // Array of URLs to be used for resolution. If set, `dataSourceDomains` need to be empty.
earliestResolutionDate: string; // ISO date string for earliest resolution
}
Example request:
{
"predictionMarketId": "1",
"title": "Will Bitcoin reach $100k in 2024?",
"description": "This market predicts whether Bitcoin will reach...",
"potentialOutcomes": ["Yes", "No"],
"rules": [
"Price must be reached on at least 3 major exchanges",
"Must maintain price for 1 hour minimum"
],
"dataSourceDomains": [
"coinbase.com",
"binance.com",
"kraken.com"
],
"resolutionURLs": [
"https://api.coinbase.com/v2/prices/BTC-USD/spot",
"https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT"
],
"earliestResolutionDate": "2024-12-31T23:59:59Z"
}
Chat API Endpoints
POST /api/chat
: Send message to AI assistant
Chat Request Schema
{
"messages": [
{
"role": "user" | "assistant" | "system",
"content": "string"
}
]
}
Example request:
{
"messages": [
{
"role": "user",
"content": "__start__"
}
]
}
The __start__
message is used to initialize a new chat session. The API will maintain conversation context across multiple messages in a session.
Example response:
{
"role": "assistant",
"content": "Hello! I'm here to help you configure your Intelligent Oracle. Would you like to start setting up a new prediction market?"
}