US Congress Stock Trading API examples & templates
Use these vals as a playground to view and fork US Congress Stock Trading API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.

yawnxyz
processTextInChunks
Script
Text Chunk Processor This JavaScript function processes long text inputs by breaking them into smaller chunks, applying a custom processing function to each chunk, and optionally handling overlaps between chunks. Function Signature processTextInChunks(inputText, processFn, config) Parameters inputText (string): The long input text to be processed. processFn (function, optional): A function to process each chunk. Defaults to logging the chunk. config (object, optional): Configuration options. Config Options chunkLength (number): Length of each chunk. Default: 1000. overlapLength (number): Length of overlap between chunks. Default: 0. Usage const longText = "Your very long text here...";
const result = processTextInChunks(longText,
(mainChunk, overlapChunk, info) => {
// Process the chunk here
console.log(`Processing chunk from ${info.startIndex} to ${info.endIndex}`);
console.log(`Main chunk: ${mainChunk}`);
console.log(`Overlap: ${overlapChunk}`);
return mainChunk.length; // Example return value
},
{
chunkLength: 500,
overlapLength: 50
}
);
console.log(result); Notes If processFn is not provided, the function will log each chunk and return the original text. If processFn returns a value, these values will be collected in an array and returned. If processFn doesn't return anything, the original input text is returned. The processFn receives three arguments: mainChunk : The current chunk of text being processed. overlapChunk : The overlapping text from the previous chunk (empty for the first chunk). An info object containing: startIndex : Start index of the current chunk in the original text. endIndex : End index of the current chunk in the original text. isLastChunk : Boolean indicating if this is the last chunk. Use Cases Processing large texts in smaller, manageable pieces. Applying transformations or analysis to text while maintaining context through overlaps. Tokenization or parsing of large documents.
0
rozek
GDI_AIChatCompletion
HTTP
This val is part of a series of examples to introduce "val.town" in my computer science course at
Stuttgart University of Applied Sciences . The idea is to motivate even first-semester students not to wait but to put their
ideas into practice from the very beginning and implement web apps with
frontend and backend. It contains a simple web page which allows users to enter a "System Message" and
a "User Message" in order to be sent to a preconfigured server. That server then
runs a chat completion and returns the computed "Assistant Message" back to the
client where the result is presented to the user. This val is the companion of https://rozek-gdi_aichatcompletionservice.web.val.run/ which contains the server part (aka "backend") for this example. The code was created using Townie - with only a few small manual corrections. This val is licensed under the MIT License.
0