Skip to content

Commit

Permalink
fix: examples being re-added late into context
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed Aug 7, 2024
1 parent 7fd4f7f commit 3dee6b5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions app/constants/APIState/BaseAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ export abstract class APIBase implements IAPIBase {
const wrap_string = `\n`
const wrap_length = currentInstruct.wrap ? tokenizer(wrap_string) : 0

// we use this to check if the first message is reached
// this is needed to check if examples should be added
let first_message_reached = false

// we require lengths for names if use_names is enabled
for (const message of messages?.reverse() ?? []) {
for (const message of messages.reverse()) {
const swipe_len = Chats.useChat.getState().getTokenCount(index)
const swipe_data = message.swipes[message.swipe_id]

Expand Down Expand Up @@ -163,25 +167,24 @@ export abstract class APIBase implements IAPIBase {
message_shard += wrap_string
}

first_message_reached = index === 0

// ensure no more is_last checks after this
is_last = false

message_acc_length += shard_length
message_acc = message_shard + message_acc
index--
}

if (currentInstruct.examples) {
const examples = currentCard.data?.mes_example
if (examples) {
if (
message_acc_length + payload_length + characterCache.examples_length <
max_length
) {
payload += examples
message_acc_length += characterCache.examples_length
}
}
const examples = currentCard.data?.mes_example
if (
first_message_reached &&
currentInstruct.examples &&
examples &&
message_acc_length + payload_length + characterCache.examples_length < max_length
) {
payload += examples
message_acc_length += characterCache.examples_length
}

payload += currentInstruct.system_suffix
Expand Down

0 comments on commit 3dee6b5

Please sign in to comment.