Skip to content

Fix crash when first message exceeds max token length.#18

Open
tylerstillwater wants to merge 3 commits intoalfianlosari:mainfrom
tylerstillwater:historyList-fix
Open

Fix crash when first message exceeds max token length.#18
tylerstillwater wants to merge 3 commits intoalfianlosari:mainfrom
tylerstillwater:historyList-fix

Conversation

@tylerstillwater
Copy link

@tylerstillwater tylerstillwater commented Apr 10, 2023

During encoding, we check to see if the latest text to be encoded and sent to ChatGPT exceeds our maximum token length of 4096. If it does, we throw an error, as this message can never function correctly.

private func generateMessages(from text: String, systemText: String) -> [Message] {
var messages = [systemMessage(content: systemText)] + historyList + [Message(role: "user", content: text)]
if gptEncoder.encode(text: messages.content).count > 4096 {
if !historyList.isEmpty() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isEmpty is a function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Working on this now. I'm very new to Swift and made this edit in a github codespace. This solution doesn't work anyway. Something more complex is required.

@tylerstillwater
Copy link
Author

I've pushed a commit that correctly fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments