Prompt Context
Understanding how LLMs remember your chat conversation and how it provides prompt context
Last updated
const express = require("express");
const fs = require("fs");
const readline = require("readline");
const app = express();
const port = 3000;
app.get("/process-data", async (req, res) => {
const fileStream = fs.createReadStream("large_data_file.txt");
const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity });
let dataChunk = "";
for await (const line of rl) {
dataChunk += line;
if (dataChunk.length >= 2048) {
// Process dataChunk with generative AI model
console.log("Processing data chunk:", dataChunk);
// Reset dataChunk for the next iteration
dataChunk = "";
}
}
if (dataChunk.length > 0) {
// Process remaining dataChunk with generative AI model
console.log("Processing remaining data chunk:", dataChunk);
}
res.send("Data processing completed.");
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});const express = require("express");
const axios = require("axios");
const app = express();
const port = 3000;
app.get("/process-api-data", async (req, res) => {
const apiUrl = "https://api.example.com/data";
let currentPage = 1;
let hasMoreData = true;
while (hasMoreData) {
try {
const response = await axios.get(apiUrl, { params: { page: currentPage, per_page: 50 } });
const data = response.data;
if (data && data.length > 0) {
// Process data with generative AI model
console.log("Processing data:", data);
// Move on to the next page
currentPage++;
} else {
hasMoreData = false;
}
} catch (error) {
console.error("Error fetching data from API:", error);
break;
}
}
res.send("API data processing completed.");
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});