Merge branch 'fix/5'
This commit is contained in:
commit
1205eea7af
2 changed files with 15 additions and 7 deletions
|
@ -267,6 +267,7 @@ async function executeFromQueue(channel: string) {
|
|||
|
||||
messages.forEach(m => { Moderation.checkMessageNoReturn(m); });
|
||||
|
||||
const questionMessageId: string = message instanceof DiscordApi.Message ? message.id : '';
|
||||
if (message instanceof DiscordApi.Message) {
|
||||
channelQueue.startTyping();
|
||||
}
|
||||
|
@ -274,7 +275,13 @@ async function executeFromQueue(channel: string) {
|
|||
await message.deferReply();
|
||||
}
|
||||
|
||||
OpenAImessages = toOpenAIMessages(messages);
|
||||
messages.sort((a, b) => {
|
||||
if (a.id === questionMessageId) return -1;
|
||||
if (b.id === questionMessageId) return 1;
|
||||
return b.createdTimestamp - a.createdTimestamp;
|
||||
});
|
||||
|
||||
OpenAImessages = toOpenAIMessages(messages.values());
|
||||
let generatedMessage: ChatCompletionResponseMessage | undefined = undefined;
|
||||
let answer: Awaited<ReturnType<typeof openai.createChatCompletion>>;
|
||||
|
||||
|
|
|
@ -92,17 +92,18 @@ function getAuthorUsername(message: DiscordMessage): string | undefined {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts the Collection of Discord Messages to array of OpenAI Messages to send
|
||||
* @param messages the collection to convert
|
||||
* Converts the Iterable of Discord Messages to array of OpenAI Messages to send
|
||||
* first message in the interable will be the last of the returned array (reverse order)
|
||||
* @param messages the iterable to convert
|
||||
* @returns the converted messages
|
||||
*/
|
||||
export default function toOpenAIMessages(messages: Collection<string, DiscordMessage>): OpenAIMessage[] {
|
||||
export default function toOpenAIMessages(
|
||||
messages: Iterable<DiscordMessage>,
|
||||
): OpenAIMessage[] {
|
||||
const rvalue: OpenAIMessage[] = [];
|
||||
let tokenCount = 0;
|
||||
|
||||
messages.sort((a, b) => b.createdTimestamp - a.createdTimestamp);
|
||||
|
||||
for (const message of messages.values()) {
|
||||
for (const message of messages) {
|
||||
const content = formatMessage(message);
|
||||
// FIXME: tokens are not being counted properly (it's lower than it is) but it's enough for me for now.
|
||||
tokenCount += countTokens(content);
|
||||
|
|
Loading…
Reference in a new issue