<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steve Mayne on Medium]]></title>
        <description><![CDATA[Stories by Steve Mayne on Medium]]></description>
        <link>https://medium.com/@stevemayne_8055?source=rss-32d699a5d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VEVJxlCjiE1llttV.</url>
            <title>Stories by Steve Mayne on Medium</title>
            <link>https://medium.com/@stevemayne_8055?source=rss-32d699a5d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:31:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stevemayne_8055/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Structure from the Chaos — Using ChatGPT to iteratively complete forms]]></title>
            <link>https://medium.com/@stevemayne_8055/structure-from-the-chaos-using-chatgpt-to-iteratively-complete-forms-756874f3d75e?source=rss-32d699a5d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/756874f3d75e</guid>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[gpt]]></category>
            <dc:creator><![CDATA[Steve Mayne]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 16:44:45 GMT</pubDate>
            <atom:updated>2024-03-23T16:57:49.292Z</atom:updated>
            <content:encoded><![CDATA[<h3>Structure from the Chaos — Using ChatGPT to iteratively complete forms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a4DMOn_xFgy78D0XUcl2IQ.jpeg" /><figcaption>Structure from the Chaos</figcaption></figure><p>I don’t know about you, but filling in forms is one of my least favourite activities. They’re dry, often confusing, and depend on copy-paste from your memory or other systems. Some godforsaken jobs require people to spend their days completing them: Requisitions, taxes, referrals — you name it, humans have created a special form of hell for each other (pun intended).</p><p>If you’re on the phone with a customer services department, they’ll often fill out a form on your behalf, simply to escalate your request into the bowels of their organisation. This process is often highly inefficient, with disparate systems (e.g. the incoming ticketing system) separate from the structured data required to achieve an outcome (e.g. an internal administration panel).</p><p>So what can be done about it?</p><p>Well, we could ask our customers to fill in the forms themselves — but the experience would be poor. It merely passes the buck onto another, unfortunate human.</p><p>What if we could talk through the information we needed whilst omitting unnecessary questions?</p><h4>Structure from the Chaos</h4><p>LLMs, amongst their many qualities, provide a fuzzy interface to data. They can convert unstructured data into structured, and vice-versa.</p><p>Let’s have a look at a real example using ChatGPT.</p><p>First of all, imagine describing an existing, structured support request from a ticketing system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofrpI4RlF2ZHgoTwBeUIsQ.png" /><figcaption>Structured data to a human-readable, unstructured sentence</figcaption></figure><p>Now imagine doing the reverse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCfKt8fgFHuK3qLW1beJtA.png" /><figcaption>Unstructured request to structured data</figcaption></figure><p>This is awesomely powerful. Using this technique we could take unstructured requests from the chat messages and plug them straight into systems that require structured input.</p><p>Moreover, we can define the data we require in a standardised prompt structure, allowing us to adapt this pattern for different requirements.</p><p>“Ok,” I hear you cry, “But what if they haven’t provided sufficient information?”</p><h4>Let’s Get Iterative</h4><p>Imagine a chatbot servicing requests directly with the user, asking more questions until satisfied.</p><p>We’ll use this technique iteratively until we’ve completed our form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NO4VIkDS_wr_TC3cfWFJNw.png" /></figure><p>We will keep passing in new user input alongside our JSON state, let ChatGPT fill in any gaps, prompt for more input, or trigger completion.</p><p>A bonus of this technique is that we don’t have to continually pass the full history of our user’s input into our context window — our form state acts as a summary of everything that’s already happened.</p><h4>Implementation using Langchain</h4><p>The following code runs against GPT-3.5 and uses the fantastic “Streamlit” library to mock up a simple chat user interface.</p><pre># Import required libraries<br>from dotenv import load_dotenv<br>from itertools import zip_longest<br><br>import json<br>import streamlit as st<br>from streamlit_chat import message<br><br>from langchain_community.chat_models import ChatOpenAI<br>from langchain.schema import (<br>    SystemMessage,<br>    HumanMessage,<br>    AIMessage<br>)<br><br># Load environment variables<br>load_dotenv()<br><br># Set streamlit page configuration<br>st.set_page_config(page_title=&quot;Helpdesk Bot&quot;)<br>st.title(&quot;Helpdesk Bot&quot;)<br><br># Initialize session state variables<br>if &#39;generated&#39; not in st.session_state:<br>    st.session_state[&#39;generated&#39;] = []  # Store AI generated responses<br><br>if &#39;past&#39; not in st.session_state:<br>    st.session_state[&#39;past&#39;] = []  # Store past user inputs<br><br>if &#39;entered_prompt&#39; not in st.session_state:<br>    st.session_state[&#39;entered_prompt&#39;] = &quot;&quot;  # Store the latest user input<br>    <br>if &#39;form&#39; not in st.session_state:<br>    st.session_state[&#39;form&#39;] = {}  # Store the form state<br><br># Initialize the ChatOpenAI model<br>chat = ChatOpenAI(<br>    temperature=0.5,<br>    model_name=&quot;gpt-3.5-turbo&quot;<br>)<br><br><br>def build_message_list():<br>    &quot;&quot;&quot;<br>    Build a list of messages including system, human and AI messages.<br>    &quot;&quot;&quot;<br>    # Start zipped_messages with the SystemMessage<br>    zipped_messages = [SystemMessage(<br>        content=&quot;&quot;&quot;You are a bot acting as a secretary, filling out an IT helpdesk form based on the information provided by the user and the following template:<br>{<br>  &quot;clientName&quot;: {<br>    &quot;example&quot;: &quot;John Doe&quot;,<br>    &quot;mandatory&quot;: true,<br>    &quot;description&quot;: &quot;The name of the person requesting help including their first and last name&quot;<br>  },<br>  &quot;computerAgeYears&quot;: {<br>    &quot;example&quot;: 3,<br>    &quot;mandatory&quot;: true,<br>    &quot;description&quot;: &quot;The age of the computer in years&quot;<br>  },<br>  &quot;computerAssetTag&quot;: {<br>    &quot;example&quot;: &quot;123456&quot;,<br>    &quot;mandatory&quot;: true,<br>    &quot;description&quot;: &quot;The asset tag of the computer in alphanumeric format&quot;<br>  },<br>  &quot;faultDescription&quot;: {<br>    &quot;example&quot;: &quot;The computer won&#39;t turn on&quot;,<br>    &quot;mandatory&quot;: true,<br>    &quot;description&quot;: &quot;A description of the fault including any error messages&quot;<br>  },<br>}<br>If you need more information to fill out the form, you should request it from the user using the description fields. If you cannot establish an answer based on the provided information, leave the entry blank. Once the form is complete, you should provide the user with a summary of the information you have collected.<br><br>Always reply using json including both the new form state and a message for the user:<br>{<br>    &quot;formState&quot;: {},<br>    &quot;message&quot;: &quot;&quot;,<br>}<br>&quot;&quot;&quot;)]<br>    # # Zip together the past and generated messages<br>    for human_msg, ai_msg in zip_longest(st.session_state[&#39;past&#39;], st.session_state[&#39;generated&#39;]):<br>        if human_msg is not None:<br>            zipped_messages.append(HumanMessage(<br>                content=human_msg))  # Add user messages<br>        if ai_msg is not None:<br>            zipped_messages.append(<br>                AIMessage(content=ai_msg))  # Add AI messages<br>    return zipped_messages<br><br><br>def generate_response():<br>    &quot;&quot;&quot;<br>    Generate AI response using the ChatOpenAI model.<br>    &quot;&quot;&quot;<br>    # Build the list of messages<br>    zipped_messages = build_message_list()<br><br>    # Generate response using the chat model<br>    ai_response = chat(zipped_messages)<br><br>    return ai_response.content<br><br><br># Define function to submit user input<br>def submit():<br>    # Set entered_prompt to the current value of prompt_input<br>    st.session_state.entered_prompt = st.session_state.prompt_input<br>    # Clear prompt_input<br>    st.session_state.prompt_input = &quot;&quot;<br><br><br># Create a text input for user<br>st.text_input(&#39;YOU: &#39;, key=&#39;prompt_input&#39;, on_change=submit)<br><br><br>if st.session_state.entered_prompt != &quot;&quot;:<br>    # Get user query<br>    user_query = st.session_state.entered_prompt<br><br>    # Append user query to past queries<br>    st.session_state.past.append(user_query)<br><br>    # Generate response<br>    output = generate_response()<br><br>    if (output.startswith(&#39;{&#39;)):<br>    # Split output into message and form data<br>        output_d = json.loads(output)<br>        user_message = output_d[&#39;message&#39;]<br>        form_state = output_d[&#39;formState&#39;]<br>    else:<br>        user_message = output<br>        form_state = None<br><br>    # Append AI response to generated responses<br>    st.session_state.generated.append(user_message)<br>    if form_state:<br>        st.session_state.form = form_state<br><br># Display the chat history<br>if st.session_state[&#39;generated&#39;]:<br>    # Display the current form state<br>    if st.session_state[&#39;form&#39;]:<br>        st.json(st.session_state[&#39;form&#39;])<br>    for i in range(len(st.session_state[&#39;generated&#39;])-1, -1, -1):<br>        # Display AI response<br>        message(st.session_state[&quot;generated&quot;][i], key=str(i))<br>        # Display user message<br>        message(st.session_state[&#39;past&#39;][i],<br>                is_user=True, key=str(i) + &#39;_user&#39;)</pre><h4>Run the Code!</h4><p>Even though we’re using a old GPT model, the exchange to complete our form is satisfactory. I even tried to ‘trick’ the bot by supplying an age in months (rather than years), and it converted the value correctly.</p><p>Unlike a traditional Q&amp;A chatbot, if the user supplies multiple pieces of information in a single answer, they are all captured and used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yt5Fp9YHCxJ8YB9N7o8GIg.gif" /></figure><p><strong>Video Transcript</strong></p><blockquote>User: “I need help with my computer”</blockquote><blockquote>AI: “Please provide your full name, the age of your computer in years, the asset tag of the computer, and a description of the fault you are experiencing.”</blockquote><blockquote>User: “My name is Steve Mayne and my computer is 12 months old”</blockquote><pre>{<br>&quot;clientName&quot;:&quot;Steve Mayne&quot;<br>&quot;computerAgeYears&quot;:1<br>}</pre><blockquote>AI: “Thank you for the information. Please provide the asset tag of the computer and a description of the fault you are experiencing.”</blockquote><blockquote>User: “Asset tag is 1234”</blockquote><blockquote>AI: “Could you please provide a description of the fault you are experiencing with your computer?”</blockquote><blockquote>User: “It won’t turn on”</blockquote><pre>{<br>&quot;clientName&quot;:&quot;Steve Mayne&quot;<br>&quot;computerAgeYears&quot;:1<br>&quot;computerAssetTag&quot;:&quot;1234&quot;<br>&quot;faultDescription&quot;:&quot;The computer won&#39;t turn on&quot;<br>}</pre><h3>Conclusion</h3><p>Although it’s still very rough around the edges, I hope you can see how this technique could be used as the basis for quickly and easily wrapping any form with a bot interface.</p><p>Of course, the benefits don’t end there: How about filling in as much of the form as possible from an email and asking ChatGPT to request any missing information from the sender? No more time spent chasing information!</p><p>The opportunities for creating structure from unstructured data are endless and I hope I’ve inspired you to take this concept further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=756874f3d75e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating Image Captions (Alt Text) with ChatGPT and Azure AI Vision]]></title>
            <link>https://medium.com/@stevemayne_8055/generating-image-captions-alt-text-with-chatgpt-and-azure-ai-vision-596ec430d725?source=rss-32d699a5d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/596ec430d725</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[vision]]></category>
            <category><![CDATA[multimodal]]></category>
            <dc:creator><![CDATA[Steve Mayne]]></dc:creator>
            <pubDate>Sat, 27 Jan 2024 14:19:43 GMT</pubDate>
            <atom:updated>2024-02-02T07:47:03.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUq7Mfztyh-Cb-b1Vc3Odg.png" /><figcaption>ChatGPT Vision</figcaption></figure><p>Imagine the scenario, your website has thousands of images but no captions… The idea of going through each of them by hand is far less appealing than learning something new and writing a blog post about it, so here we are!</p><p>For those who don’t know, <em>Alt Text</em> is an invisible caption associated with an image on a webpage. It’s best practice to have one for every image.</p><p>There are hundreds of millions of visually impaired people in the world, and many rely on screen readers. Alt Text describes images that people cannot see for themselves.</p><p>“Big deal!” I hear some of you cry, “I don’t have time for accessibility. I’ve got <em>deadlines</em>!”</p><p>Well, <a href="https://www.forbes.com/sites/forbesbusinesscouncil/2023/03/20/understanding-the-importance-of-web-accessibility/">I won’t argue with deadlines</a>, but you probably make time for SEO. Alt Text is used by Google and other search engines to help index your site. It can also help your products appear in image search results on Google and marketplace sites like Etsy.</p><p>Until recently, describing images using natural language was something that could only be done by humans. But not any more…</p><h4>Computer Vision History: Image Classification</h4><p>When Randall Munroe published <a href="https://xkcd.com/1425/">this comic</a> on <a href="https://xkcd.com/">XKCD</a> less than ten years ago (2014), image classification was a complex problem:</p><figure><img alt="XKCD comic explaining that image classification is a complex problem, in 2014" src="https://cdn-images-1.medium.com/max/267/0*ffD0o3ua-kRpYn4f.png" /><figcaption>In 2014, Image Classification was hard</figcaption></figure><p>Yet less than a decade later, we consider it rather trivial. There are numerous image-classification Models and tutorials freely available, e.g. from <a href="https://huggingface.co/">Hugging Face</a>:</p><p><a href="https://huggingface.co/docs/transformers/tasks/image_classification">Image classification</a></p><p><em>Classification</em> is the process of taking an image and applying a label (or labels) to its contents, usually with a probability assigned to the results (e.g. 98% chance of being a cat, 0.05% chance of being a magical liopleurodon).</p><p>However, for our Alt Text problem, simply labelling our product image as “cat” is going to be insufficient. A good piece of Alt Text describes the image. “There is a 90% probability that this is a cat” probably wouldn’t satisfy the SEO team either.</p><h4>Semantic Grounding and Multimodal Learning</h4><p><em>Semantic Grounding</em> is a term used to describe the way that an AI model links language concepts to other sensory inputs, such as images or videos. Essentially, it’s about creating a connection between words and the physical world they describe.</p><p>Multimodal AI models are trained on more than one type of input (e.g. images and text) to infer these grounding associations.</p><p>This is a huge step up from straightforward image classification and allows such models to perform tasks such as:</p><ul><li>Image Captioning: Generating textual descriptions for images.</li><li>Visual Question Answering: Answering questions based on the content of an image.</li></ul><p>Grounding is a complex task because it requires the model to not only understand the content of the image and text separately but also to comprehend the nuanced relationships between them. This involves a sophisticated understanding of both visual and linguistic cues.</p><h4>Chat GPT Vision</h4><p>Everyone knows that Chat GPT can hold a conversation, but many don’t realise that Chat GPT 4 is a multimodal model. It can analyse text and images together, making it the perfect tool to solve our little Alt Text problem.</p><p>With a simple prompt on the <a href="https://chat.openai.com/">Chat GPT website</a>, we can ask it to describe our products (<a href="https://www.etsy.com/uk/listing/1665273021/resident-evil-mug-umbrella-corporation">such as this geeky mug</a>) and produce our alt-text output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qt15WcgyZBVAEFlvKKKZQ.png" /><figcaption>Chat GPT 4 generating alt-text output for an uploaded image</figcaption></figure><p>It’s almost too easy! Notice how it understands not only the objects in the image, but the relationship between them (i.e. “background objects”).</p><p>Now we know what to ask for, we can easily wrap it into a piece of Python code and invoke it automatically for each of our images:</p><pre>from openai import OpenAI<br><br>client = OpenAI(<br>    api_key=&quot;** OPENAI KEY **&quot;<br>)<br><br>def generate_alt_text(image_url):<br>  response = client.chat.completions.create(<br>    model=&quot;gpt-4-vision-preview&quot;,<br>    messages=[<br>      {<br>        &quot;role&quot;: &quot;user&quot;,<br>        &quot;content&quot;: [<br>          {<br>            &quot;type&quot;: &quot;text&quot;, <br>            &quot;text&quot;: &quot;Generate a suitable sentence for product image alt-text. Focus on the product, not the background objects.&quot;},<br>          {<br>            &quot;type&quot;: &quot;image_url&quot;,<br>            &quot;image_url&quot;: {<br>              &quot;url&quot;: image_url,<br>            },<br>          },<br>        ],<br>      }<br>    ],<br>    max_tokens=4096,<br>  )<br><br>if __name__ == &quot;__main__&quot;:<br>  text = generate_alt_text(&quot;https://i.etsystatic.com/45823779/r/il/4f38a8/5516029834/il_1588xN.5516029834_sn85.jpg&quot;)<br>  print(text)</pre><p>Running this demo script against this <a href="https://quirkify.shop/products/stardew-valley-customisable-mug-your-own-farm-name-artisan-goods-left-or-right-handed-cosy-personalised-gaming-gift">Stardew Valley Mug</a> generates the following caption:</p><blockquote>Colorful ceramic mug with yellow handle, one side featuring a ‘Tea Artisan Goods’ label with stat boosts, and the other side depicting a vibrant ‘Stardew Valley’ farm scene.</blockquote><p>Incredible! Now because this is ChatGPT, we can easily augment the output by concatenating our product description onto our prompt. This might help SEO by adding certain keywords that can’t be easily determined from the picture.</p><blockquote>Generate a suitable sentence for product image alt-text. Focus on the product, not the background objects. Consider the additional product text: “15oz Stardew Valley Mug”</blockquote><p>To which returned the almost perfect sentence:</p><blockquote>“15oz Stardew Valley Mug: a vibrant yellow mug with an in-game style label for ‘Tea — Artisan Goods’, detailing buffs such as energy and health boosts.”</blockquote><p>I don’t think I could do any better myself!</p><h4>Azure AI Vision / Microsoft Florence</h4><p>ChatGPT isn’t free, and access to the GPT-4 vision model is currently restricted. Fortunately, it isn’t the only game in town.</p><p>Microsoft have created a multimodal model called “<a href="https://encord.com/blog/florence-2-explained/">Florence</a>” which generates fantastic results of its own, and can even return bounding boxes, categories, and OCR text. It is hosted on Microsoft’s Azure Cloud.</p><p>The full suite of options available in Azure AI Vision include:</p><ul><li>Recognisable objects</li><li>A caption for the image (much like Chat GPT Vision)</li><li>A dense caption which goes to town describing not only the image, but specific regions within the image too</li><li>Objects and their locations (bounding boxes)</li><li>People</li><li>Text (OCR)</li><li>Crop suggestions (suitable for deciding on suitable places to cut out thumbnails)</li></ul><p>Microsoft has created a good tutorial to get you set up on Azure and <a href="https://learn.microsoft.com/en-gb/azure/ai-services/computer-vision/quickstarts-sdk/image-analysis-client-library-40?pivots=programming-language-python&amp;tabs=visual-studio%2Cwindows">start playing with Microsoft Vision</a>.</p><p>Let’s give it a go! The following code takes an image URL as input, and prints out the information generated by the model:</p><pre>import load_secrets<br>import time<br>import pprint<br>import azure.ai.vision as visionsdk<br><br>def analyse_image_async(image_url: str):<br>    &quot;&quot;&quot;<br>    Analyze image from URL, asynchronous (non-blocking)<br>    &quot;&quot;&quot;<br><br>    service_options = visionsdk.VisionServiceOptions(load_secrets.endpoint, load_secrets.key)<br>    vision_source = visionsdk.VisionSource(url=image_url)<br><br>    analysis_options = visionsdk.ImageAnalysisOptions()<br>    analysis_options.features = (visionsdk.ImageAnalysisFeature.CROP_SUGGESTIONS |<br>        visionsdk.ImageAnalysisFeature.CAPTION |<br>        visionsdk.ImageAnalysisFeature.DENSE_CAPTIONS |<br>        visionsdk.ImageAnalysisFeature.OBJECTS |<br>        visionsdk.ImageAnalysisFeature.PEOPLE |<br>        visionsdk.ImageAnalysisFeature.TEXT |<br>        visionsdk.ImageAnalysisFeature.TAGS)<br><br>    image_analyzer = visionsdk.ImageAnalyzer(service_options, vision_source, analysis_options)<br><br>    callback_done = False<br><br>    def analyzed_callback(args: visionsdk.ImageAnalysisEventArgs):<br>        &quot;&quot;&quot;callback that signals analysis is done&quot;&quot;&quot;<br>        print_result(args.result)<br>        nonlocal callback_done<br>        callback_done = True<br><br>    image_analyzer.analyzed.connect(analyzed_callback)<br>    image_analyzer.analyze()<br><br>    while not callback_done:<br>        time.sleep(.1)<br><br>def print_result(result: ImageAnalysisResult):<br>  if result.caption is not None:<br>    print(&quot; Caption:&quot;)<br>    print(&quot;   &#39;{}&#39;, Confidence {:.4f}&quot;.format(result.caption.content, result.caption.confidence))<br>  # etc. Snipped for brevity<br><br>if __name__ == &#39;__main__&#39;:<br>  analyse_image_async(&quot;https://i.etsystatic.com/45823779/r/il/4f38a8/5516029834/il_1588xN.5516029834_sn85.jpg&quot;)</pre><p>Running it for the same Stardew Valley Mug as our ChatGPT example gives us the following output:</p><pre>Image height: 894<br> Image width: 1588<br> Model version: 2023-02-01-preview<br> Caption:<br>   &#39;two mugs on a table&#39;, Confidence 0.8097<br> Dense Captions:<br>   &#39;two mugs on a table&#39;, Rectangle(x=0, y=0, w=1588, h=894), Confidence: 0.8097<br>   &#39;a mug with a picture on it&#39;, Rectangle(x=785, y=300, w=510, h=479), Confidence: 0.7364<br>   &#39;a yellow and white mug with text on it&#39;, Rectangle(x=214, y=301, w=508, h=468), Confidence: 0.7640<br>   &#39;two mugs with pictures on them&#39;, Rectangle(x=181, y=296, w=1206, h=578), Confidence: 0.7211<br>   &#39;a close up of a plant&#39;, Rectangle(x=883, y=0, w=167, h=316), Confidence: 0.8322<br>   &#39;a yellow letter on a green background&#39;, Rectangle(x=840, y=481, w=256, h=73), Confidence: 0.6944<br>   &#39;a wooden spoons on a table&#39;, Rectangle(x=0, y=598, w=290, h=136), Confidence: 0.7201<br>   &#39;a close-up of a yellow handle&#39;, Rectangle(x=219, y=389, w=170, h=286), Confidence: 0.8220<br>   &#39;a close-up of two mugs&#39;, Rectangle(x=295, y=2, w=1045, h=404), Confidence: 0.7562<br>   &#39;a close up of a handle&#39;, Rectangle(x=1125, y=387, w=171, h=288), Confidence: 0.8319<br> Objects:<br>   &#39;Container&#39;, Rectangle(x=217, y=314, w=530, h=453), Confidence: 0.6280<br>   &#39;Container&#39;, Rectangle(x=792, y=316, w=511, h=469), Confidence: 0.5130<br> Tags:<br>   &#39;coffee cup&#39;, Confidence 0.9426<br>   &#39;tableware&#39;, Confidence 0.9313<br>   &#39;indoor&#39;, Confidence 0.9262<br>   &#39;mug&#39;, Confidence 0.9221<br>   &#39;table&#39;, Confidence 0.9137<br>   &#39;drinkware&#39;, Confidence 0.8934<br>   &#39;serveware&#39;, Confidence 0.8911<br>   &#39;ceramic&#39;, Confidence 0.8728<br>   &#39;cup&#39;, Confidence 0.8679<br>   &#39;pitcher&#39;, Confidence 0.8463<br>   &#39;coffee&#39;, Confidence 0.7267<br>   &#39;plant&#39;, Confidence 0.5999<br> People:<br>   Rectangle(x=892, y=619, w=25, h=44), Confidence 0.0013<br> Crop Suggestions:<br>   Aspect ratio 1.95: Crop suggestion Rectangle(x=66, y=112, w=1456, h=745)<br> Text:<br>   Line: &#39;Tea&#39;, Bounding polygon {437, 428, 492, 433, 492, 461, 435, 458}<br>     Word: &#39;Tea&#39;, Bounding polygon {438, 428, 488, 432, 486, 462, 436, 458}, Confidence 0.6720<br>   Line: &#39;STARDEW&#39;, Bounding polygon {827, 413, 1105, 416, 1103, 488, 826, 483}<br>     Word: &#39;STARDEW&#39;, Bounding polygon {836, 414, 1087, 417, 1087, 488, 835, 484}, Confidence 0.4400<br>   Line: &#39;Artisan Goods&#39;, Bounding polygon {435, 465, 585, 468, 585, 495, 434, 491}<br>     Word: &#39;Artisan&#39;, Bounding polygon {437, 465, 505, 467, 504, 494, 435, 492}, Confidence 0.8320<br>     Word: &#39;Goods&#39;, Bounding polygon {510, 467, 585, 469, 584, 496, 509, 494}, Confidence 0.9960<br>   Line: &#39;VALLEY&#39;, Bounding polygon {851, 480, 1079, 483, 1078, 541, 850, 539}<br>     Word: &#39;VALLEY&#39;, Bounding polygon {852, 480, 1071, 485, 1070, 541, 851, 540}, Confidence 0.9060<br>   ... snipped ...</pre><p>Whilst the response contains so much more detail than we get from ChatGPT, the model constructed a weak overall caption:</p><blockquote>Two mugs on a table</blockquote><p><em>NB: I suspect responses will be better with Florence-2, which you can use as a foundation model for further training.</em></p><p>However, such is the power of ChatGPT, even when dealing with text, I simply fed it the whole response (including the categorisations, OCR results and regional captions):</p><blockquote>Based on the following Microsoft Vision output, generate an alt-text label for the image:<br> <br>Image height: 894<br>Image width: 1588<br>Model version: 2023–02–01-preview<br>Caption: ‘two mugs on a table’, Confidence 0.8097<br>… snipped …</blockquote><p>Which produced a far more satisfying output:</p><blockquote>“Two mugs with Stardew Valley and artisan tea graphics, featuring in-game benefits, placed on a table with a plant and wooden spoons in the background.&quot;</blockquote><h4>Conclusion</h4><p>Multimodal AI models are mind-blowing, and I’ve barely scratched the surface of what they can do. My mind is racing with possibilities, such as the potential for screen reader software to integrate with vision models, enabling individuals with vision impairments to ‘visualise’ images while reading books or navigating websites.</p><p>There’s a whole world of potential out there, yet, at this moment, their incredible power is being channelled into crafting Alt Text for me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=596ec430d725" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing live data with ChatGPT]]></title>
            <link>https://medium.com/@stevemayne_8055/accessing-live-data-with-chatgpt-65e95cd666db?source=rss-32d699a5d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/65e95cd666db</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Steve Mayne]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 16:06:35 GMT</pubDate>
            <atom:updated>2024-01-14T16:15:53.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*syUe0YNoJuSGDeJa_lZpGg.png" /></figure><p>ChatGPT has quickly supplanted Search as the quickest way to get answers to questions, but until recently it’s been missing a key feature — the ability to access live data. In the past, when asking Chat GPT a topical question requiring up-to-date knowledge, it responded as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RW-0ewR-GIOpbq_8nBDBCQ.png" /><figcaption>“When was the hottest year on record?” “… 2020 …”</figcaption></figure><p>So how have Open AI solved this problem?</p><p>They have introduced <strong><em>Actions</em></strong>: Small pieces of code that allow ChatGPT to interact with external systems.</p><p>OpenAI has integrated ChatGPT with numerous actions already. If you ask for an image, the <em>DALL·E</em> action will create one for you, and if you ask a question that demands an up-to-date answer, it will often query Bing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CrpZ4XH4KIqTfnHvU4qEOQ.png" /></figure><p>In this article, I’m going to show how you can quickly and easily write your own actions to access live information from any source.</p><h3>Example — Domain Availability Checker</h3><p>When creating a website, it’s common to register a domain name for your brand. But with over 365 million domain names currently registered, it’s unlikely you’ll get the first one you want. Some creativity is usually required!</p><h4>ChatGPT to the Rescue</h4><p>After discovering that icecream.com was taken, I asked Chat GPT for alternative domain names for my ice cream company:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1SaDlNteJCCL6KZcB487Q.png" /></figure><p>Great! I especially like ScoopSensation.com. However, it would be time-consuming to take each of these suggestions and paste them into a domain registration website, only to be told they’re unavailable again and again.</p><p>Wouldn’t it be cool if we could get Chat GPT to check each of its answers?</p><p>Well, we’re in luck, because we can do exactly that. And I’m going to show you how to do it.</p><h4>API</h4><p>ChatGPT can integrate with any publicly-addressable API, even if it requires authentication.</p><p>For this example, we’ll create a little demo API which does a basic domain-availability check.</p><p><em>(In reality, you’d want to check with a registration API, but here we’re just checking if the domain resolves to an IP address and calling it ‘available’ if it doesn’t)</em></p><pre>from flask import Flask, jsonify, request<br>import dns.resolver<br><br>app = Flask(__name__)<br><br># Function to check domain availability<br>def is_domain_available(domain):<br>    try:<br>        # Attempt to resolve the domain<br>        dns.resolver.resolve(domain, &#39;A&#39;)<br>        return False  # Domain is registered<br>    except dns.resolver.NoAnswer:<br>        return True   # Domain is likely available<br>    except dns.resolver.NXDOMAIN:<br>        return True   # Domain is not registered<br>    except Exception as e:<br>        return str(e) # Other errors<br><br># API endpoint to check domain availability<br>@app.route(&#39;/check_domain&#39;, methods=[&#39;GET&#39;])<br>def check_domain():<br>    domain = request.args.get(&#39;domain&#39;, default=&#39;&#39;, type=str)<br>    if domain:<br>        is_available = is_domain_available(domain)<br>        return jsonify({&#39;domain&#39;: domain, &#39;is_available&#39;: is_available})<br>    else:<br>        return jsonify({&#39;error&#39;: &#39;No domain specified&#39;}), 400<br><br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(debug=True)</pre><p>Using this API is trivial, as the following query for testmedium123.com shows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zcdntDRwxK6aHfpuaoIUTQ.png" /><figcaption>Domain registration check for testmedium123.com showing is_available = true</figcaption></figure><p>Ok, great- we’ve set up our API to tell us whether a domain is available, how do we get ChatGPT to use it?</p><h4>Creating a GPT</h4><p>First you must log into Chat GPT, then access your GPTs page:</p><p><a href="https://chat.openai.com/gpts/mine">https://chat.openai.com/gpts/mine</a></p><p>Here, you will find the option to create a GPT of your own:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*cQTDYs1AbFElJbzm7U_OZg.png" /><figcaption>Create a GPT: Customize a version of ChatGPT for a specific purpose</figcaption></figure><p>Within the “Create a GPT” interface, we provide a brief overview of what our GPT allows users to do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FFw7Pxrba-H6LUhl97uVdw.png" /><figcaption>GPT Settings</figcaption></figure><p>Scroll to the bottom of the page, and you will find a button to “Create a new action”.</p><p>Within this panel, we have various options which allow us to describe our new API to ChatGPT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvM9qBJFqLP2PvouavQRxg.png" /><figcaption>ChatGPT Actions Options</figcaption></figure><p>The core part of this section is some JSON called the “API Schema,” which I have repeated below so that we can discuss it.</p><p><em>NB: If your API has been written using a modern API framework, then you might be able to import this schema directly from the API itself.</em></p><pre>{<br>  &quot;openapi&quot;: &quot;3.1.0&quot;,<br>  &quot;info&quot;: {<br>    &quot;title&quot;: &quot;Is domain registered?&quot;,<br>    &quot;description&quot;: &quot;Returns if a domain is registered or not.&quot;,<br>    &quot;version&quot;: &quot;v1.0.0&quot;<br>  },<br>  &quot;servers&quot;: [<br>    {<br>      &quot;url&quot;: &quot;https://domregapi.&lt;redacted&gt;&quot;<br>    }<br>  ],<br>  &quot;paths&quot;: {<br>    &quot;/check_domain&quot;: {<br>      &quot;get&quot;: {<br>        &quot;description&quot;: &quot;Determine if a domain is registered&quot;,<br>        &quot;operationId&quot;: &quot;GetDomainAvailability&quot;,<br>        &quot;parameters&quot;: [<br>          {<br>            &quot;name&quot;: &quot;domain&quot;,<br>            &quot;in&quot;: &quot;query&quot;,<br>            &quot;description&quot;: &quot;The domain name&quot;,<br>            &quot;required&quot;: true,<br>            &quot;schema&quot;: {<br>              &quot;type&quot;: &quot;string&quot;<br>            }<br>          }<br>        ],<br>        &quot;deprecated&quot;: false<br>      }<br>    }<br>  },<br>  &quot;components&quot;: {<br>    &quot;schemas&quot;: {}<br>  }<br>}</pre><p>The info and description parts are very important, as this informs ChatGPT what your function does and when to invoke it. This is worth repeating: the description is not just for your benefit — you’re explaining to ChatGPT when your function is useful.</p><p>In my example we have a single get endpoint /check_domain which takes a single string parameter domain</p><p>Those of you who are used to creating strongly typed interfaces probably shudder at the notion that this information is sufficient for ChatGPT to work out what to do. Even without a return schema!</p><p>Click “Save” in the top-right corner of the screen, then let’s see what happens when we ask ChatGPT for some more ice cream domains!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LyqnCuv01xaw30kR4YW-Aw.png" /></figure><p>ChatGPT has worked out that it needs to call the API ten times to check the availability of each domain. Once it is done, it even returns us a helpful summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nM1EAfPGj-DnwrbIn9PgcA.png" /><figcaption>ChatGPT Action results</figcaption></figure><p>Excellent, ScoopDelight.com is available! Sign me up!</p><h4>Where do we go from here?</h4><p>Well, this is powerful, but slow. It made 10 serial calls to our API — one for each domain. What if we tried to create an endpoint that could lookup multiple domains in a single call?</p><p><em>NB: This would be even faster using asyncio and doing the lookups in parallel, but it’s just a demo!</em></p><pre>@app.route(&#39;/check_domains&#39;, methods=[&#39;GET&#39;])<br>def check_domains():<br>    domains = request.args.get(&#39;domains&#39;, default=&#39;&#39;, type=str)<br>    if domains:<br>        results = {}<br>        for domain in domains.split(&#39;,&#39;):<br>            results[domain] = is_domain_available(domain)<br>        return jsonify({&#39;results&#39;: results})<br>    else:<br>        return jsonify({&#39;error&#39;: &#39;No domain specified&#39;}), 400</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrgYSDDF_5fifUeaVHwyXg.png" /></figure><p>Let’s see what ChatGPT makes of a more complex arrangement — where the parameters are comma-separated and the results need to be extracted from a deeper structure.</p><p>I added the new endpoint to the GPT’s schema:</p><pre>&quot;/check_domains&quot;: {<br>  &quot;get&quot;: {<br>    &quot;description&quot;: &quot;Determine if multiple domains are registered&quot;,<br>    &quot;operationId&quot;: &quot;GetDomainsAvailability&quot;,<br>    &quot;parameters&quot;: [<br>      {<br>        &quot;name&quot;: &quot;domains&quot;,<br>        &quot;in&quot;: &quot;query&quot;,<br>        &quot;description&quot;: &quot;The domain names to check&quot;,<br>        &quot;required&quot;: true,<br>        &quot;schema&quot;: {<br>          &quot;type&quot;: &quot;string&quot;<br>        }<br>      }<br>    ],<br>    &quot;deprecated&quot;: false<br>  }<br>}</pre><p>Once I’d edited the schema, I was presented with a button to test the new endpoint / action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*br5V8XDwJ1ugcl06mDmSDQ.png" /><figcaption>GetDomainsAvailability appeared for test</figcaption></figure><p>I clicked the button and ChatGPT dutifully made up a suitable request, provided debug information about what it sent and what it received, and understood the resulting payload first time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnrAUG4ftP8ok-DmnoPAEA.png" /></figure><p>Three results in a single API call!</p><p>Now obviously we can take this far further, and there’s nothing to stop us from using POST endpoints on the API either, perhaps allowing users to register their domains.</p><h4>Conclusion</h4><p>Actions are an incredibly powerful way to add utility to ChatGPT and your own workflows. Integration could not be simpler, and the power is immense. The way that ChatGPT interprets results is nothing short of spectacular.</p><p>Can you think of other cool things to integrate with ChatGPT? Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65e95cd666db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>