How to work with the OpenAI API with the help of ChatGTP

Home Forums Let’s get technical How to work with the OpenAI API with the help of ChatGTP

Tagged: , , ,

  • Creator
    Discussion
  • #1748

    csautot
    Participant

    I was curious about the OpenAI API. So I asked ChatGPT (https://chat.openai.com/chat) to provide some example code of how to use it for a use case where end-users could ask for certain e-commerce store data using natural language sentences (like “What is the total sales for the product with ID 1234 in the store orders table?“). My personal account is not yet GPT-4, so approach and results might be different in using GPT-4. For example, I think the Davinci Codex has been deprecated with GPT-4 and so it wouldn’t be used. Here are the prompts I gave to ChatGPT if you want to try them yourself to see what it came up with:

    Please provide me with some example PHP code that calls the OpenAI API. The way that a user interacts is that they provide a prompt and then the ChatGPT API should return a SQL query based on what data the user is seeking. The SQL query should use a MySQL table called store_orders that has the columns of id, product_id, sale_total, number_of_items, created, modified. The PHP code should then use the generated SQL query returned from the OpenAI API call to query a MySQL database called woo_store. With the data returned from the query, reformat it as JSON and echo it.

    Can you please explain why the davinci-codex is used?

    What would be an example SQL query returned by the call to the OpenAI API?

    Can you provide me a link to the documentation on the API parameters that I can use with davinci-codex?

    Inspiration for this use case came for this from seeing Hubspot’s co-founder/CTO (https://twitter.com/dharmesh) launch his own night/weekend side project that gives a more “human”/user-friendly interface to Hubspot: https://chatspot.ai/

    Might be something we could think about as a use case to make it easier for our users to more easily find the data/reporting they are seeking.

    Anyone have a different approach that you would take, have any examples of using the OpenAI API or another model? Would be interested to get your thoughts on this.

Log in to reply.