Init oracle with others providers

This commit is contained in:
ngoc 2026-01-02 16:45:02 +07:00
parent f42408c825
commit 29f8e5c617
No known key found for this signature in database
GPG Key ID: 51FE6110113A5C32
2 changed files with 59 additions and 10 deletions

View File

@ -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-...

View File

@ -20,7 +20,9 @@ Usage:
Options:
--rpc-url <url> RPC URL for the blockchain network (required)
--private-key <key> Private key of the oracle operator (required)
--openai-api-key <key> OpenAI API key (required)
--openai-api-key <key> OpenAI API key (optional)
--anthropic-api-key <key> Anthropic API key (optional)
--openrouter-api-key <key> OpenRouter API key (optional)
--eas-contract <address> EAS contract address (optional)
--deployment <file> Load addresses from deployment file (optional)
--polling-interval <ms> 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