Core Functions
Here’s an overview of the main functions required for initAIAccessPoint:
checkBalanceCondition
This function halts any active services associated with a given NFT ID. It identifies ongoing services and attempts to stop them, helping manage resources effectively.
import { NFTCosts } from '@decloudlabs/Skynet-SmartAccessPoint /lib/types/types';
import { APICallReturn } from '@decloudlabs/sky-cluster-operator/lib/types/types';
import { stopService } from './clients/runpod'; // Assuming `stopService` stops a specific service
const checkBalanceCondition = async (nftCosts: NFTCosts): Promise<APICallReturn<boolean>> => {
console.log(`Checking running services for NFT ID: ${nftCosts.nftID}`);
const runningServices = await getRunningServices(nftCosts.nftID); // Implement `getRunningServices` to fetch services
const stoppedServices = [];
for (const service of runningServices) {
try {
console.log(`Stopping service: ${service.id}`);
const result = await stopService(service.id);
if (result.success) {
stoppedServices.push(service.id);
} else {
console.error(`Failed to stop service ${service.id}:`, result.error);
}
} catch (err) {
console.error(`Error stopping service ${service.id}:`, err);
}
}
console.log(`Stopped services: ${stoppedServices}`);
return { success: true, data: true };
};applyCosts
Calculates and applies the usage costs based on request parameters, which helps manage the user’s balance effectively.
runNaturalFunction
Processes natural language requests, interprets parameters with OpenAI, and executes operations based on the extracted information.
Last updated