Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove verifiable inference concept, will be plugin loaded #3344

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ export async function createAgent(
// elizaLogger.log("Verifiable inference adapter initialized");
// }
// Initialize Opacity adapter if environment variables are present
let verifiableInferenceAdapter = null;
// let verifiableInferenceAdapter = null;
// if (
// process.env.OPACITY_TEAM_ID &&
// process.env.OPACITY_CLOUDFLARE_NAME &&
Expand Down Expand Up @@ -1017,7 +1017,7 @@ export async function createAgent(
providers: [],
managers: [],
fetch: logFetch,
verifiableInferenceAdapter,
// verifiableInferenceAdapter,
});
}

Expand Down
94 changes: 47 additions & 47 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import {
ModelProviderName,
ServiceType,
type ActionResponse,
type IVerifiableInferenceAdapter,
type VerifiableInferenceOptions,
type VerifiableInferenceResult,
// type IVerifiableInferenceAdapter,
// type VerifiableInferenceOptions,
// type VerifiableInferenceResult,
//VerifiableInferenceProvider,
type TelemetrySettings,
TokenizerType,
Expand Down Expand Up @@ -347,8 +347,8 @@ export async function generateText({
maxSteps = 1,
stop,
customSystemPrompt,
verifiableInference = process.env.VERIFIABLE_INFERENCE_ENABLED === "true",
verifiableInferenceOptions,
// verifiableInference = process.env.VERIFIABLE_INFERENCE_ENABLED === "true",
// verifiableInferenceOptions,
}: {
runtime: IAgentRuntime;
context: string;
Expand All @@ -358,9 +358,9 @@ export async function generateText({
maxSteps?: number;
stop?: string[];
customSystemPrompt?: string;
verifiableInference?: boolean;
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
verifiableInferenceOptions?: VerifiableInferenceOptions;
// verifiableInference?: boolean;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
// verifiableInferenceOptions?: VerifiableInferenceOptions;
}): Promise<string> {
if (!context) {
console.error("generateText context is empty");
Expand All @@ -372,36 +372,36 @@ export async function generateText({
elizaLogger.info("Generating text with options:", {
modelProvider: runtime.modelProvider,
model: modelClass,
verifiableInference,
// verifiableInference,
});
elizaLogger.log("Using provider:", runtime.modelProvider);
// If verifiable inference is requested and adapter is provided, use it
if (verifiableInference && runtime.verifiableInferenceAdapter) {
elizaLogger.log(
"Using verifiable inference adapter:",
runtime.verifiableInferenceAdapter
);
try {
const result: VerifiableInferenceResult =
await runtime.verifiableInferenceAdapter.generateText(
context,
modelClass,
verifiableInferenceOptions
);
elizaLogger.log("Verifiable inference result:", result);
// Verify the proof
const isValid =
await runtime.verifiableInferenceAdapter.verifyProof(result);
if (!isValid) {
throw new Error("Failed to verify inference proof");
}

return result.text;
} catch (error) {
elizaLogger.error("Error in verifiable inference:", error);
throw error;
}
}
// if (verifiableInference && runtime.verifiableInferenceAdapter) {
// elizaLogger.log(
// "Using verifiable inference adapter:",
// runtime.verifiableInferenceAdapter
// );
// try {
// const result: VerifiableInferenceResult =
// await runtime.verifiableInferenceAdapter.generateText(
// context,
// modelClass,
// verifiableInferenceOptions
// );
// elizaLogger.log("Verifiable inference result:", result);
// // Verify the proof
// const isValid =
// await runtime.verifiableInferenceAdapter.verifyProof(result);
// if (!isValid) {
// throw new Error("Failed to verify inference proof");
// }

// return result.text;
// } catch (error) {
// elizaLogger.error("Error in verifiable inference:", error);
// throw error;
// }
// }

const provider = runtime.modelProvider;
elizaLogger.debug("Provider settings:", {
Expand Down Expand Up @@ -2050,9 +2050,9 @@ export interface GenerationOptions {
stop?: string[];
mode?: "auto" | "json" | "tool";
experimental_providerMetadata?: Record<string, unknown>;
verifiableInference?: boolean;
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
verifiableInferenceOptions?: VerifiableInferenceOptions;
// verifiableInference?: boolean;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
// verifiableInferenceOptions?: VerifiableInferenceOptions;
}

/**
Expand Down Expand Up @@ -2084,9 +2084,9 @@ export const generateObject = async ({
schemaDescription,
stop,
mode = "json",
verifiableInference = false,
verifiableInferenceAdapter,
verifiableInferenceOptions,
// verifiableInference = false,
// verifiableInferenceAdapter,
// verifiableInferenceOptions,
}: GenerationOptions): Promise<GenerateObjectResult<unknown>> => {
if (!context) {
const errorMessage = "generateObject context is empty";
Expand Down Expand Up @@ -2130,9 +2130,9 @@ export const generateObject = async ({
runtime,
context,
modelClass,
verifiableInference,
verifiableInferenceAdapter,
verifiableInferenceOptions,
// verifiableInference,
// verifiableInferenceAdapter,
// verifiableInferenceOptions,
});

return response;
Expand All @@ -2158,9 +2158,9 @@ interface ProviderOptions {
modelOptions: ModelSettings;
modelClass: ModelClass;
context: string;
verifiableInference?: boolean;
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
verifiableInferenceOptions?: VerifiableInferenceOptions;
// verifiableInference?: boolean;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
// verifiableInferenceOptions?: VerifiableInferenceOptions;
}

/**
Expand Down
18 changes: 5 additions & 13 deletions packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
type IDatabaseAdapter,
type IMemoryManager,
type IRAGKnowledgeManager,
type IVerifiableInferenceAdapter,
// type IVerifiableInferenceAdapter,
type KnowledgeItem,
// RAGKnowledgeItem,
//Media,
Expand Down Expand Up @@ -178,7 +178,7 @@ export class AgentRuntime implements IAgentRuntime {
cacheManager: ICacheManager;
clients: ClientInstance[] = [];

verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter;

registerMemoryManager(manager: IMemoryManager): void {
if (!manager.tableName) {
Expand Down Expand Up @@ -261,7 +261,7 @@ export class AgentRuntime implements IAgentRuntime {
speechModelPath?: string;
cacheManager?: ICacheManager;
logging?: boolean;
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
}) {
// use the character id if it exists, otherwise use the agentId if it is passed in, otherwise use the character name
this.agentId =
Expand Down Expand Up @@ -439,7 +439,7 @@ export class AgentRuntime implements IAgentRuntime {
this.registerEvaluator(evaluator);
});

this.verifiableInferenceAdapter = opts.verifiableInferenceAdapter;
// this.verifiableInferenceAdapter = opts.verifiableInferenceAdapter;
}

private async initializeDatabase() {
Expand Down Expand Up @@ -1138,7 +1138,7 @@ export class AgentRuntime implements IAgentRuntime {
runtime: this,
context,
modelClass: ModelClass.SMALL,
verifiableInferenceAdapter: this.verifiableInferenceAdapter,
// verifiableInferenceAdapter: this.verifiableInferenceAdapter,
});

const evaluators = parseJsonArrayFromText(
Expand Down Expand Up @@ -1783,14 +1783,6 @@ Text: ${attachment.text}
attachments: formattedAttachments,
} as State;
}

getVerifiableInferenceAdapter(): IVerifiableInferenceAdapter | undefined {
return this.verifiableInferenceAdapter;
}

setVerifiableInferenceAdapter(adapter: IVerifiableInferenceAdapter): void {
this.verifiableInferenceAdapter = adapter;
}
}

const formatKnowledge = (knowledge: KnowledgeItem[]) => {
Expand Down
126 changes: 63 additions & 63 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ export interface IAgentRuntime {
services: Map<ServiceType, Service>;
clients: ClientInstance[];

verifiableInferenceAdapter?: IVerifiableInferenceAdapter | null;
// verifiableInferenceAdapter?: IVerifiableInferenceAdapter | null;

initialize(): Promise<void>;

Expand Down Expand Up @@ -1569,68 +1569,68 @@ export interface ISlackService extends Service {
client: any;
}

/**
* Available verifiable inference providers
*/
export enum VerifiableInferenceProvider {
RECLAIM = "reclaim",
OPACITY = "opacity",
PRIMUS = "primus",
}

/**
* Options for verifiable inference
*/
export interface VerifiableInferenceOptions {
/** Custom endpoint URL */
endpoint?: string;
/** Custom headers */
headers?: Record<string, string>;
/** Provider-specific options */
providerOptions?: Record<string, unknown>;
}

/**
* Result of a verifiable inference request
*/
export interface VerifiableInferenceResult {
/** Generated text */
text: string;
/** Proof */
proof: any;
/** Proof id */
id?: string;
/** Provider information */
provider: VerifiableInferenceProvider;
/** Timestamp */
timestamp: number;
}

/**
* Interface for verifiable inference adapters
*/
export interface IVerifiableInferenceAdapter {
options: any;
/**
* Generate text with verifiable proof
* @param context The input text/prompt
* @param modelClass The model class/name to use
* @param options Additional provider-specific options
* @returns Promise containing the generated text and proof data
*/
generateText(
context: string,
modelClass: string,
options?: VerifiableInferenceOptions,
): Promise<VerifiableInferenceResult>;

/**
* Verify the proof of a generated response
* @param result The result containing response and proof to verify
* @returns Promise indicating if the proof is valid
*/
verifyProof(result: VerifiableInferenceResult): Promise<boolean>;
}
// /**
// * Available verifiable inference providers
// */
// export enum VerifiableInferenceProvider {
// RECLAIM = "reclaim",
// OPACITY = "opacity",
// PRIMUS = "primus",
// }

// /**
// * Options for verifiable inference
// */
// export interface VerifiableInferenceOptions {
// /** Custom endpoint URL */
// endpoint?: string;
// /** Custom headers */
// headers?: Record<string, string>;
// /** Provider-specific options */
// providerOptions?: Record<string, unknown>;
// }

// /**
// * Result of a verifiable inference request
// */
// export interface VerifiableInferenceResult {
// /** Generated text */
// text: string;
// /** Proof */
// proof: any;
// /** Proof id */
// id?: string;
// /** Provider information */
// provider: VerifiableInferenceProvider;
// /** Timestamp */
// timestamp: number;
// }

// /**
// * Interface for verifiable inference adapters
// */
// export interface IVerifiableInferenceAdapter {
// options: any;
// /**
// * Generate text with verifiable proof
// * @param context The input text/prompt
// * @param modelClass The model class/name to use
// * @param options Additional provider-specific options
// * @returns Promise containing the generated text and proof data
// */
// generateText(
// context: string,
// modelClass: string,
// options?: VerifiableInferenceOptions,
// ): Promise<VerifiableInferenceResult>;

// /**
// * Verify the proof of a generated response
// * @param result The result containing response and proof to verify
// * @returns Promise indicating if the proof is valid
// */
// verifyProof(result: VerifiableInferenceResult): Promise<boolean>;
// }

export enum TokenizerType {
Auto = "auto",
Expand Down
Loading