|
|
@@ -42,12 +42,11 @@ const receiveData = ( |
|
|
|
}); |
|
|
|
memory.push(assistantMessage as OpenAi.MessageObject); |
|
|
|
process.stdout.write('\n\n'); |
|
|
|
// const { length: promptTokens } = OpenAi.getPromptTokens( |
|
|
|
// normalizedChatMessage, |
|
|
|
// model, |
|
|
|
// ); |
|
|
|
// process.stdout.write(`info:\n${promptTokens} prompt tokens\n${completionTokens} completion tokens`); |
|
|
|
process.stdout.write(`info:\n${completionTokens} completion tokens`); |
|
|
|
const { length: promptTokens } = OpenAi.getPromptTokens( |
|
|
|
normalizedChatMessage, |
|
|
|
model, |
|
|
|
); |
|
|
|
process.stdout.write(`info:\n${promptTokens} prompt tokens\n${completionTokens} completion tokens`); |
|
|
|
if (argv.memory) { |
|
|
|
process.stdout.write(`\n${memory.length} memory items`); |
|
|
|
} |
|
|
@@ -87,7 +86,7 @@ const receiveData = ( |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
const main = (argv: Argv) => new Promise<number>(async (resolve) => { |
|
|
|
const main = async (argv: Argv) => { |
|
|
|
let done = false; |
|
|
|
let resolveResult = 0; |
|
|
|
const memory = [] as OpenAi.MessageObject[]; |
|
|
@@ -111,6 +110,7 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => { |
|
|
|
return `${OpenAi.MessageRole.USER}:\n${this.valueWithCursor ?? ''}`; |
|
|
|
}, |
|
|
|
}); |
|
|
|
// eslint-disable-next-line no-await-in-loop |
|
|
|
const contentRaw = await textPrompt.prompt(); |
|
|
|
if (isCancel(contentRaw)) { |
|
|
|
done = true; |
|
|
@@ -121,6 +121,7 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => { |
|
|
|
break; |
|
|
|
} |
|
|
|
process.stdout.write('\n'); |
|
|
|
// eslint-disable-next-line no-await-in-loop |
|
|
|
await receiveData(aiClient, content, argv, memory); |
|
|
|
} catch { |
|
|
|
resolveResult = -1; |
|
|
@@ -129,8 +130,8 @@ const main = (argv: Argv) => new Promise<number>(async (resolve) => { |
|
|
|
} while (!done); |
|
|
|
|
|
|
|
process.stdout.write('\ninfo:\nUser exited loop\n\n'); |
|
|
|
resolve(resolveResult); |
|
|
|
}); |
|
|
|
return resolveResult; |
|
|
|
}; |
|
|
|
|
|
|
|
main( |
|
|
|
yargs(hideBin(process.argv)) |
|
|
@@ -160,7 +161,9 @@ main( |
|
|
|
.then((result) => { |
|
|
|
process.exit(result); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
console.error(error); |
|
|
|
.catch((errRaw) => { |
|
|
|
const error = errRaw as Error; |
|
|
|
process.stderr.write(error.message); |
|
|
|
process.stderr.write('\n'); |
|
|
|
process.exit(-1); |
|
|
|
}); |