|
| 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 |
0 commit comments