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: sort out inference code after refactor for finetune #9

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sidosidonie
Copy link
Collaborator

@sidosidonie sidosidonie commented Jan 14, 2025

This change is Reviewable

@0g-peterzhb 0g-peterzhb requested a review from Ravenyjh January 14, 2025 23:06
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/request.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/response.ts Outdated Show resolved Hide resolved
src.ts/inference/broker/broker.ts Outdated Show resolved Hide resolved
inference.ts Outdated
import {createZGComputeNetworkBroker} from './src.ts'
import OpenAI from 'openai'

async function main() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After local testing, integrate the content into src.ts/example/inference.md. There's no need to add another file.

@@ -6,6 +6,7 @@ import { ServingRequestHeaders } from './request'
import { decryptData, getNonce, strToPrivateKey } from '../../common/utils'
import { PackedPrivkey, Request, signData } from '../../common/settle-signer'
import { Cache, CacheValueTypeEnum } from '../storage'
import {LedgerBroker} from "../../ledger";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


async updateCachedFee(provide: string, fee: bigint) {
try {
const curFee = await this.cache.getItemOr(provide, BigInt(0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need getItemOr but just use this.cache.getItem(key) || BigInt(0) ?

const svc = await extractor.getSvcInfo()
const inputCount = await extractor.getInputCount(content)
const inputFee = BigInt(inputCount) * svc.inputPrice
return inputFee
}

async updateCachedFee(provide: string, fee: bigint) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent duplication, the cache key should be formatted as ${providerAddress}_${serviceName}_cachedFee.

@@ -356,6 +326,25 @@ export class InferenceBroker {
throw error
}
}

/**
* retrive fund from all inference account back to ledger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* retrive fund from all inference account back to ledger
* retrieve fund from all inference account back to ledger


async getService(svcName: string): Promise<ServiceStructOutput> {
try {
const services = await this.listService()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use await this.contract.getService(providerAddress, svcName)

@@ -47,6 +51,19 @@ export interface ServingRequestHeaders {
* before use.
*/
export class RequestProcessor extends ZGServingUserBrokerBase {
private checkAccountThreshold = BigInt(1000)
private topupAccountThreshold = BigInt(5000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private topupAccountThreshold = BigInt(5000)
private topUpTriggerThreshold= BigInt(5000)
private topUpTargetThreshold = BigInt(10000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants