@@ -43,7 +43,7 @@ class AiDemo : public yup::Component
4343 modelLabel.setText (" Model" , yup::dontSendNotification);
4444 addAndMakeVisible (modelLabel);
4545
46- modelEditor.setText (" llama3.2 " , yup::dontSendNotification);
46+ modelEditor.setText (" gemma4 " , yup::dontSendNotification);
4747 modelEditor.setMultiLine (false );
4848 addAndMakeVisible (modelEditor);
4949
@@ -68,6 +68,10 @@ class AiDemo : public yup::Component
6868 };
6969 addAndMakeVisible (askButton);
7070
71+ toolsToggle.setButtonText (" Tools" );
72+ toolsToggle.setToggleState (true , yup::dontSendNotification);
73+ addAndMakeVisible (toolsToggle);
74+
7175 statusLabel.setText (" Ollama can call set_background_color for this page." , yup::dontSendNotification);
7276 addAndMakeVisible (statusLabel);
7377
@@ -116,6 +120,8 @@ class AiDemo : public yup::Component
116120 auto actionRow = area.removeFromTop (34 );
117121 askButton.setBounds (actionRow.removeFromLeft (96 ));
118122 actionRow.removeFromLeft (12 );
123+ toolsToggle.setBounds (actionRow.removeFromLeft (86 ));
124+ actionRow.removeFromLeft (12 );
119125 statusLabel.setBounds (actionRow);
120126
121127 area.removeFromTop (18 );
@@ -138,12 +144,13 @@ class AiDemo : public yup::Component
138144 class OllamaRequestThread final : public yup::Thread
139145 {
140146 public:
141- OllamaRequestThread (AiDemo& ownerToUse, yup::String modelToUse, yup::String baseUrlToUse, yup::String promptToUse)
147+ OllamaRequestThread (AiDemo& ownerToUse, yup::String modelToUse, yup::String baseUrlToUse, yup::String promptToUse, bool useToolsToUse )
142148 : Thread (" OllamaRequest" )
143149 , owner (ownerToUse)
144150 , model (std::move (modelToUse))
145151 , baseUrl (std::move (baseUrlToUse))
146152 , prompt (std::move (promptToUse))
153+ , useTools (useToolsToUse)
147154 , ownerReference (&ownerToUse)
148155 {
149156 }
@@ -159,25 +166,32 @@ class AiDemo : public yup::Component
159166 yup::LLMHttpClient client (std::move (options));
160167
161168 yup::LLMClient::Request request;
162- request.systemPrompt = " You are a concise assistant inside a YUP example app. "
163- " If the user asks to change the page background, call set_background_color with a CSS color name, #RRGGBB value, rgb(...), or hsl(...). "
164- " After a tool result, briefly tell the user what changed." ;
165169 request.messages .push_back (yup::LLMMessage::user (prompt));
166170 request.temperature = 0 .2f ;
167171
168172 yup::LLMToolRegistry toolRegistry;
169- owner.registerTools (toolRegistry, ownerReference);
170- request.tools = toolRegistry.getAllTools ();
171- request.toolChoice = " auto" ;
173+ if (useTools)
174+ {
175+ request.systemPrompt = " You are a concise assistant inside a YUP example app. "
176+ " If the user asks to change the page background, call set_background_color with a CSS color name, #RRGGBB value, rgb(...), or hsl(...). "
177+ " After a tool result, briefly tell the user what changed." ;
178+
179+ owner.registerTools (toolRegistry, ownerReference);
180+ request.tools = toolRegistry.getAllTools ();
181+ request.toolChoice = " auto" ;
182+ }
172183
173184 auto response = client.runToolLoop (request, toolRegistry);
174185
175186 yup::String responseText;
176- if (! response.choices .empty ())
187+ if (response.failed () && response.errorMessage .has_value ())
188+ responseText = " Ollama error: " + *response.errorMessage ;
189+ else if (! response.choices .empty ())
177190 responseText = response.choices .front ().message .content .trim ();
178191
179192 if (responseText.isEmpty ())
180- responseText = " No response was returned. Check that Ollama is running, the model is pulled, and the base URL is reachable." ;
193+ responseText = useTools ? " No response was returned. Check that Ollama is running, the model is pulled, the base URL is reachable, and the model supports tool calls."
194+ : " No response was returned. Check that Ollama is running, the model is pulled, and the base URL is reachable." ;
181195
182196 if (threadShouldExit ())
183197 return ;
@@ -199,6 +213,7 @@ class AiDemo : public yup::Component
199213 yup::String model;
200214 yup::String baseUrl;
201215 yup::String prompt;
216+ bool useTools;
202217 yup::WeakReference<yup::Component> ownerReference;
203218 };
204219
@@ -215,6 +230,7 @@ class AiDemo : public yup::Component
215230 const auto model = modelEditor.getText ().trim ();
216231 const auto baseUrl = baseUrlEditor.getText ().trim ();
217232 const auto prompt = promptEditor.getText ().trim ();
233+ const auto useTools = toolsToggle.getToggleState ();
218234
219235 if (model.isEmpty () || baseUrl.isEmpty () || prompt.isEmpty ())
220236 {
@@ -226,7 +242,7 @@ class AiDemo : public yup::Component
226242 statusLabel.setText (" Waiting for Ollama..." , yup::dontSendNotification);
227243 responseEditor.setText (" " , yup::dontSendNotification);
228244
229- requestThread = std::make_unique<OllamaRequestThread> (*this , model, baseUrl, prompt);
245+ requestThread = std::make_unique<OllamaRequestThread> (*this , model, baseUrl, prompt, useTools );
230246 if (! requestThread->startThread (yup::Thread::Priority::background))
231247 {
232248 requestThread.reset ();
@@ -306,6 +322,7 @@ class AiDemo : public yup::Component
306322 yup::TextEditor promptEditor { " promptEditor" };
307323 yup::TextEditor responseEditor { " responseEditor" };
308324 yup::TextButton askButton { " askButton" };
325+ yup::ToggleButton toolsToggle { " toolsToggle" };
309326
310327 yup::Font titleFont;
311328 std::optional<yup::Color> backgroundColor;
0 commit comments