APP Router Readme 0.0.1
NOTE: For builder's kit instructions, please see the builder's kit README file at builder's kit README.
This is a sample app using Morpheus inference in a Next.js app hosted on Google Cloud. The app consists of two parts:
- App proxy router that exists in a Docker container.
- A front end that the user uses to send prompts and see responses from the App router
- Overview
- Builder's Kit Instructions
- Guide
- Getting Started
- Deployment
- Service Architecture
- Environment Variables
- Monitoring & Logs
- Cleanup
You will need to set up the app router in order to open and close inference sessions on the Morpheus network. There is a complete guide for this in the Morpheus Marketplace Docs
For this particular demo we have installed the app router on a Google Cloud Run service to host Docker containers.
- For step-by-step instructions for running the Builders' Kit project locally (requires Docker), please refer to the Builders' Kit Local Guide in the node-red-example directory: Builders' Kit Local Guide.
Follow the steps below to deploy the App Router and configure the system for Morpheus inference.
-
Collect at least 10 MOR that will be used to pay for inference on the Morpheus network. The address's secret key used for this demo will be potentially exposed so use a new address that you don't use for anything else besides this demo.
-
Make sure you have at least 0.1 ETH in your consumder node. This is the minimum required gas to operate the system.
-
Set up your hosting so it can host the 3 Docker Containers required for this demo. We are using Google Cloud. You can use any cloud service the hosts docker containers.
For the required environment variables see ./cloud/config.example.sh
-
The `./cloud/deploy-all.sh script basically deploys the 3 Docker containers to Google Cloud Run. You can also deploy each container individually with the other scripts in the cloud directory. If you're not using google cloud, you should be able to comment out the gcloud commands and replace them with the commands for your cloud service, or just use the docker commands to push your containers where you need them for your cloud service.
-
Environment variables
The following variables are used across the sample deployment:
-
GCP Project
PROJECT_ID
– GCP project IDREGION
– GCP regionZONE
– GCP zoneDOCKER_REGISTRY
– Docker registry name
-
API Configuration
OPENAI_API_URL
– URL for the NFA ProxyCONSUMER_URL
– URL for Consumer Node
-
Contract Configuration
DIAMOND_CONTRACT_ADDRESS
– Address of the diamond contractWALLET_PRIVATE_KEY
– Private key for transactions
-
Service Configuration
INTERNAL_API_PORT
– Internal port for API containerMARKETPLACE_PORT
– Consumer Node portSESSION_DURATION
– Session duration (e.g. "1h")
-
Additional
MARKETPLACE_BASE_URL
– Base URL for MarketplaceMARKETPLACE_URL
– Public URL for MarketplaceNFA_PROXY_URL
– Public URL for the NFA Proxy
-
Versions
NFA_PROXY_VERSION
– Tag for the proxy imageCONSUMER_NODE_VERSION
– Tag for the consumer image
-
Consumer Node - for more context see lumerin protocol docs (https://github.com/Lumerin-protocol/Morpheus-Lumerin-Node/blob/dev/docs/proxy-router.all.env)
BLOCKCHAIN_WS_URL
– WebSocket endpoint for chain eventsBLOCKCHAIN_HTTP_URL
– HTTP endpoint for chain transactionsLOG_LEVEL
– Logging detail (info/debug)LOG_FORMAT
– Log output format (text/json)PROVIDER_CACHE_TTL
– Cache TTL in secondsMAX_CONCURRENT_SESSIONS
– Max concurrency limitSESSION_TIMEOUT
– Timeout in secondsMOR_TOKEN_ADDRESS
– MOR token addressEXPLORER_API_URL
– Blockchain explorer endpointETH_NODE_CHAIN_ID
– Ethereum chain IDENVIRONMENT
– App environment (development/production)PROXY_ADDRESS
– Consumer Node's proxy bind addressWEB_ADDRESS
– Consumer Node's web interface addressWEB_PUBLIC_URL
– Consumer Node's public URLETH_NODE_USE_SUBSCRIPTIONS
– Enable chain event subscriptionsETH_NODE_ADDRESS
– Ethereum RPC node URLETH_NODE_LEGACY_TX
– True to enforce legacy transactionsPROXY_STORE_CHAT_CONTEXT
– Activates chat context storagePROXY_STORAGE_PATH
– Storage path for dataLOG_COLOR
– True to enable colored logs
- Google Cloud Account
- Google Cloud SDK installed Setup Instructions
- Google Cloud Run and necessary APIs enabled
- Logged in with
gcloud auth login
- Node.js >=16
- npm >=7
- Docker
git clone https://github.com/srt0422/morpheus-quickstart-node.git
cd morpheus-quickstart-node
- Copy the example environment file:
cp cloud/config.example.sh cloud/config.sh
- Edit
cloud/config.sh
with your settings:
- Add your GCP project id (PROJECT_ID)
- Add your wallet private key (WALLET_PRIVATE_KEY)
- Add your password for the consumer node (CONSUMER_PASSWORD)
export PROJECT_ID="your-project-id"
export REGION="us-central1"
export ZONE="us-central1-a"
export DOCKER_REGISTRY="srt0422" # Using Docker Hub registry instead of GCR
# Service Configuration
export NFA_PROXY_PORT="8080"
export CONSUMER_PORT="3333"
export WEBAPP_PORT="3000"
# Authentication Configuration
export CONSUMER_USERNAME="admin" # Username for proxy and consumer node authentication
export CONSUMER_PASSWORD="your-secure-password" # Password for proxy and consumer node authentication
# Wallet Configuration
export WALLET_PRIVATE_KEY="your-wallet-private-key"
# Contract Configuration
export DIAMOND_CONTRACT_ADDRESS="0xb8C55cD613af947E73E262F0d3C54b7211Af16CF"
Deploy all services with:
./cloud/deploy-all.sh
## Docker Images
The deployment uses the following pre-built Docker Hub images:
- NFA Proxy: `srt0422/openai-morpheus-proxy:latest`
- Consumer Node: `srt0422/morpheus-marketplace-consumer:latest`
The Chat Web App is deployed directly from the source code to Google Cloud Run.
## Deployment
### Single Command Deployment
Deploy all services with:
```bash
./cloud/deploy-all.sh
Deploy services separately:
# Deploy NFA Proxy
./cloud/deploy-proxy.sh
# Deploy Consumer Node
./cloud/deploy-consumer.sh
# Deploy Chat Web App
./cloud/deploy-webapp.sh
Chat Web App (Frontend)
↓
NFA Proxy (API Layer)
↓
Consumer Node (Morpheus Integration Layer)
API_LISTEN_PORT
: Internal service port (default: 8080)
PROXY_URL
: URL of NFA Proxy servicePORT
: Service port (default: 3333)WALLET_PRIVATE_KEY
: Your Ethereum wallet private key (required for blockchain interactions)DIAMOND_CONTRACT_ADDRESS
: The deployed diamond contract addressBLOCKCHAIN_WS_URL
: Websocket URL for blockchain eventsBLOCKCHAIN_HTTP_URL
: HTTP URL for blockchain transactionsLOG_LEVEL
: Logging level (default: info)LOG_FORMAT
: Log format (text/json, default: text)PROVIDER_CACHE_TTL
: Provider cache time-to-live in seconds (default: 60)MAX_CONCURRENT_SESSIONS
: Maximum concurrent sessions (default: 100)SESSION_TIMEOUT
: Session timeout in seconds (default: 3600)
OPENAI_API_URL
: URL of Consumer NodePORT
: Web app port (default: 3000)
View service logs:
gcloud logging tail "resource.type=cloud_run_revision"
Remove all deployed services:
./cloud/cleanup.sh
- Launched a highly engaging and user-friendly chat experience that demonstrates the inference capabilities of the Morpheus network.
- Delivered an intuitive interface designed to enhance developer engagement and drive increases in inference usage.
- Implemented robust security and reliability measures that foster trust and protect valuable customer data.
- Established a scalable foundation for Morpheus builders that opens doors for future innovations and continuous improvement.
- Added Node-RED integration with pre-built flows for common tasks like batch processing and data transformation
- Added Google Cloud Run auto-scaling configuration and basic request logging
- Added new API endpoints for system status updates and notifications
- Added Node-RED custom node support for extending functionality with new drag-n-drop node-red node and custom deploymentflow (deploys the image https://hub.docker.com/repository/docker/srt0422/openai-morpheus-proxy/tags)
- Built and pushed the docker image to Docker Hub and Google Container Registry (https://hub.docker.com/repository/docker/srt0422/nodered-example/tags)
- This update provides an Open AI api gateway to the morpheus network
- Created a custom node-red plugin for deploying the morpheus consumer node
- Added reasonable default configuration values to minimize setup requirements for builders
- Created a sample google cloud run deployment flow "Morpheus Deployment Flow" to replace "Deploy Proxy Flow"
- The consumer-node plugin now offers significant value to builders through:
- Streamlined deployment with pre-configured settings
- Reduced implementation time through sensible defaults and improved UI
- Enhanced security through proper authentication configuration
- Simplified integration with the proxy component via automated data flow
- Accelerated time-to-market for Morpheus-powered applications