From 29f8e5c617fe3482ed6c436583232d6fab63fed0 Mon Sep 17 00:00:00 2001 From: ngoc Date: Fri, 2 Jan 2026 16:45:02 +0700 Subject: [PATCH] Init oracle with others providers --- .env.example | 14 ++++++++++- cli/server/oracle.ts | 55 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 2dd1a25..aae978b 100644 --- a/.env.example +++ b/.env.example @@ -34,7 +34,19 @@ ORACLE_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b7 # ================================ # AI CONFIGURATION # ================================ +# At least ONE of the following API keys is required for the oracle to function -# OpenAI API Key (required for oracle) +# OpenAI API Key (optional) # Get your API key from https://platform.openai.com/api-keys +# Supports models: gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-3.5-turbo OPENAI_API_KEY=sk-proj... + +# Anthropic API Key (optional) +# Get your API key from https://console.anthropic.com/ +# Supports models: claude-3-5-sonnet-20241022, claude-3-opus-20240229, claude-3-sonnet-20240229 +# ANTHROPIC_API_KEY=sk-ant-... + +# OpenRouter API Key (optional) +# Get your API key from https://openrouter.ai/keys +# Supports any model available on OpenRouter (e.g., openai/gpt-4, anthropic/claude-3-opus) +# OPENROUTER_API_KEY=sk-or-... diff --git a/cli/server/oracle.ts b/cli/server/oracle.ts index 3ab3d59..3c1c251 100644 --- a/cli/server/oracle.ts +++ b/cli/server/oracle.ts @@ -20,7 +20,9 @@ Usage: Options: --rpc-url RPC URL for the blockchain network (required) --private-key Private key of the oracle operator (required) - --openai-api-key OpenAI API key (required) + --openai-api-key OpenAI API key (optional) + --anthropic-api-key Anthropic API key (optional) + --openrouter-api-key OpenRouter API key (optional) --eas-contract
EAS contract address (optional) --deployment Load addresses from deployment file (optional) --polling-interval Polling interval in milliseconds (default: 5000) @@ -30,6 +32,8 @@ Environment Variables (alternative to CLI options): RPC_URL RPC URL for the blockchain network ORACLE_PRIVATE_KEY Private key of the oracle operator OPENAI_API_KEY OpenAI API key + ANTHROPIC_API_KEY Anthropic API key + OPENROUTER_API_KEY OpenRouter API key EAS_CONTRACT_ADDRESS EAS contract address Examples: @@ -55,6 +59,8 @@ function parseCliArgs() { "rpc-url": { type: "string" }, "private-key": { type: "string" }, "openai-api-key": { type: "string" }, + "anthropic-api-key": { type: "string" }, + "openrouter-api-key": { type: "string" }, "eas-contract": { type: "string" }, "deployment": { type: "string" }, "polling-interval": { type: "string" }, @@ -109,6 +115,8 @@ async function main() { const privateKey = args["private-key"] || process.env.ORACLE_PRIVATE_KEY; const openaiApiKey = args["openai-api-key"] || process.env.OPENAI_API_KEY; + const anthropicApiKey = args["anthropic-api-key"] || process.env.ANTHROPIC_API_KEY; + const openrouterApiKey = args["openrouter-api-key"] || process.env.OPENROUTER_API_KEY; const pollingInterval = parseInt(args["polling-interval"] || "5000"); // Validate required parameters @@ -124,8 +132,10 @@ async function main() { process.exit(1); } - if (!openaiApiKey) { - console.error("āŒ Error: OpenAI API key is required. Use --openai-api-key or set OPENAI_API_KEY environment variable."); + // Check if at least one API key is provided + if (!openaiApiKey && !anthropicApiKey && !openrouterApiKey) { + console.error("āŒ Error: At least one LLM provider API key is required."); + console.error(" Set one of: OPENAI_API_KEY, ANTHROPIC_API_KEY, or OPENROUTER_API_KEY"); console.error("Run with --help for usage information."); process.exit(1); } @@ -134,7 +144,14 @@ async function main() { console.log("Configuration:"); console.log(` šŸ“” RPC URL: ${rpcUrl}`); console.log(` šŸ”‘ Oracle Key: ${privateKey.slice(0, 6)}...${privateKey.slice(-4)}`); - console.log(` šŸ¤– AI Provider: OpenAI`); + + // Show available providers + const availableProviders = []; + if (openaiApiKey) availableProviders.push("OpenAI"); + if (anthropicApiKey) availableProviders.push("Anthropic"); + if (openrouterApiKey) availableProviders.push("OpenRouter"); + console.log(` šŸ¤– AI Providers: ${availableProviders.join(", ")}`); + if (easContract) { console.log(` šŸ“ EAS Contract: ${easContract}`); } @@ -158,12 +175,32 @@ async function main() { llm: makeLLMClient([]), })); - llmClient.llm.addProvider({ - providerName: "OpenAI", - apiKey: openaiApiKey, - }); + // Add all available providers + if (openaiApiKey) { + llmClient.llm.addProvider({ + providerName: "OpenAI", + apiKey: openaiApiKey, + }); + console.log("āœ… OpenAI provider configured"); + } - console.log("šŸŽÆ LLM Arbitrator configured and ready\n"); + if (anthropicApiKey) { + llmClient.llm.addProvider({ + providerName: "Anthropic", + apiKey: anthropicApiKey, + }); + console.log("āœ… Anthropic provider configured"); + } + + if (openrouterApiKey) { + llmClient.llm.addProvider({ + providerName: "OpenRouter", + apiKey: openrouterApiKey, + }); + console.log("āœ… OpenRouter provider configured"); + } + + console.log("\nšŸŽÆ LLM Arbitrator configured and ready\n"); console.log("šŸ‘‚ Listening for arbitration requests...\n"); // Define the obligation ABI