Skip to content

Commit

Permalink
fix stop words
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacartney committed Aug 14, 2023
1 parent e22f4d8 commit ad58d29
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions convex/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function startConversation(
`\n${player.name}:`,
},
];
const stop = newFriendsNames.map((name) => name + ':');
const stop = stopWords(newFriendsNames);
const { content } = await chatCompletion({ messages: prompt, max_tokens: 300, stop });
return { content, memoryIds: memories.map((m) => m.memory._id) };
}
Expand All @@ -51,6 +51,10 @@ function messageContent(m: Message): string {
}
}

function stopWords(names: string[]): string[] {
return names.flatMap((name) => [name + ':', name.toLowerCase() + ':']);
}

export function chatHistoryFromMessages(messages: Message[]): LLMMessage[] {
return (
messages
Expand Down Expand Up @@ -110,7 +114,6 @@ export async function converse(
const reflectionMemories = filterMemoriesType(['reflection'], memories);
const lastConversationTs = conversationMemories[0]?.memory._creationTime;

const stop = nearbyPlayers.join(':');
const relevantReflections: string =
reflectionMemories.length > 0
? reflectionMemories
Expand All @@ -126,7 +129,7 @@ export async function converse(
let prefixPrompt = `Your name is ${player.name}. About you: ${player.identity}.\n`;
if (relevantReflections.length > 0) {
prefixPrompt += relevantReflections;
console.log('relevantReflections', relevantReflections);
// console.debug('relevantReflections', relevantReflections);
}

prefixPrompt += `\nYou are talking to ${nearbyPlayersNames}, below are something about them: `;
Expand All @@ -153,6 +156,7 @@ export async function converse(
content: `${player.name}:`,
},
];
const stop = stopWords(nearbyPlayers.map((p) => p.name));
const { content } = await chatCompletion({ messages: prompt, max_tokens: 300, stop });
// console.debug('converse result through chatgpt: ', content);
return { content, memoryIds: memories.map((m) => m.memory._id) };
Expand Down

0 comments on commit ad58d29

Please sign in to comment.