Skip to content

Commit c1f6b0c

Browse files
committed
Merge branch 'extractBetween' into 'main'
replace regexp with extractBetween See merge request dferreir/llms-with-matlab!5
2 parents c5c9aeb + 33ae866 commit c1f6b0c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

examples/ExampleFunctionCalling.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,26 @@
3939
% Extract individual paper entries from the API response and use ChatGPT
4040
% to determine whether each paper is related to the specified topic.
4141

42-
pattern = '<entry>(.*?)</entry>';
43-
4442
% ChatGPT will parse the XML file, so we only need to extract the relevant
4543
% entries.
46-
matches = regexp(code, pattern, 'tokens');
44+
entries = extractBetween(code, '<entry>', '</entry>');
4745

4846
% Determine the topic of interest
4947
topic = "Embedding documents or sentences";
5048

5149
% Loop over the entries and see if they are relevant to the topic of
5250
% interest.
53-
for i = 1:length(matches)
51+
for i = 1:length(entries)
5452
prompt = "Given the following paper:" + newline +...
55-
string(matches{i})+ newline +...
53+
string(entries{i})+ newline +...
5654
"Is it related to the topic: "+ topic +"?" + ...
5755
" Answer 'yes' or 'no'.";
5856
[text, response] = generate(chat, prompt);
5957

6058
% If the model classifies this entry as relevant, then it tries to
6159
% request a function call.
6260
if contains("yes", text, IgnoreCase=true)
63-
prompt = "Given the following paper:" + newline + string(matches{i})+ newline +...
61+
prompt = "Given the following paper:" + newline + string(entries{i})+ newline +...
6462
"Given the topic: "+ topic + newline + "Write the details to a table.";
6563
[text, response] = generate(chat, prompt);
6664

0 commit comments

Comments
 (0)