Skip to content

Commit

Permalink
Merge pull request #440 from ai16z/cleanups
Browse files Browse the repository at this point in the history
fix: fixes some console logs
  • Loading branch information
lalalune authored Nov 20, 2024
2 parents b0a0b84 + 21a4f6a commit 71371e1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export async function loadCharacters(
?.split(",")
.map((path) => path.trim())
.map((path) => {
if (path[0] === '/') return path; // handle absolute paths
// assume relative to the project root where pnpm is ran
return `../${path}`;
if (path[0] === "/") return path; // handle absolute paths
// assume relative to the project root where pnpm is ran
return `../${path}`;
});
const loadedCharacters = [];

Expand Down
6 changes: 3 additions & 3 deletions packages/client-discord/src/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export class VoiceManager extends EventEmitter {
const callback: HandlerCallback = async (
content: Content
) => {
console.log("callback content: ", content);
elizaLogger.debug("callback content: ", content);
const { roomId } = memory;

const responseMemory: Memory = {
Expand Down Expand Up @@ -660,8 +660,8 @@ export class VoiceManager extends EventEmitter {
}

private async _shouldIgnore(message: Memory): Promise<boolean> {
console.log("message: ", message);
console.log("message.content: ", message.content);
// console.log("message: ", message);
elizaLogger.debug("message.content: ", message.content);
// if the message is 3 characters or less, ignore it
if ((message.content as Content).text.length < 3) {
return true;
Expand Down
2 changes: 0 additions & 2 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ export class TwitterInteractionClient extends ClientBase {
twitterShouldRespondTemplate,
});

console.log("composeContext done");

const shouldRespond = await generateShouldRespond({
runtime: this.runtime,
context: shouldRespondContext,
Expand Down
46 changes: 24 additions & 22 deletions packages/plugin-node/src/services/transcription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAgentRuntime, settings } from "@ai16z/eliza";
import { elizaLogger, IAgentRuntime, settings } from "@ai16z/eliza";
import { Service, ServiceType } from "@ai16z/eliza";
import { exec } from "child_process";
import { File } from "formdata-node";
Expand Down Expand Up @@ -116,7 +116,7 @@ export class TranscriptionService extends Service {
const probeResult = JSON.parse(stdout);
const stream = probeResult.streams[0];

console.log("Input audio info:", stream);
elizaLogger.log("Input audio info:", stream);

let ffmpegCommand = `ffmpeg -i "${inputPath}" -ar ${this.TARGET_SAMPLE_RATE} -ac 1`;

Expand All @@ -126,7 +126,7 @@ export class TranscriptionService extends Service {

ffmpegCommand += ` "${outputPath}"`;

console.log("FFmpeg command:", ffmpegCommand);
elizaLogger.log("FFmpeg command:", ffmpegCommand);

await execAsync(ffmpegCommand);

Expand All @@ -135,7 +135,7 @@ export class TranscriptionService extends Service {
fs.unlinkSync(outputPath);
return convertedBuffer;
} catch (error) {
console.error("Error converting audio:", error);
elizaLogger.error("Error converting audio:", error);
throw error;
}
}
Expand All @@ -147,7 +147,7 @@ export class TranscriptionService extends Service {
const filePath = path.join(this.DEBUG_AUDIO_DIR, filename);

fs.writeFileSync(filePath, Buffer.from(audioBuffer));
console.log(`Debug audio saved: ${filePath}`);
elizaLogger.log(`Debug audio saved: ${filePath}`);
}

public async transcribeAttachment(
Expand Down Expand Up @@ -201,7 +201,7 @@ export class TranscriptionService extends Service {
private async transcribeWithOpenAI(
audioBuffer: ArrayBuffer
): Promise<string | null> {
console.log("Transcribing audio with OpenAI...");
elizaLogger.log("Transcribing audio with OpenAI...");

try {
await this.saveDebugAudio(audioBuffer, "openai_input_original");
Expand All @@ -225,19 +225,22 @@ export class TranscriptionService extends Service {
});

const trimmedResult = (result as any).trim();
console.log(`OpenAI speech to text result: "${trimmedResult}"`);
elizaLogger.log(`OpenAI speech to text result: "${trimmedResult}"`);

return trimmedResult;
} catch (error) {
console.error("Error in OpenAI speech-to-text conversion:", error);
elizaLogger.error(
"Error in OpenAI speech-to-text conversion:",
error
);
if (error.response) {
console.error("Response data:", error.response.data);
console.error("Response status:", error.response.status);
console.error("Response headers:", error.response.headers);
elizaLogger.error("Response data:", error.response.data);
elizaLogger.error("Response status:", error.response.status);
elizaLogger.error("Response headers:", error.response.headers);
} else if (error.request) {
console.error("No response received:", error.request);
elizaLogger.error("No response received:", error.request);
} else {
console.error("Error setting up request:", error.message);
elizaLogger.error("Error setting up request:", error.message);
}
return null;
}
Expand All @@ -247,7 +250,7 @@ export class TranscriptionService extends Service {
audioBuffer: ArrayBuffer
): Promise<string | null> {
try {
console.log("Transcribing audio locally...");
elizaLogger.log("Transcribing audio locally...");

await this.saveDebugAudio(audioBuffer, "local_input_original");

Expand All @@ -261,12 +264,12 @@ export class TranscriptionService extends Service {
);
fs.writeFileSync(tempWavFile, convertedBuffer);

console.log(`Temporary WAV file created: ${tempWavFile}`);
elizaLogger.debug(`Temporary WAV file created: ${tempWavFile}`);

let output = await nodewhisper(tempWavFile, {
modelName: "base.en",
autoDownloadModelName: "base.en",
verbose: true,
verbose: false,
removeWavFileAfterTranscription: false,
withCuda: this.isCudaAvailable,
whisperOptions: {
Expand All @@ -281,8 +284,6 @@ export class TranscriptionService extends Service {
},
});

console.log("Raw output from nodejs-whisper:", output);

output = output
.split("\n")
.map((line) => {
Expand All @@ -294,17 +295,18 @@ export class TranscriptionService extends Service {
})
.join("\n");

console.log("Processed output:", output);

fs.unlinkSync(tempWavFile);

if (!output || output.length < 5) {
console.log("Output is null or too short, returning null");
elizaLogger.log("Output is null or too short, returning null");
return null;
}
return output;
} catch (error) {
console.error("Error in local speech-to-text conversion:", error);
elizaLogger.error(
"Error in local speech-to-text conversion:",
error
);
return null;
}
}
Expand Down

0 comments on commit 71371e1

Please sign in to comment.