{"id":3050,"date":"2023-03-16T11:37:35","date_gmt":"2023-03-16T06:07:35","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=3050"},"modified":"2024-05-20T15:57:38","modified_gmt":"2024-05-20T10:27:38","slug":"building-a-xojo-app-to-interact-with-openai-api","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/","title":{"rendered":"Building a Xojo App to Interact with OpenAI API"},"content":{"rendered":"<p>A few weeks ago I registered with <a href=\"https:\/\/platform.openai.com\/overview\" target=\"_blank\" rel=\"noopener\"><em><strong>OpenAI<\/strong><\/em><\/a> 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 <em><strong>\u201cChat\u201d<\/strong><\/em> and <em><strong>\u201cCompletion\u201d<\/strong><\/em> models. Since I have several tools at my disposal (<em><strong>RAD Studio<\/strong><\/em>, <em><strong>LispWorks<\/strong><\/em>, <em><strong>Allegro CommonLisp<\/strong><\/em>, <em><strong>Visual Studio<\/strong><\/em>, and <em><strong>Xojo<\/strong><\/em>), I debated briefly as to which of the tools I should use for the current task. Normally I would have selected <em><strong>LispWorks<\/strong><\/em> or <em><strong>RAD Studio<\/strong><\/em>, but this time I decided to use <a href=\"https:\/\/www.xojo.com\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Xojo<\/strong><\/em><\/a>. <em><strong>Xojo<\/strong><\/em> is multplatform (<em><strong>Desktop<\/strong><\/em>, <em><strong>Web<\/strong><\/em> and <em><strong>Mobile<\/strong><\/em>) enabled and fortunately I have a Pro license allowing me to build and deploy in all three formats.<\/p>\n<p>Building the application itself was quite a breeze and there is nothing fancy in the programming logic. I am sharing the project so that you can take a look at what I have done and change the functionality to suit your requirements.<\/p>\n<p>Here is the initial screen.<\/p>\n<figure id=\"attachment_3051\" aria-describedby=\"caption-attachment-3051\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"3051\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/initial-screen\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png\" data-orig-size=\"904,699\" 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=\"Initial Screen\" data-image-description=\"&lt;p&gt;Initial Screen&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Initial Screen&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png\" class=\"wp-image-3051\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png?resize=500%2C387&#038;ssl=1\" alt=\"Initial Screen\" width=\"500\" height=\"387\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png?resize=300%2C232&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png?resize=768%2C594&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Initial-Screen.png?w=904&amp;ssl=1 904w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3051\" class=\"wp-caption-text\"><strong>Initial Screen<\/strong><\/figcaption><\/figure>\n<p>Although the API has several models and corresponding parameters to tweak, I decided to use just two models and two parameters. The <em><strong>\u201cChat\u201d<\/strong><\/em> option uses the underlying <em><strong>\u201cgpt-3.5-turbo\u201d<\/strong><\/em> model while the <em><strong>\u201cCompletions\u201d<\/strong><\/em> option uses <em><strong>\u201ctext-davinci-003\u201d<\/strong><\/em> model. As of this writing I have not got access to the latest <em><strong>\u201cGPT-4\u201d<\/strong><\/em> model although it was released a couple of days ago. For exploring the API, it really doesn\u2019t matter since we are not solving any specific problem.<\/p>\n<p>The <em><strong>\u201cNum Tokens\u201d<\/strong><\/em> field is bound to <em><strong>\u201cmax_tokens\u201d<\/strong><\/em> parameter, allowing us to control the <em>maximum number of tokens<\/em> that the system will generate. The <em><strong>\u201cTemperature\u201d<\/strong><\/em> field is mapped to <em><strong>\u201ctemperature\u201d<\/strong><\/em> parameter, which decides how <em>deterministic<\/em> the system behaviour is. I keep it at <em><strong>\u201cZero\u201d<\/strong><\/em> by default since I want crisp and precise response to my input. You can learn more about these options in the official <a href=\"https:\/\/platform.openai.com\/docs\/api-reference\/chat\" target=\"_blank\" rel=\"noopener\"><em><strong>documentation<\/strong><\/em><\/a>.<\/p>\n<p>What you might find interesting is the <em><strong>\u201cResult Type\u201d<\/strong><\/em> option. Since I use <em><strong>Lisp<\/strong><\/em> a lot, I find it convenient to get the result as an <em><strong>\u201cS-Expression\u201d<\/strong><\/em> as it is easily parsed in the <em><strong>Lisp<\/strong><\/em> environment. Outside of <em><strong>Lisp<\/strong><\/em>, when I wish to use the result in another application, <em><strong>JSON<\/strong><\/em> format is quite useful. For all other use cases, I support the <em><strong>\u201cNormal Text\u201d<\/strong><\/em> option.<\/p>\n<p>How to convey these format options to the API model? I chose a simple trick of prefixing all input text with an appropriate <em><strong>\u201chint\u201d<\/strong><\/em> context:<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #0000ff;\"><em><strong>S-Expression =&gt; \u201cGive just the answer as S-Expression: \u201d<\/strong><\/em><\/span><br \/>\n<span style=\"color: #0000ff;\"><em><strong>JSON =&gt; \u201cGive just the answer as JSON: \u201d<\/strong><\/em><\/span><br \/>\n<span style=\"color: #0000ff;\"><em><strong>Normal Text =&gt; \u201cGive just the answer: \u201d<\/strong><\/em><\/span><\/p>\n<p>With this background, let us look at some interactions.<br \/>\nThe following shows the use of <em><strong>\u201cS-Expression\u201d<\/strong><\/em> in the <em><strong>\u201cResult Type\u201d<\/strong><\/em>:<\/p>\n<figure id=\"attachment_3053\" aria-describedby=\"caption-attachment-3053\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3053\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/screen5-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png\" data-orig-size=\"930,697\" 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=\"Result as S-Expression\" data-image-description=\"&lt;p&gt;Result as S-Expression&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Result as S-Expression&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png\" class=\"wp-image-3053\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png?resize=500%2C375&#038;ssl=1\" alt=\"Result as S-Expression\" width=\"500\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen5.png?w=930&amp;ssl=1 930w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3053\" class=\"wp-caption-text\"><strong>Result as S-Expression<\/strong><\/figcaption><\/figure>\n<p>What is weird in this case is that we get a representation of the input and not the calculated value! Let us try another example:<\/p>\n<figure id=\"attachment_3054\" aria-describedby=\"caption-attachment-3054\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3054\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/screen9\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png\" data-orig-size=\"930,697\" 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=\"Another S-Expression Example\" data-image-description=\"&lt;p&gt;Another S-Expression Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another S-Expression Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png\" class=\"wp-image-3054\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png?resize=500%2C375&#038;ssl=1\" alt=\"Another S-Expression Example\" width=\"500\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen9.png?w=930&amp;ssl=1 930w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3054\" class=\"wp-caption-text\"><strong>Another S-Expression Example<\/strong><\/figcaption><\/figure>\n<p>This works as expected! We can confirm that the generated structure is correct by comparing it with <a href=\"https:\/\/www.wolfram.com\/mathematica\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Mathematica\u2019s<\/strong><\/em><\/a> output for the same text:<\/p>\n<figure id=\"attachment_3055\" aria-describedby=\"caption-attachment-3055\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3055\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/mathematica-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png\" data-orig-size=\"777,177\" 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=\"Structure as Identified by Mathematica\" data-image-description=\"&lt;p&gt;Structure as Identified by Mathematica&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Structure as Identified by Mathematica&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png\" class=\"wp-image-3055\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png?resize=500%2C114&#038;ssl=1\" alt=\"Structure as Identified by Mathematica\" width=\"500\" height=\"114\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png?resize=300%2C68&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png?resize=768%2C175&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Mathematica.png?w=777&amp;ssl=1 777w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3055\" class=\"wp-caption-text\"><strong>Structure as Identified by Mathematica<\/strong><\/figcaption><\/figure>\n<p>Here is an example of <em><strong>\u201cCompletions\u201d<\/strong><\/em> using <em><strong>\u201cNormal Text\u201d<\/strong><\/em> result type:<\/p>\n<figure id=\"attachment_3056\" aria-describedby=\"caption-attachment-3056\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3056\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/screen8\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png\" data-orig-size=\"930,697\" 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=\"Normal Text Result Type\" data-image-description=\"&lt;p&gt;Normal Text Result Type&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Normal Text Result Type&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png\" class=\"wp-image-3056\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png?resize=500%2C375&#038;ssl=1\" alt=\"Normal Text Result Type\" width=\"500\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen8.png?w=930&amp;ssl=1 930w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3056\" class=\"wp-caption-text\"><strong>Normal Text Result Type<\/strong><\/figcaption><\/figure>\n<p>Let use <em><strong>\u201cChat\u201d<\/strong><\/em> model instead of <em><strong>\u201cCompletions\u201d<\/strong><\/em>:<\/p>\n<figure id=\"attachment_3057\" aria-describedby=\"caption-attachment-3057\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3057\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/screen7\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png\" data-orig-size=\"930,697\" 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 Chat Model\" data-image-description=\"&lt;p&gt;Using Chat Model&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using Chat Model&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png\" class=\"wp-image-3057\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png?resize=500%2C375&#038;ssl=1\" alt=\"Using Chat Model\" width=\"500\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen7.png?w=930&amp;ssl=1 930w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3057\" class=\"wp-caption-text\"><strong>Using Chat Model<\/strong><\/figcaption><\/figure>\n<p>Finally, here is an example that uses <em><strong>\u201cJSON\u201d<\/strong><\/em>.<\/p>\n<figure id=\"attachment_3058\" aria-describedby=\"caption-attachment-3058\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3058\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/03\/16\/building-a-xojo-app-to-interact-with-openai-api\/screen6-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png\" data-orig-size=\"930,697\" 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 JSON Type\" data-image-description=\"&lt;p&gt;Using JSON Type&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using JSON Type&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png\" class=\"wp-image-3058\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png?resize=500%2C375&#038;ssl=1\" alt=\"Using JSON Type\" width=\"500\" height=\"375\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/03\/Screen6.png?w=930&amp;ssl=1 930w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3058\" class=\"wp-caption-text\"><strong>Using JSON Type<\/strong><\/figcaption><\/figure>\n<p>As the above scenarios show, the API works as expected. I used <em><strong>Xojo 2022 Release 4.1<\/strong><\/em> to build this application. You can download the project from <a href=\"http:\/\/www.rangakrish.com\/downloads\/OpenAI Tester.xojo_binary_project\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. If you are planning to build and run the application, make sure you get a valid API Key and use it in the project.<\/p>\n<p>Have great day!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 CommonLisp, Visual Studio, and Xojo), [&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":[388,17,318],"tags":[116,354,319],"class_list":["post-3050","post","type-post","status-publish","format-standard","hentry","category-openai","category-programming","category-xojo","tag-api","tag-openai","tag-xojo"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Nc","jetpack-related-posts":[{"id":2765,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/04\/17\/calling-lisp-functions-from-xojo\/","url_meta":{"origin":3050,"position":0},"title":"Calling Lisp Functions from Xojo","author":"admin","date":"April 17, 2022","format":false,"excerpt":"A few days ago, I purchased Xojo Pro commercial license. In case you haven't heard about the product, Xojo\u00a0is a popular cross-platform development tool targeting Desktop, Web and iOS (Android is expected in the near future). It supports an Object-Oriented Basic language. It has been around for over 25 years\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"The Lisp Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3614,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/02\/04\/interacting-with-openai-api-using-golang\/","url_meta":{"origin":3050,"position":1},"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":[]},{"id":3599,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/01\/20\/using-openai-from-allegro-common-lisp\/","url_meta":{"origin":3050,"position":2},"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":3626,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/02\/21\/using-openai-from-mathematica-part-3\/","url_meta":{"origin":3050,"position":3},"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":3514,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/02\/using-openai-from-mathematica-part-2\/","url_meta":{"origin":3050,"position":4},"title":"Using OpenAI from Mathematica: Part-2","author":"admin","date":"October 2, 2024","format":false,"excerpt":"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\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\/10\/image1-300x71.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1-300x71.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/image1-300x71.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":599,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/08\/30\/kp-astrology-rest-api\/","url_meta":{"origin":3050,"position":5},"title":"KP Astrology REST API","author":"admin","date":"August 30, 2017","format":false,"excerpt":"In today's post I want to share my experience in implementing a set of REST API calls for Astrology. The series on iLangGen will resume after this. As readers of this column probably know, I am the author of an Astrology software called KPAstro. You can read about it here.\u2026","rel":"","context":"In &quot;Astrology&quot;","block_context":{"text":"Astrology","link":"https:\/\/www.rangakrish.com\/index.php\/category\/astrology\/"},"img":{"alt_text":"Project Step 1","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Project-image1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Project-image1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/08\/Project-image1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3050","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=3050"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3050\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=3050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=3050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=3050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}