-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for limitConversationContext
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-disable */ | ||
import { limitConversationContext } from './helpers' | ||
import { describe, expect, test, it } from "@jest/globals"; | ||
import { CreateChatCompletionRequestMessage } from "openai/resources/chat"; | ||
|
||
describe('limitConversationContext', () => { | ||
it('waits for the promise to resolve', () => { | ||
|
||
let conversation: CreateChatCompletionRequestMessage[] = [ | ||
{ role: "assistant", content: "Welcome to the platform!" }, | ||
{ role: "user", content: "Your order has been confirmed." }, | ||
{ role: "assistant", content: "Please adhere to the community guidelines." }, | ||
]; | ||
|
||
let limitedConversation = limitConversationContext(conversation, 42) | ||
|
||
expect(limitedConversation.length).toEqual(1) | ||
}) | ||
|
||
it('shouldAttachPartOfAMessage', () => { | ||
let conversation: CreateChatCompletionRequestMessage[] = [ | ||
{ role: "assistant", content: "Welcome to the platform!"}, | ||
{ role: "user", content: "Your order has been confirmed."}, | ||
{ role: "assistant", content: "Please adhere to the community guidelines."}, | ||
]; | ||
|
||
let limitedConversation = limitConversationContext(conversation, 52) | ||
|
||
expect(limitedConversation.length).toEqual(2) | ||
expect(limitedConversation[0].content).toEqual("confirmed.") | ||
expect(limitedConversation[1].content).toEqual("Please adhere to the community guidelines.") | ||
}) | ||
|
||
it('shouldReturnAllMessages', () => { | ||
let conversation: CreateChatCompletionRequestMessage[] = [ | ||
{ role: "assistant", content: "Welcome to the platform!"}, | ||
{ role: "user", content: "Your order has been confirmed."}, | ||
{ role: "assistant", content: "Please adhere to the community guidelines."}, | ||
]; | ||
|
||
let limitedConversation = limitConversationContext(conversation, 100) | ||
|
||
expect(limitedConversation.length).toEqual(3) | ||
expect(limitedConversation[0].content).toEqual("Welcome to the platform!") | ||
expect(limitedConversation[1].content).toEqual("Your order has been confirmed.") | ||
expect(limitedConversation[2].content).toEqual("Please adhere to the community guidelines.") | ||
}) | ||
|
||
it('shouldFilterEmpty', () => { | ||
let emptyConversation: CreateChatCompletionRequestMessage[] = []; | ||
|
||
let limitedEmpty = limitConversationContext(emptyConversation, 100) | ||
|
||
expect(limitedEmpty.length).toEqual(0) | ||
}) | ||
|
||
it('shouldFilterEmptyMessages', () => { | ||
let conversation: CreateChatCompletionRequestMessage[] = [ | ||
{ role: "assistant", content: ""}, | ||
{ role: "assistant", content: "Please adhere to the community guidelines."}, | ||
{ role: "assistant", content: ""}, | ||
{ role: "assistant", content: null}, | ||
]; | ||
|
||
let cleanConversation = limitConversationContext(conversation, 100) | ||
|
||
expect(cleanConversation.length).toEqual(1) | ||
expect(cleanConversation[0].content).toEqual("Please adhere to the community guidelines.") | ||
}) | ||
|
||
it('shouldPreserveOrderOfMessages', () => { | ||
let conversation: CreateChatCompletionRequestMessage[] = [ | ||
{ role: "assistant", content: "one"}, | ||
{ role: "assistant", content: "two"}, | ||
{ role: "assistant", content: "three"}, | ||
]; | ||
|
||
let limitedc = limitConversationContext(conversation, 100) | ||
|
||
expect(limitedc[0].content).toEqual("one") | ||
expect(limitedc[1].content).toEqual("two") | ||
expect(limitedc[2].content).toEqual("three") | ||
}) | ||
}) |