import type { AccountStructOutput } from '../contract'; import type { JsonRpcSigner, Wallet } from 'ethers'; import { RequestProcessor } from './request'; import { ResponseProcessor } from './response'; import { Verifier } from './verifier'; import { AccountProcessor } from './account'; import { ModelProcessor } from './model'; import type { LedgerBroker } from '../../ledger'; export declare class InferenceBroker { requestProcessor: RequestProcessor; responseProcessor: ResponseProcessor; verifier: Verifier; accountProcessor: AccountProcessor; modelProcessor: ModelProcessor; private signer; private contractAddress; private ledger; constructor(signer: JsonRpcSigner | Wallet, contractAddress: string, ledger: LedgerBroker); initialize(): Promise; /** * Retrieves a list of services from the contract. * * @returns {Promise} A promise that resolves to an array of ServiceStructOutput objects. * @throws An error if the service list cannot be retrieved. */ listService: () => Promise; /** * Retrieves the account information for a given provider address. * * @param {string} providerAddress - The address of the provider identifying the account. * * @returns A promise that resolves to the account information. * * @throws Will throw an error if the account retrieval process fails. */ getAccount: (providerAddress: string) => Promise; getAccountWithDetail: (providerAddress: string) => Promise<[AccountStructOutput, { amount: bigint; remainTime: bigint; }[]]>; /** * checks if the user has acknowledged the provider signer. * * @param {string} providerAddress - The address of the provider. * @returns {Promise} A promise that resolves to a boolean indicating whether the user * has acknowledged the provider signer. * @throws Will throw an error if the acknowledgment check fails. */ userAcknowledged: (providerAddress: string) => Promise; /** * Acknowledge the given provider address. * * @param {string} providerAddress - The address of the provider identifying the account. * * * @throws Will throw an error if failed to acknowledge. */ acknowledgeProviderSigner: (providerAddress: string, gasPrice?: number) => Promise; /** * Generates request metadata for the provider service. * Includes: * 1. Request endpoint for the provider service * 2. Model information for the provider service * * @param {string} providerAddress - The address of the provider. * * @returns { endpoint, model } - Object containing endpoint and model. * * @throws An error if errors occur during the processing of the request. */ getServiceMetadata: (providerAddress: string) => Promise<{ endpoint: string; model: string; }>; /** * getRequestHeaders generates billing-related headers for the request * when the user uses the provider service. * * In the 0G Serving system, a request with valid billing headers * is considered a settlement proof and will be used by the provider * for contract settlement. * * @param {string} providerAddress - The address of the provider. * @param {string} content - The content being billed. For example, in a chatbot service, it is the text input by the user. * @param {boolean} vllmProxy - Chat signature proxy, default is false * * @returns headers. Records information such as the request fee and user signature. * * @example * * const { endpoint, model } = await broker.getServiceMetadata( * providerAddress, * serviceName, * ); * * const headers = await broker.getServiceMetadata( * providerAddress, * serviceName, * content, * ); * * const openai = new OpenAI({ * baseURL: endpoint, * apiKey: "", * }); * * const completion = await openai.chat.completions.create( * { * messages: [{ role: "system", content }], * model, * }, * headers: { * ...headers, * }, * ); * * @throws An error if errors occur during the processing of the request. */ getRequestHeaders: (providerAddress: string, content: string, vllmProxy?: boolean) => Promise; /** * processResponse is used after the user successfully obtains a response from the provider service. * * It will settle the fee for the response content. Additionally, if the service is verifiable, * input the chat ID from the response and processResponse will determine the validity of the * returned content by checking the provider service's response and corresponding signature associated * with the chat ID. * * @param {string} providerAddress - The address of the provider. * @param {string} content - The main content returned by the service. For example, in the case of a chatbot service, * it would be the response text. * @param {string} chatID - Only for verifiable services. You can provide the chat ID obtained from the response to * automatically download the response signature. The function will verify the reliability of the response * using the service's signing address. * @param {boolean} vllmProxy - Chat signature proxy, default is true * * @returns A boolean value. True indicates the returned content is valid, otherwise it is invalid. * * @throws An error if any issues occur during the processing of the response. */ processResponse: (providerAddress: string, content: string, chatID?: string, vllmProxy?: boolean) => Promise; /** * verifyService is used to verify the reliability of the service. * * @param {string} providerAddress - The address of the provider. * * @returns A value. True indicates the service is reliable, otherwise it is unreliable. * * @throws An error if errors occur during the verification process. */ verifyService: (providerAddress: string) => Promise; /** * getSignerRaDownloadLink returns the download link for the Signer RA. * * It can be provided to users who wish to manually verify the Signer RA. * * @param {string} providerAddress - provider address. * * @returns Download link. */ getSignerRaDownloadLink: (providerAddress: string) => Promise; /** * getChatSignatureDownloadLink returns the download link for the signature of a single chat. * * It can be provided to users who wish to manually verify the content of a single chat. * * @param {string} providerAddress - provider address. * @param {string} chatID - ID of the chat. * * @remarks To verify the chat signature, use the following code: * * ```typescript * const messageHash = ethers.hashMessage(messageToBeVerified) * const recoveredAddress = ethers.recoverAddress(messageHash, signature) * const isValid = recoveredAddress.toLowerCase() === signingAddress.toLowerCase() * ``` * * @returns Download link. */ getChatSignatureDownloadLink: (providerAddress: string, chatID: string) => Promise; } /** * createInferenceBroker is used to initialize ZGServingUserBroker * * @param signer - Signer from ethers.js. * @param contractAddress - 0G Serving contract address, use default address if not provided. * * @returns broker instance. * * @throws An error if the broker cannot be initialized. */ export declare function createInferenceBroker(signer: JsonRpcSigner | Wallet, contractAddress: string, ledger: LedgerBroker): Promise; //# sourceMappingURL=broker.d.ts.map