Skip to content

Commit 595b770

Browse files
authored
Merge branch 'develop' into develop
2 parents 4c004cf + 2f366f4 commit 595b770

File tree

15 files changed

+452
-32
lines changed

15 files changed

+452
-32
lines changed

.env.example

+14-1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ WALLET_SECRET_SALT= # ONLY define if you want to use TEE Plugin, oth
297297

298298
# Galadriel Configuration
299299
GALADRIEL_API_KEY=gal-* # Get from https://dashboard.galadriel.com/
300+
SMALL_GALADRIEL_MODEL= # Default: gpt-4o-mini
301+
MEDIUM_GALADRIEL_MODEL= # Default: gpt-4o
302+
LARGE_GALADRIEL_MODEL= # Default: gpt-4o
303+
GALADRIEL_FINE_TUNE_API_KEY= # Use an OpenAI key to use a fine-tuned model with the verified inference endpoint
300304

301305
# Venice Configuration
302306
VENICE_API_KEY= # generate from venice settings
@@ -359,7 +363,7 @@ MVX_NETWORK= # must be one of mainnet, devnet, testnet
359363
NEAR_WALLET_SECRET_KEY=
360364
NEAR_WALLET_PUBLIC_KEY=
361365
NEAR_ADDRESS=
362-
SLIPPAGE=1
366+
NEAR_SLIPPAGE=1
363367
NEAR_RPC_URL=https://rpc.testnet.near.org
364368
NEAR_NETWORK=testnet # or mainnet
365369

@@ -436,3 +440,12 @@ OPEN_WEATHER_API_KEY= # OpenWeather API key
436440
# Allora
437441
ALLORA_API_KEY= # Allora API key, format: UP-f8db7d6558ab432ca0d92716
438442
ALLORA_CHAIN_SLUG= # must be one of mainnet, testnet. If not specified, it will use testnet by default
443+
444+
# Opacity zkTLS
445+
OPACITY_TEAM_ID=f309ac8ae8a9a14a7e62cd1a521b1c5f
446+
OPACITY_CLOUDFLARE_NAME=eigen-test
447+
OPACITY_PROVER_URL=https://opacity-ai-zktls-demo.vercel.app
448+
449+
# Verifiable Inference Configuration
450+
VERIFIABLE_INFERENCE_ENABLED=false # Set to false to disable verifiable inference
451+
VERIFIABLE_INFERENCE_PROVIDER=opacity # Options: opacity

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@elizaos/plugin-obsidian": "workspace:*",
7979
"@elizaos/plugin-arthera": "workspace:*",
8080
"@elizaos/plugin-allora": "workspace:*",
81+
"@elizaos/plugin-opacity": "workspace:*",
8182
"readline": "1.3.0",
8283
"ws": "8.18.0",
8384
"yargs": "17.7.2"

agent/src/index.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import net from "net";
8686
import path from "path";
8787
import { fileURLToPath } from "url";
8888
import yargs from "yargs";
89+
import { OpacityAdapter } from "@elizaos/plugin-opacity";
8990

9091
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
9192
const __dirname = path.dirname(__filename); // get the name of the directory
@@ -554,6 +555,28 @@ export async function createAgent(
554555
// });
555556
// elizaLogger.log("Verifiable inference adapter initialized");
556557
// }
558+
// Initialize Opacity adapter if environment variables are present
559+
let verifiableInferenceAdapter;
560+
if (
561+
process.env.OPACITY_TEAM_ID &&
562+
process.env.OPACITY_CLOUDFLARE_NAME &&
563+
process.env.OPACITY_PROVER_URL &&
564+
process.env.VERIFIABLE_INFERENCE_ENABLED === "true"
565+
) {
566+
verifiableInferenceAdapter = new OpacityAdapter({
567+
teamId: process.env.OPACITY_TEAM_ID,
568+
teamName: process.env.OPACITY_CLOUDFLARE_NAME,
569+
opacityProverUrl: process.env.OPACITY_PROVER_URL,
570+
modelProvider: character.modelProvider,
571+
token: token,
572+
});
573+
elizaLogger.log("Verifiable inference adapter initialized");
574+
elizaLogger.log("teamId", process.env.OPACITY_TEAM_ID);
575+
elizaLogger.log("teamName", process.env.OPACITY_CLOUDFLARE_NAME);
576+
elizaLogger.log("opacityProverUrl", process.env.OPACITY_PROVER_URL);
577+
elizaLogger.log("modelProvider", character.modelProvider);
578+
elizaLogger.log("token", token);
579+
}
557580

558581
return new AgentRuntime({
559582
databaseAdapter: db,
@@ -683,7 +706,7 @@ export async function createAgent(
683706
managers: [],
684707
cacheManager: cache,
685708
fetch: logFetch,
686-
// verifiableInferenceAdapter,
709+
verifiableInferenceAdapter,
687710
});
688711
}
689712

packages/core/src/generation.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,18 @@ export async function generateText({
212212
model: modelClass,
213213
verifiableInference,
214214
});
215-
215+
elizaLogger.log("Using provider:", runtime.modelProvider);
216216
// If verifiable inference is requested and adapter is provided, use it
217217
if (verifiableInference && runtime.verifiableInferenceAdapter) {
218+
elizaLogger.log("Using verifiable inference adapter:", runtime.verifiableInferenceAdapter);
218219
try {
219-
const result =
220+
const result: VerifiableInferenceResult =
220221
await runtime.verifiableInferenceAdapter.generateText(
221222
context,
222223
modelClass,
223224
verifiableInferenceOptions
224225
);
225-
226+
elizaLogger.log("Verifiable inference result:", result);
226227
// Verify the proof
227228
const isValid =
228229
await runtime.verifiableInferenceAdapter.verifyProof(result);
@@ -788,7 +789,13 @@ export async function generateText({
788789

789790
case ModelProviderName.GALADRIEL: {
790791
elizaLogger.debug("Initializing Galadriel model.");
792+
const headers = {}
793+
const fineTuneApiKey = runtime.getSetting("GALADRIEL_FINE_TUNE_API_KEY")
794+
if (fineTuneApiKey) {
795+
headers["Fine-Tune-Authentication"] = fineTuneApiKey
796+
}
791797
const galadriel = createOpenAI({
798+
headers,
792799
apiKey: apiKey,
793800
baseURL: endpoint,
794801
fetch: runtime.fetch,

packages/core/src/models.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -558,40 +558,34 @@ export const models: Models = {
558558
},
559559
},
560560
[ModelProviderName.GALADRIEL]: {
561-
endpoint: "https://api.galadriel.com/v1",
561+
endpoint: "https://api.galadriel.com/v1/verified",
562562
model: {
563563
[ModelClass.SMALL]: {
564-
name: "llama3.1:70b",
564+
name: settings.SMALL_GALADRIEL_MODEL || "gpt-4o-mini",
565565
stop: [],
566566
maxInputTokens: 128000,
567567
maxOutputTokens: 8192,
568-
frequency_penalty: 0.5,
569-
presence_penalty: 0.5,
570-
temperature: 0.8,
568+
frequency_penalty: 0.0,
569+
presence_penalty: 0.0,
570+
temperature: 0.6,
571571
},
572572
[ModelClass.MEDIUM]: {
573-
name: "llama3.1:70b",
573+
name: settings.MEDIUM_GALADRIEL_MODEL || "gpt-4o",
574574
stop: [],
575575
maxInputTokens: 128000,
576576
maxOutputTokens: 8192,
577-
frequency_penalty: 0.5,
578-
presence_penalty: 0.5,
579-
temperature: 0.8,
577+
frequency_penalty: 0.0,
578+
presence_penalty: 0.0,
579+
temperature: 0.6,
580580
},
581581
[ModelClass.LARGE]: {
582-
name: "llama3.1:405b",
582+
name: settings.LARGE_GALADRIEL_MODEL || "gpt-4o",
583583
stop: [],
584584
maxInputTokens: 128000,
585585
maxOutputTokens: 8192,
586-
frequency_penalty: 0.5,
587-
presence_penalty: 0.5,
588-
temperature: 0.8,
589-
},
590-
[ModelClass.EMBEDDING]: {
591-
name: "gte-large-en-v1.5",
592-
},
593-
[ModelClass.IMAGE]: {
594-
name: "stabilityai/stable-diffusion-xl-base-1.0",
586+
frequency_penalty: 0.0,
587+
presence_penalty: 0.0,
588+
temperature: 0.6,
595589
},
596590
},
597591
},

packages/core/src/types.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ export interface ISlackService extends Service {
14151415
* Available verifiable inference providers
14161416
*/
14171417
export enum VerifiableInferenceProvider {
1418-
RECLAIM = "reclaim",
1418+
OPACITY = "opacity",
14191419
}
14201420

14211421
/**
@@ -1436,8 +1436,10 @@ export interface VerifiableInferenceOptions {
14361436
export interface VerifiableInferenceResult {
14371437
/** Generated text */
14381438
text: string;
1439-
/** Proof data */
1440-
proof: unknown;
1439+
/** Proof */
1440+
proof: any;
1441+
/** Proof id */
1442+
id?: string;
14411443
/** Provider information */
14421444
provider: VerifiableInferenceProvider;
14431445
/** Timestamp */
@@ -1448,6 +1450,7 @@ export interface VerifiableInferenceResult {
14481450
* Interface for verifiable inference adapters
14491451
*/
14501452
export interface IVerifiableInferenceAdapter {
1453+
options: any;
14511454
/**
14521455
* Generate text with verifiable proof
14531456
* @param context The input text/prompt

packages/plugin-near/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NEAR_WALLET_PUBLIC_KEY=your-wallet-public-key
3535
NEAR_ADDRESS=your-account.near
3636
NEAR_NETWORK=testnet # mainnet or testnet
3737
NEAR_RPC_URL=https://rpc.testnet.near.org
38-
SLIPPAGE=0.01 # 1% slippage tolerance
38+
NEAR_SLIPPAGE=0.01 # 1% slippage tolerance
3939
```
4040

4141
## Usage

packages/plugin-near/src/environment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const nearEnvSchema = z.object({
88
NEAR_WALLET_SECRET_KEY: z.string().min(1, "Wallet secret key is required"),
99
NEAR_WALLET_PUBLIC_KEY: z.string().min(1, "Wallet public key is required"),
1010
NEAR_ADDRESS: z.string().min(1, "Near address is required"),
11-
SLIPPAGE: z.string().min(1, "Slippage is required"),
11+
NEAR_SLIPPAGE: z.string().min(1, "Slippage is required"),
1212
NEAR_RPC_URL: z.string().min(1, "RPC URL is required"),
1313
networkId: z.string(),
1414
nodeUrl: z.string(),
@@ -86,7 +86,7 @@ export async function validateNearConfig(
8686
process.env.NEAR_WALLET_PUBLIC_KEY,
8787
NEAR_ADDRESS:
8888
runtime.getSetting("NEAR_ADDRESS") || process.env.NEAR_ADDRESS,
89-
SLIPPAGE: runtime.getSetting("SLIPPAGE") || process.env.SLIPPAGE,
89+
NEAR_SLIPPAGE: runtime.getSetting("NEAR_SLIPPAGE") || process.env.NEAR_SLIPPAGE,
9090
NEAR_RPC_URL: runtime.getSetting("NEAR_RPC_URL") || process.env.NEAR_RPC_URL,
9191
...envConfig, // Spread the environment-specific config
9292
};

packages/plugin-near/src/providers/wallet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const PROVIDER_CONFIG = {
2020
explorerUrl: `https://${process.env.NEAR_NETWORK || "testnet"}.nearblocks.io`,
2121
MAX_RETRIES: 3,
2222
RETRY_DELAY: 2000,
23-
SLIPPAGE: process.env.SLIPPAGE ? parseInt(process.env.SLIPPAGE) : 1,
23+
SLIPPAGE: process.env.NEAR_SLIPPAGE ? parseInt(process.env.NEAR_SLIPPAGE) : 1,
2424
};
2525

2626
export interface NearToken {

packages/plugin-opacity/README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# @elizaos/adapter-opacity
2+
3+
This adapter integrates Opacity proofs into ElizaOS, enabling verifiable inference results from various AI model providers available through the [CloudFlare AI Gateway](https://developers.cloudflare.com/ai-gateway). It implements the `IVerifiableInferenceAdapter` interface, making it compatible with other verifiable inference solutions.
4+
5+
## Installation
6+
7+
```bash
8+
pnpm add @elizaos/adapter-opacity
9+
```
10+
11+
## Configuration
12+
13+
Add the following environment variables to your `.env` file:
14+
15+
```env
16+
OPACITY_TEAM_ID=f309ac8ae8a9a14a7e62cd1a521b1c5f
17+
OPACITY_CLOUDFLARE_NAME=eigen-test
18+
OPACITY_PROVER_URL=https://opacity-ai-zktls-demo.vercel.app
19+
# Verifiable Inference Configuration
20+
VERIFIABLE_INFERENCE_ENABLED=true # Set to true to enable verifiable inference
21+
VERIFIABLE_INFERENCE_PROVIDER=opacity # Options: opacity
22+
```
23+
(make sure to VERIFIABLE_INFERENCE_ENABLED to true!)
24+
25+
## Usage
26+
27+
```typescript
28+
import { OpacityAdapter } from "@elizaos/adapter-opacity";
29+
import { VerifiableInferenceOptions } from "@elizaos/core";
30+
31+
// Initialize the adapter
32+
const opacityAdapter = new OpacityAdapter(runtime, {
33+
teamId: process.env.OPACITY_TEAM_ID,
34+
teamName: process.env.OPACITY_CLOUDFLARE_NAME,
35+
baseUrl: process.env.OPACITY_PROVER_URL
36+
});
37+
38+
// Generate text with verifiable results
39+
const options: VerifiableInferenceOptions = {
40+
// Optional: Override the default endpoint
41+
endpoint: "https://custom-api.example.com",
42+
// Optional: Add custom headers
43+
headers: {
44+
"X-Custom-Header": "value",
45+
},
46+
// Optional: Provider-specific options
47+
providerOptions: {
48+
temperature: 0.7,
49+
},
50+
};
51+
52+
const result = await opacityAdapter.generateText(
53+
"What is Rust?",
54+
"gpt-4",
55+
options
56+
);
57+
58+
console.log("Response:", result.text);
59+
console.log("Proof:", result.proof);
60+
61+
// Verify the proof
62+
const isValid = await opacityAdapter.verifyProof(result);
63+
console.log("Proof is valid:", isValid);
64+
```
65+
66+
## Features
67+
68+
- Implements `IVerifiableInferenceAdapter` interface for standardized verifiable inference
69+
- Support for multiple AI model provider, in the future may be expanded to accomdate for all gateways [supported by CloudFlare](https://developers.cloudflare.com/ai-gateway/providers/)
70+
- Customizable options for each request
71+
- Built-in proof verification
72+
73+
## Response Format
74+
75+
The adapter returns a `VerifiableInferenceResult` object containing:
76+
77+
```typescript
78+
{
79+
text: string; // The generated text response
80+
proof: unknown; // The proof data
81+
provider: string; // The provider name (e.g., "opacity")
82+
timestamp: number; // Generation timestamp
83+
metadata?: { // Optional metadata
84+
modelProvider: string;
85+
modelClass: string;
86+
endpoint: string;
87+
}
88+
}
89+
```
90+
91+
## How it Works
92+
93+
The Opacity adapter wraps AI model API calls to CloudFlare, then performs MPC-TLS on the logged responses.
94+
95+
96+
This allows you to:
97+
1. Make verifiable API calls to AI model providers
98+
2. Generate proofs of the responses
99+
3. Verify the authenticity of the responses
100+
4. Ensure the responses haven't been tampered with
101+
102+
## Step By Step
103+
```mermaid
104+
sequenceDiagram
105+
autonumber
106+
participant Eliza
107+
participant Cloudflare
108+
participant OpenAI
109+
Eliza ->> Cloudflare : Prompt Req
110+
Cloudflare ->> OpenAI : Prompt Req
111+
OpenAI ->> Cloudflare : Prompt Response
112+
Cloudflare ->> Cloudflare : Log Prompt Response
113+
Cloudflare ->> Eliza : Prompt Response
114+
create participant Opacity
115+
Eliza ->> Opacity : Generate Proof for Prompt Response
116+
Opacity ->> Cloudflare : Fetch Prompt Response Log in MPC-TLS
117+
Cloudflare ->> Opacity : Respond with Prompt Response Log
118+
Opacity ->> Eliza : Return Proof of Prompt Response Log
119+
```
120+
121+
## License
122+
123+
MIT

packages/plugin-opacity/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@elizaos/plugin-opacity",
3+
"version": "0.1.7-alpha.2",
4+
"description": "Opacity Protocol adapter for ElizaOS",
5+
"main": "dist/index.js",
6+
"type": "module",
7+
"types": "dist/index.d.ts",
8+
"scripts": {
9+
"build": "tsup src/index.ts --format esm --dts",
10+
"lint": "eslint --fix --cache .",
11+
"watch": "tsc --watch",
12+
"dev": "tsup src/index.ts --format esm --dts --watch"
13+
},
14+
"dependencies": {
15+
"@elizaos/core": "workspace:*",
16+
"dotenv": "^16.4.5"
17+
},
18+
"devDependencies": {
19+
"tsup": "^8.3.5"
20+
}
21+
}

0 commit comments

Comments
 (0)