Logo
⚠️ Unsaved
[M]:

Reproducing Input Context Exceeded error

[13]:
!npm install together-ai

import Together from "together-ai";

const client = new Together({ apiKey: "input key here" });

async function getTogetherEmbedding(text: string): Promise<number[]> {
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: text,
});
return response.data[0].embedding;
}

async function getTogetherEmbeddings(texts: string[]): Promise<number[][]> {
try {
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: texts,
});
return response.data.map((item: { embedding: number[] }) => item.embedding);
} catch (error) {
console.error(`Error getting embeddings: ${error}`);
console.error(`First text: ${texts[0].slice(0, 100)}...`);
throw error;
}
}
$ npm install together-ai

up to date in 462ms

30 packages are looking for funding
  run `npm fund` for details
[14]:
const chunks = [
"Eventbrite\n \n\n \n\n\n \n\nYour event is coming up soon!\n Capital Factory Member Salon\n\n \n\n \nThursday at 5:00\u202fPM\n\n\n \n \nOrganized by Capital Factory\n\n------------------------------------------------------------------------\n\n\n \n----\n\n\n \n----\n\n \n\nGet your tickets ready\n\n \n\n<tr>\n <td >\n \n\n\n\n </td>\n <td>\n \nMore Info: https://itunes.apple.com/us/app/eventbrite-local-events-fun-things-to-do-near-me/id487922291?mt=8&utm_source=eventbrite&utm_medium=attendeeapp&utm_campaign=reminder_email\n\n------------------------------------------------------------------------\n\n \n\nMore Info: https://play.google.com/store/apps/details?id=com.eventbrite.attendee&utm_source=eventbrite&utm_medium=attendeeapp&utm_campaign=reminder_email\n\n------------------------------------------------------------------------\n\n </td>\n </tr>\n\n------------------------------------------------------------------------\n\n \n\nGo to My Tickets: https://www.eventbrite.com/mytickets%2F9821317199\n\n------------------------------------------------------------------------\n\n------------------------------------------------------------------------",
"+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | mailgun ( | | | | |\r\n| https://www.mailgun.com/ ) | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+\r\n\r\n+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | | | | | 2FA enabled | | |\r\n| ----------- | | Hey there, Two | | |\r\n| Factor | | Authentication has | | |\r\n| been | | successfully enabled | | |\r\n| for user | | tech@happilabs.org. | |\r\n| | Cheers! | | The Mailgun Team | | |\r\n| | | | | + | | + | | | | | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+",
"+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | mailgun ( | | | | |\r\n| https://www.mailgun.com/ ) | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+\r\n\r\n+---------------------------------------------------------------------------+\r\n| +-----------------------------------------------------------------------+ |\r\n| | +-------------------------------------------------------------------+ |\r\n| | | | | | | | | | One-time Login Passcode ----------------------- |\r\n| | | Hi there, Your | | one-time login passcode is 648263. If | |\r\n| | you did not initiate | | the login, we recommend reviewing | |\r\n| | your account credentials and | | turning on 2FA. *We highly | |\r\n| | recommend* configuring 2FA to avoid | | encountering these | |\r\n| | notifications in the future. You can find more | | information |",
"+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | mailgun ( | | | | |\r\n| https://www.mailgun.com/ ) | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+\r\n\r\n+---------------------------------------------------------------------------+\r\n| +-----------------------------------------------------------------------+ |\r\n| | +-------------------------------------------------------------------+ |\r\n| | | | | | | | | | One-time Login Passcode ----------------------- |\r\n| | | Hi there, Your | | one-time login passcode is 643789. If | |\r\n| | you did not initiate | | the login, we recommend reviewing | |\r\n| | your account credentials and | | turning on 2FA. *We highly | |\r\n| | recommend* configuring 2FA to avoid | | encountering these | |\r\n| | notifications in the future. You can find more | | information |",
"+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | mailgun ( | | | | |\r\n| https://www.mailgun.com/ ) | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+\r\n\r\n+---------------------------------------------------------------------------+\r\n| +-----------------------------------------------------------------------+ |\r\n| | +-------------------------------------------------------------------+ |\r\n| | | | | | | | | | One-time Login Passcode ----------------------- |\r\n| | | Hi there, Your | | one-time login passcode is 619706. If | |\r\n| | you did not initiate | | the login, we recommend reviewing | |\r\n| | your account credentials and | | turning on 2FA. *We highly | |\r\n| | recommend* configuring 2FA to avoid | | encountering these | |\r\n| | notifications in the future. You can find more | | information |",
"+--+---------------------------------------------------------------------------------------+--+\r\n| | +-----------------------------------------------------------------------------------+ | |\r\n| | | +-------------------------------------------------------------------------------+ | |\r\n| | | | | Hi there, Falcon Partners LLC has invited you to join Mailgun. Mailgun | | |\r\n| | | | | is an email service that enables developers to send and track email. | | | | |\r\n| | | +---------------------------------------------------------------------------+ | |\r\n| | | | | | | Join Falcon Partners LLC on Mailgun ( | | | | | | | |\r\n| | https://signup.mailgun.com/activate/user/33a171f78b90e2d2a9466eba36473a6b | |\r\n| | | | | | | | ) | | | | | | |\r\n| | +---------------------------------------------------------------------------+ | |",
"+----------------------------------------+\r\n| +------------------------------------+ |\r\n| | +--------------------------------+ |\r\n| | | | | | mailgun ( | | | | |\r\n| https://www.mailgun.com/ ) | | | | | |\r\n| +--------------------------------+ | |\r\n| +------------------------------------+ |\r\n+----------------------------------------+\r\n\r\n+---------------------------------------------------------------------------+\r\n| +-----------------------------------------------------------------------+ |\r\n| | +-------------------------------------------------------------------+ |\r\n| | | | | | | | | | One-time Login Passcode ----------------------- |\r\n| | | Hi there, Your | | one-time login passcode is 643789. If | |\r\n| | you did not initiate | | the login, we recommend reviewing | |\r\n| | your account credentials and | | turning on 2FA. *We highly | |\r\n| | recommend* configuring 2FA to avoid | | encountering these | |\r\n| | notifications in the future. You can find more | | information |",
"Eventbrite\n \n\n \n\n\n \n\nYour event is coming up soon!\n The G.O.A.T Comedy Show\n\n \n\n \nSaturday at 7:30\u202fPM\n\n\n \n \nOrganized by Breakout Entertainment\n\n------------------------------------------------------------------------\n\n\n \n----\n\n\n \n----\n\n \n\nGet your tickets ready\n\n \n\n<tr>\n <td >\n \n\n\n\n </td>\n <td>\n \nMore Info: https://itunes.apple.com/us/app/eventbrite-local-events-fun-things-to-do-near-me/id487922291?mt=8&utm_source=eventbrite&utm_medium=attendeeapp&utm_campaign=reminder_email\n\n------------------------------------------------------------------------\n\n \n\nMore Info: https://play.google.com/store/apps/details?id=com.eventbrite.attendee&utm_source=eventbrite&utm_medium=attendeeapp&utm_campaign=reminder_email\n\n------------------------------------------------------------------------\n\n </td>\n </tr>\n\n------------------------------------------------------------------------\n\n \n\nGo to My Tickets: https://www.eventbrite.com/mytickets%2F10221824839\n\n------------------------------------------------------------------------\n\n------------------------------------------------------------------------"
]
[15]:
!npm install "@dqbd/tiktoken"

import { get_encoding } from "@dqbd/tiktoken";

const encoder = get_encoding("cl100k_base"); // Use cl100k_base encoding which is commonly used for modern models

for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
const tokens = encoder.encode(chunk);
console.log(`Chunk ${i + 1}:\n`);
console.log(`- Length: ${chunk.length} characters\n`);
console.log(`- Token count: ${tokens.length}\n`);
console.log('---\n');
}

// Free up the memory
encoder.free();
$ npm install "@dqbd/tiktoken"

up to date in 461ms

30 packages are looking for funding
  run `npm fund` for details
Chunk 1:
- Length: 1297 characters
- Token count: 199
---
Chunk 2:
- Length: 924 characters
- Token count: 202
---
Chunk 3:
- Length: 1063 characters
- Token count: 198
---
Chunk 4:
- Length: 1063 characters
- Token count: 198
---
Chunk 5:
- Length: 1063 characters
- Token count: 198
---
Chunk 6:
- Length: 1000 characters
- Token count: 187
---
Chunk 7:
- Length: 1063 characters
- Token count: 198
---
Chunk 8:
- Length: 1300 characters
- Token count: 203
---
[16]:
await getTogetherEmbedding(chunks[0])
Error during execution: 422 {"id":"90aa91bdc82403ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 652 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[17]:
await getTogetherEmbedding(chunks[0])
Error during execution: 422 {"id":"90aa91c51a1503ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 652 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[18]:
await getTogetherEmbedding(chunks[1])
Error during execution: 422 {"id":"90aa91cbbbb003ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 614 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[19]:
await getTogetherEmbedding(chunks[2])
Error during execution: 422 {"id":"90aa91d5396603ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 633 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[20]:
await getTogetherEmbedding(chunks[3])
Error during execution: 422 {"id":"90aa91da589c03ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 633 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[21]:
await getTogetherEmbedding(chunks[4])
Error during execution: 422 {"id":"90aa91e5e8a203ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 633 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[22]:
await getTogetherEmbedding(chunks[5])
Error during execution: 422 {"id":"90aa91ec08f003ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 566 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[23]:
await getTogetherEmbedding(chunks[6])
Error during execution: 422 {"id":"90aa91f37b5b03ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 633 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
[24]:
await getTogetherEmbedding(chunks[7])
Error during execution: 422 {"id":"90aa91f9bb7e03ee","error":{"message":"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 532. Given: 657 `inputs` tokens and 20 `max_new_tokens`","type":"invalid_request_error","param":null,"code":null}}
Sign in to save your work and access it from anywhere