{"id":3514,"date":"2024-10-02T11:24:12","date_gmt":"2024-10-02T05:54:12","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=3514"},"modified":"2024-10-02T11:24:12","modified_gmt":"2024-10-02T05:54:12","slug":"using-openai-from-mathematica-part-2","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/","title":{"rendered":"Using OpenAI from Mathematica: Part-2"},"content":{"rendered":"<p>I had written an <a href=\"https:\/\/www.rangakrish.com\/index.php\/2024\/05\/20\/using-openai-from-mathematica\/\" target=\"_blank\" rel=\"noopener\"><em><strong>earlier article<\/strong><\/em><\/a>\u00a0showing how to use <em><strong>OpenAI<\/strong><\/em> models from <em><strong>Mathematica<\/strong><\/em> ver 14.0.<span class=\"Apple-converted-space\">\u00a0 <\/span><em><strong>Wolfram Mathematica<\/strong><\/em> ver 14.1 was released recently, with several improvements in the area of LLMs. Of course, there are many other core additions as well, but our focus is on LLMs in this article.<\/p>\n<p>This version supports many vendors other than <em><strong>OpenAI<\/strong><\/em>. For example, <em><strong>Anthropic<\/strong><\/em>, <em><strong>Cohere<\/strong><\/em>, and <em><strong>MistralAI<\/strong><\/em> are also supported.<span class=\"Apple-converted-space\">\u00a0 <\/span>We can even use many other open-source models via <em><strong>Groq<\/strong><\/em> and <em><strong>TogetherAI<\/strong><\/em>. That is great news!<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>I will be using my <em><strong>OpenAI<\/strong><\/em> account with all the examples discussed in today\u2019s article.<\/p>\n<p>Let us start with the <em><strong>LLMSynthesize[]<\/strong><\/em> function that we looked at in the previous article. It is the easiest to get started with.<\/p>\n<figure id=\"attachment_3515\" aria-describedby=\"caption-attachment-3515\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"3515\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image1-10\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png\" data-orig-size=\"1574,374\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"LLMSynthesize Function\" data-image-description=\"&lt;p&gt;LLMSynthesize Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;LLMSynthesize Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1-1024x243.png\" class=\"wp-image-3515\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?resize=550%2C131&#038;ssl=1\" alt=\"LLMSynthesize Function\" width=\"550\" height=\"131\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?resize=300%2C71&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?resize=1024%2C243&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?resize=768%2C182&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?resize=1536%2C365&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1.png?w=1574&amp;ssl=1 1574w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3515\" class=\"wp-caption-text\"><strong>LLMSynthesize Function<\/strong><\/figcaption><\/figure>\n<p>Let us suppose we wanted to generalize this and turn it into a function. Although we can implement a <em><strong>Mathematica<\/strong><\/em> function over <em><strong>LLMSynthesize[]<\/strong><\/em> to take arguments and return values, it is more convenient to use <em><strong>LLMFunction[]<\/strong><\/em> for this.<\/p>\n<figure id=\"attachment_3516\" aria-describedby=\"caption-attachment-3516\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3516\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image2-11\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png\" data-orig-size=\"1560,526\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"LLMFunction\" data-image-description=\"&lt;p&gt;LLMFunction&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;LLMFunction&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2-1024x345.png\" class=\"wp-image-3516\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?resize=550%2C185&#038;ssl=1\" alt=\"LLMFunction\" width=\"550\" height=\"185\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?resize=300%2C101&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?resize=1024%2C345&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?resize=768%2C259&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?resize=1536%2C518&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image2.png?w=1560&amp;ssl=1 1560w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3516\" class=\"wp-caption-text\"><strong>LLMFunction<\/strong><\/figcaption><\/figure>\n<p>What about those cases where the LLM has to use an <em><strong>external \u201cfunction\u201d<\/strong><\/em> or <em><strong>source<\/strong><\/em> to produce the correct answer? One common use case is retrieving information about some fact that the LLM\u2019s knowledge base (at the time of training) might not have. To keep things simple, I will try to calculate the <em><strong>\u201cFactorial\u201d<\/strong> <\/em>of a number by using <em><strong>Mathematica\u2019s<\/strong><\/em> function instead of relying on the LLM to give me the correct answer.<\/p>\n<p>For this we use the <em><strong>LLMTool[]<\/strong><\/em> function.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_3517\" aria-describedby=\"caption-attachment-3517\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3517\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image3-12\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png\" data-orig-size=\"1554,258\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"LLMTool Function\" data-image-description=\"&lt;p&gt;LLMTool Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;LLMTool Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3-1024x170.png\" class=\"wp-image-3517\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?resize=550%2C91&#038;ssl=1\" alt=\"LLMTool Function\" width=\"550\" height=\"91\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?resize=300%2C50&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?resize=1024%2C170&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?resize=768%2C128&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?resize=1536%2C255&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image3.png?w=1554&amp;ssl=1 1554w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3517\" class=\"wp-caption-text\"><strong>LLMTool Function<\/strong><\/figcaption><\/figure>\n<p>Here we pass the name, a brief description, the argument, and the actual function that does the job.<\/p>\n<p>Here is how we use it in <em><strong>LLMSynthesize[]<\/strong><\/em>:<\/p>\n<figure id=\"attachment_3518\" aria-describedby=\"caption-attachment-3518\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3518\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image4-13\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png\" data-orig-size=\"1562,212\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Using the Tool Function\" data-image-description=\"&lt;p&gt;Using the Tool Function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using the Tool Function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4-1024x139.png\" class=\"wp-image-3518\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?resize=550%2C75&#038;ssl=1\" alt=\"Using the Tool Function\" width=\"550\" height=\"75\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?resize=300%2C41&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?resize=1024%2C139&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?resize=768%2C104&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?resize=1536%2C208&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image4.png?w=1562&amp;ssl=1 1562w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3518\" class=\"wp-caption-text\"><strong>Using the Tool Function<\/strong><\/figcaption><\/figure>\n<p>We can wrap this inside a function that takes an integer and passes it to the <em><strong>LLMSynthesize[]<\/strong><\/em> function.<\/p>\n<figure id=\"attachment_3519\" aria-describedby=\"caption-attachment-3519\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3519\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image5-11\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png\" data-orig-size=\"1568,554\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Parameterizing the Tool Call\" data-image-description=\"&lt;p&gt;Parameterizing the Tool Call&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Parameterizing the Tool Call&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5-1024x362.png\" class=\"wp-image-3519\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?resize=550%2C194&#038;ssl=1\" alt=\"Parameterizing the Tool Call\" width=\"550\" height=\"194\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?resize=300%2C106&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?resize=1024%2C362&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?resize=768%2C271&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?resize=1536%2C543&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image5.png?w=1568&amp;ssl=1 1568w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3519\" class=\"wp-caption-text\"><strong>Parameterizing the Tool Call<\/strong><\/figcaption><\/figure>\n<p>Another cool addition is <em><strong>LLMExampleFunction[]<\/strong><\/em>. This function is capable of generating text with a prompt dynamically generated from a list of examples. Let us check it out.<\/p>\n<figure id=\"attachment_3520\" aria-describedby=\"caption-attachment-3520\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3520\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image6-10\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png\" data-orig-size=\"1576,980\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Learning from Examples\" data-image-description=\"&lt;p&gt;Learning from Examples&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Learning from Examples&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6-1024x637.png\" class=\"wp-image-3520\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?resize=550%2C342&#038;ssl=1\" alt=\"Learning from Examples\" width=\"550\" height=\"342\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?resize=1024%2C637&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?resize=768%2C478&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?resize=1536%2C955&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image6.png?w=1576&amp;ssl=1 1576w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3520\" class=\"wp-caption-text\"><strong>Learning from Examples<\/strong><\/figcaption><\/figure>\n<p>Pretty neat, isn\u2019t it?<\/p>\n<p>There is also the <em><strong>ChatObject[]<\/strong><\/em> that models an ongoing chat with the LLM. It stores the complete conversation along with metadata. Here is how we can use it.<\/p>\n<figure id=\"attachment_3521\" aria-describedby=\"caption-attachment-3521\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3521\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/image7-8\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png\" data-orig-size=\"1564,1184\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Chat Mode\" data-image-description=\"&lt;p&gt;Chat Mode&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Chat Mode&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7-1024x775.png\" class=\"wp-image-3521\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?resize=550%2C416&#038;ssl=1\" alt=\"Chat Mode\" width=\"550\" height=\"416\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?resize=300%2C227&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?resize=1024%2C775&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?resize=768%2C581&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?resize=1536%2C1163&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image7.png?w=1564&amp;ssl=1 1564w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-3521\" class=\"wp-caption-text\"><strong>Chat Mode<\/strong><\/figcaption><\/figure>\n<p>The new version even has support for <em><strong>Semantic Search<\/strong><\/em> and <em><strong>RAG<\/strong><\/em>. More on this in another article.<\/p>\n<p>Have a Great Day!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had written an earlier article\u00a0showing how to use OpenAI models from Mathematica ver 14.0.\u00a0 Wolfram Mathematica ver 14.1 was released recently, with several improvements in the area of LLMs. Of course, there are many other core additions as well, but our focus is on LLMs in this article. This version supports many vendors other [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72,388,17],"tags":[401,354],"class_list":["post-3514","post","type-post","status-publish","format-standard","hentry","category-mathematica","category-openai","category-programming","tag-mathematica-14-1","tag-openai"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-UG","jetpack-related-posts":[{"id":3545,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/11\/09\/semantic-search-in-wolfram-mathematica\/","url_meta":{"origin":3514,"position":0},"title":"Semantic Search in Wolfram Mathematica","author":"admin","date":"November 9, 2024","format":false,"excerpt":"In an earlier article, I explained how to use OpenAI from Wolfram Mathematica ver 14.1. This latest release of Wolfram supports Semantic Search as well. In today\u2019s article, let me discuss this feature. As in the case of using LLMs, using Semantic Search requires an account with one of the\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Remedy Description","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3381,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/05\/20\/using-openai-from-mathematica\/","url_meta":{"origin":3514,"position":1},"title":"Using OpenAI from Mathematica","author":"admin","date":"May 20, 2024","format":false,"excerpt":"Mathematica was among the first to integrate with OpenAI. The functionality is nicely exposed in terms of a few pre-defined functions. Let us explore some of the functionality in today\u2019s article. The simplest way to get started is to use LLMSynthesize\u00a0function: It can take a few seconds before you get\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"LLMSynthesize Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3626,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/02\/21\/using-openai-from-mathematica-part-3\/","url_meta":{"origin":3514,"position":2},"title":"Using OpenAI from Mathematica: Part-3","author":"admin","date":"February 21, 2025","format":false,"excerpt":"Let us continue our discussion on using Mathematica to interact with OpenAI (you may want to go through the earlier article as well). The simplest function to interact with the LLM is LLMSynthesize[]. As you might have guessed, this is a \u201csync\u201d (non-streaming) call. What if you expect a long\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Basic LLMSynthesize","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/fig1-300x21.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/fig1-300x21.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/fig1-300x21.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3050,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/","url_meta":{"origin":3514,"position":3},"title":"Building a Xojo App to Interact with OpenAI API","author":"admin","date":"March 16, 2023","format":false,"excerpt":"A few weeks ago I registered with OpenAI to access its services through API and created a secret Key for my use. I then decided to build a simple application to try out the \u201cChat\u201d and \u201cCompletion\u201d models. Since I have several tools at my disposal (RAD Studio, LispWorks, Allegro\u2026","rel":"","context":"In &quot;OpenAI&quot;","block_context":{"text":"OpenAI","link":"https:\/\/www.rangakrish.com\/index.php\/category\/openai\/"},"img":{"alt_text":"Initial Screen","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen-300x232.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3599,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/01\/20\/using-openai-from-allegro-common-lisp\/","url_meta":{"origin":3514,"position":4},"title":"Using OpenAI from Allegro Common Lisp","author":"admin","date":"January 20, 2025","format":false,"excerpt":"Allegro Common Lisp ver 11.0\u00a0introduced support for OpenAI LLMs. In this article, let us look at some of the functions for interacting with OpenAI. First we need to specify basic parameters such as the API key, LLM to use, Temperature, etc. I have defined a convenient function configure-openai to do\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Configuring the LLM","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/01\/fig1-300x101.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3614,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/02\/04\/interacting-with-openai-api-using-golang\/","url_meta":{"origin":3514,"position":5},"title":"Interacting with OpenAI API using Golang","author":"admin","date":"February 4, 2025","format":false,"excerpt":"I normally use Python\u2019s LangChain framework to communicate with OpenAI API. For a change, I wanted to see if Go has any libraries to access OpenAI and other LLMs. Interestingly I found that LangChainGo\u00a0is a port of LangChain for Golang! I decided to implement a simple Completetion request in both\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Non-streaming Mode","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/code1-300x227.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/code1-300x227.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/02\/code1-300x227.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=3514"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3514\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=3514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=3514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=3514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}