-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
inference.ts
Outdated
import {createZGComputeNetworkBroker} from './src.ts' | ||
import OpenAI from 'openai' | ||
|
||
async function main() { |
There was a problem hiding this comment.
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.
src.ts/inference/broker/base.ts
Outdated
@@ -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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
src.ts/inference/broker/base.ts
Outdated
|
||
async updateCachedFee(provide: string, fee: bigint) { | ||
try { | ||
const curFee = await this.cache.getItemOr(provide, BigInt(0)) |
There was a problem hiding this comment.
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)
?
src.ts/inference/broker/base.ts
Outdated
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) { |
There was a problem hiding this comment.
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.
src.ts/inference/broker/broker.ts
Outdated
@@ -356,6 +326,25 @@ export class InferenceBroker { | |||
throw error | |||
} | |||
} | |||
|
|||
/** | |||
* retrive fund from all inference account back to ledger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* retrive fund from all inference account back to ledger | |
* retrieve fund from all inference account back to ledger |
src.ts/inference/broker/model.ts
Outdated
|
||
async getService(svcName: string): Promise<ServiceStructOutput> { | ||
try { | ||
const services = await this.listService() |
There was a problem hiding this comment.
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)
src.ts/inference/broker/request.ts
Outdated
@@ -47,6 +51,19 @@ export interface ServingRequestHeaders { | |||
* before use. | |||
*/ | |||
export class RequestProcessor extends ZGServingUserBrokerBase { | |||
private checkAccountThreshold = BigInt(1000) | |||
private topupAccountThreshold = BigInt(5000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private topupAccountThreshold = BigInt(5000) | |
private topUpTriggerThreshold= BigInt(5000) | |
private topUpTargetThreshold = BigInt(10000) |
This change is