Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
oktoshi committed Dec 11, 2024
2 parents bfa143f + ca885a8 commit f9b4aa0
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COPY characters ./characters

# Install dependencies and build the project
RUN pnpm install \
&& pnpm build \
&& pnpm build-docker \
&& pnpm prune --prod

# Create a new stage for the final image
Expand Down
2 changes: 1 addition & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@okcashpro/plugin-0g": "workspace:*",
"@okcashpro/plugin-aptos": "workspace:*",
"@okcashpro/plugin-bootstrap": "workspace:*",
"@okcashpro/plugin-buttplug": "workspace:*",
"@okcashpro/plugin-intiface": "workspace:*",
"@okcashpro/plugin-coinbase": "workspace:*",
"@okcashpro/plugin-conflux": "workspace:*",
"@okcashpro/plugin-evm": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { zgPlugin } from "@okcashpro/plugin-0g";
import createGoatPlugin from "@okcashpro/plugin-goat";
import { bootstrapPlugin } from "@okcashpro/plugin-bootstrap";
// import { buttplugPlugin } from "@okcashpro/plugin-buttplug";
// import { intifacePlugin } from "@okcashpro/plugin-intiface";
import {
coinbaseCommercePlugin,
coinbaseMassPaymentsPlugin,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"build": "turbo run build --filter=!okai-docs",
"build-docker": "turbo run build",
"start": "pnpm --filter \"@okcashpro/agent\" start --isRoot",
"start:client": "pnpm --dir client start --isRoot",
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=okai:* pnpm --filter \"@okcashpro/agent\" start --isRoot",
Expand Down
64 changes: 43 additions & 21 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,49 @@ export async function generateText({
runtime.character.modelEndpointOverride || models[provider].endpoint;
let model = models[provider].model[modelClass];

// if runtime.getSetting("LLAMACLOUD_MODEL_LARGE") is true and modelProvider is LLAMACLOUD, then use the large model
if (
(runtime.getSetting("LLAMACLOUD_MODEL_LARGE") &&
provider === ModelProviderName.LLAMACLOUD) ||
(runtime.getSetting("TOGETHER_MODEL_LARGE") &&
provider === ModelProviderName.TOGETHER)
) {
model =
runtime.getSetting("LLAMACLOUD_MODEL_LARGE") ||
runtime.getSetting("TOGETHER_MODEL_LARGE");
}

if (
(runtime.getSetting("LLAMACLOUD_MODEL_SMALL") &&
provider === ModelProviderName.LLAMACLOUD) ||
(runtime.getSetting("TOGETHER_MODEL_SMALL") &&
provider === ModelProviderName.TOGETHER)
) {
model =
runtime.getSetting("LLAMACLOUD_MODEL_SMALL") ||
runtime.getSetting("TOGETHER_MODEL_SMALL");
// allow character.json settings => secrets to override models
// FIXME: add MODEL_MEDIUM support
switch(provider) {
// if runtime.getSetting("LLAMACLOUD_MODEL_LARGE") is true and modelProvider is LLAMACLOUD, then use the large model
case ModelProviderName.LLAMACLOUD: {
switch(modelClass) {
case ModelClass.LARGE: {
model = runtime.getSetting("LLAMACLOUD_MODEL_LARGE") || model;
}
break;
case ModelClass.SMALL: {
model = runtime.getSetting("LLAMACLOUD_MODEL_SMALL") || model;
}
break;
}
}
break;
case ModelProviderName.TOGETHER: {
switch(modelClass) {
case ModelClass.LARGE: {
model = runtime.getSetting("TOGETHER_MODEL_LARGE") || model;
}
break;
case ModelClass.SMALL: {
model = runtime.getSetting("TOGETHER_MODEL_SMALL") || model;
}
break;
}
}
break;
case ModelProviderName.OPENROUTER: {
switch(modelClass) {
case ModelClass.LARGE: {
model = runtime.getSetting("LARGE_OPENROUTER_MODEL") || model;
}
break;
case ModelClass.SMALL: {
model = runtime.getSetting("SMALL_OPENROUTER_MODEL") || model;
}
break;
}
}
break;
}

okaiLogger.info("Selected model:", model);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export type Character = {
/** Optional configuration */
settings?: {
secrets?: { [key: string]: string };
buttplug?: boolean;
intiface?: boolean;
voice?: {
model?: string; // For VITS
url?: string; // Legacy VITS support
Expand Down Expand Up @@ -1155,7 +1155,7 @@ export enum ServiceType {
BROWSER = "browser",
SPEECH_GENERATION = "speech_generation",
PDF = "pdf",
BUTTPLUG = "buttplug",
INTIFACE = "intiface",
AWS_S3 = "aws_s3",
}

Expand Down
20 changes: 0 additions & 20 deletions packages/plugin-buttplug/CHANGELOG.md

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@okcashpro/plugin-buttplug",
"version": "0.1.5-alpha.6",
"name": "@okcashpro/plugin-intiface",
"version": "0.1.5-alpha.5",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IAgentRuntime } from "@okcashpro/okai";
import { z } from "zod";

export const buttplugEnvSchema = z
export const intifaceEnvSchema = z
.object({
INTIFACE_URL: z.string().default("ws://localhost:12345"),
INTIFACE_NAME: z.string().default("OKai Buttplug Client"),
INTIFACE_NAME: z.string().default("OKai Intiface Client"),
DEVICE_NAME: z.string().default("Lovense Nora"),
})
.refine(
Expand All @@ -20,11 +20,11 @@ export const buttplugEnvSchema = z
}
);

export type ButtplugConfig = z.infer<typeof buttplugEnvSchema>;
export type IntifaceConfig = z.infer<typeof intifaceEnvSchema>;

export async function validateButtplugConfig(
export async function validateIntifaceConfig(
runtime: IAgentRuntime
): Promise<ButtplugConfig> {
): Promise<IntifaceConfig> {
try {
const config = {
INTIFACE_URL:
Expand All @@ -36,14 +36,14 @@ export async function validateButtplugConfig(
runtime.getSetting("DEVICE_NAME") || process.env.DEVICE_NAME,
};

return buttplugEnvSchema.parse(config);
return intifaceEnvSchema.parse(config);
} catch (error) {
if (error instanceof z.ZodError) {
const errorMessages = error.errors
.map((err) => `${err.path.join(".")}: ${err.message}`)
.join("\n");
throw new Error(
`Buttplug configuration validation failed:\n${errorMessages}`
`Intiface configuration validation failed:\n${errorMessages}`
);
}
throw error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ButtplugClient, ButtplugNodeWebsocketClientConnector } from "buttplug";
import { validateButtplugConfig, type ButtplugConfig } from "./environment";
import { validateIntifaceConfig, type IntifaceConfig } from "./environment";
import type {
Action,
HandlerCallback,
Expand All @@ -15,22 +15,22 @@ import {
shutdownIntifaceEngine,
} from "./utils";

export interface IButtplugService extends Service {
export interface IIntifaceService extends Service {
vibrate(strength: number, duration: number): Promise<void>;
rotate?(strength: number, duration: number): Promise<void>;
getBatteryLevel?(): Promise<number>;
isConnected(): boolean;
getDevices(): any[];
}

export class ButtplugService extends Service implements IButtplugService {
static serviceType: ServiceType = ServiceType.BUTTPLUG;
export class IntifaceService extends Service implements IIntifaceService {
static serviceType: ServiceType = ServiceType.INTIFACE;
private client: ButtplugClient;
private connected = false;
private devices: Map<string, any> = new Map();
private vibrateQueue: VibrateEvent[] = [];
private isProcessingQueue = false;
private config: ButtplugConfig | null = null;
private config: IntifaceConfig | null = null;
private maxVibrationIntensity = 1;
private rampUpAndDown = false;
private rampSteps = 20;
Expand Down Expand Up @@ -62,16 +62,16 @@ export class ButtplugService extends Service implements IButtplugService {
}
await shutdownIntifaceEngine();
} catch (error) {
console.error("[ButtplugService] Cleanup error:", error);
console.error("[IntifaceService] Cleanup error:", error);
}
}

getInstance(): IButtplugService {
getInstance(): IIntifaceService {
return this;
}

async initialize(runtime: IAgentRuntime): Promise<void> {
this.config = await validateButtplugConfig(runtime);
this.config = await validateIntifaceConfig(runtime);
this.preferredDeviceName = this.config.DEVICE_NAME;
this.client = new ButtplugClient(this.config.INTIFACE_NAME);

Expand Down Expand Up @@ -118,7 +118,7 @@ export class ButtplugService extends Service implements IButtplugService {
await new Promise((r) => setTimeout(r, 2000));
} else {
console.error(
"Failed to connect to Buttplug server after all retries:",
"Failed to connect to Intiface server after all retries:",
error
);
throw error;
Expand All @@ -144,7 +144,7 @@ export class ButtplugService extends Service implements IButtplugService {

private async ensureDeviceAvailable() {
if (!this.connected) {
throw new Error("Not connected to Buttplug server");
throw new Error("Not connected to Intiface server");
}

if (this.devices.size === 0) {
Expand Down Expand Up @@ -325,7 +325,7 @@ const vibrateAction: Action = {
description: "Control vibration intensity of connected devices",
validate: async (runtime: IAgentRuntime, _message: Memory) => {
try {
await validateButtplugConfig(runtime);
await validateIntifaceConfig(runtime);
return true;
} catch {
return false;
Expand All @@ -338,11 +338,11 @@ const vibrateAction: Action = {
options: any,
callback: HandlerCallback
) => {
const service = runtime.getService<IButtplugService>(
ServiceType.BUTTPLUG
const service = runtime.getService<IIntifaceService>(
ServiceType.INTIFACE
);
if (!service) {
throw new Error("Buttplug service not available");
throw new Error("Intiface service not available");
}

// Extract intensity and duration from message
Expand Down Expand Up @@ -435,7 +435,7 @@ const rotateAction: Action = {
description: "Control rotation intensity of connected devices",
validate: async (runtime: IAgentRuntime, _message: Memory) => {
try {
await validateButtplugConfig(runtime);
await validateIntifaceConfig(runtime);
return true;
} catch {
return false;
Expand All @@ -448,8 +448,8 @@ const rotateAction: Action = {
options: any,
callback: HandlerCallback
) => {
const service = runtime.getService<IButtplugService>(
ServiceType.BUTTPLUG
const service = runtime.getService<IIntifaceService>(
ServiceType.INTIFACE
);
if (!service || !service.rotate) {
throw new Error("Rotation not supported");
Expand Down Expand Up @@ -493,7 +493,7 @@ const batteryAction: Action = {
description: "Check battery level of connected devices",
validate: async (runtime: IAgentRuntime, _message: Memory) => {
try {
await validateButtplugConfig(runtime);
await validateIntifaceConfig(runtime);
return true;
} catch {
return false;
Expand All @@ -506,8 +506,8 @@ const batteryAction: Action = {
options: any,
callback: HandlerCallback
) => {
const service = runtime.getService<IButtplugService>(
ServiceType.BUTTPLUG
const service = runtime.getService<IIntifaceService>(
ServiceType.INTIFACE
);
if (!service || !service.getBatteryLevel) {
throw new Error("Battery level check not supported");
Expand Down Expand Up @@ -573,13 +573,13 @@ interface VibrateEvent {
deviceId?: number;
}

export const buttplugPlugin: Plugin = {
name: "buttplug",
export const intifacePlugin: Plugin = {
name: "intiface",
description: "Controls intimate hardware devices",
actions: [vibrateAction, rotateAction, batteryAction],
evaluators: [],
providers: [],
services: [new ButtplugService()],
services: [new IntifaceService()],
};

export default buttplugPlugin;
export default intifacePlugin;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function isPortAvailable(port: number): Promise<boolean> {
export async function startIntifaceEngine(): Promise<void> {
const configPath = path.join(
__dirname,
"../src/buttplug-user-device-config.json"
"../src/intiface-user-device-config.json"
);
try {
const child = spawn(
Expand All @@ -34,7 +34,7 @@ export async function startIntifaceEngine(): Promise<void> {
"12345",
"--use-bluetooth-le",
"--server-name",
"OKai Buttplugin Server",
"OKai Intiface Server",
"--use-device-websocket-server",
"--user-device-config-file",
configPath,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f9b4aa0

Please sign in to comment.