Skip to content

Commit 74da91d

Browse files
committed
Merge branch 'summary-limit' into 'main'
Summary limit See merge request dferreir/llms-with-matlab!6
2 parents c1f6b0c + 5ce7eda commit 74da91d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

examples/ExampleSummarization.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@
3939

4040
% Looping process to gradually summarize the text chunk by chunk, reducing
4141
% the chunk size with each iteration.
42+
numCalls = 0;
4243
while numel(chunks)>1
4344
summarizedChunks = strings(size(chunks));
45+
numCalls = numCalls + numel(chunks);
46+
% Add a limit to the number of calls, to ensure you are not making
47+
% more calls than what is expected. You can change this value to match
48+
% what is needed for your application.
49+
if numCalls > 20
50+
error("Document is too long to be summarized.")
51+
end
4452

4553
for i = 1:length(chunks)
46-
summarizedChunks(i) = generate(summarizer, "Summarize this content:" + newline + chunks(i));
54+
summarizedChunks(i) = generate(summarizer, "Summarize this content:" + newline + chunks(i));
4755
end
4856

4957
% Merging the summarized chunks to serve as the base for the next iteration

0 commit comments

Comments
 (0)