Friday, March 24, 2023

#958 - Invoking ChatGPT from OIC

 


I had to try this out, first step was to create an account - 








Once in, I can try it out - Who was Mikhail Bakunin anyway?















Now how can I do something like this via the api?

Next step - get an api key - 



I already have one - but you get the idea - 



Copy the key for later use.

On to the api docs - 



On to Postman, to check out which models are available - 



I set Authorization at the Collection level - 




This is the one I will use - gpt-3.5-turbo.



This is the api I will call - I'm going to ask for book suggestions for a particular subject area eg. politics.

This brings us to roles - as they will be used in the request body. 

We have the following - system - describes the assistant. I will set this to - You are Niall. you are a well read person with great book suggestions. When answering try to be funny.

Then we have user, the user is going to be asking something.  

Here is the Postman request body - 

{
    "model""gpt-3.5-turbo",
    "messages": [
        {
            "role""system",
            "content""You are Niall. You are a well read person with great book suggestions. When answering try to be funny"
        },
        {
            "role""user",
            "content""I'm looking for books on Politics. What can you suggest?"
        }
    ]
}

Let's execute the request in Postman - 



The full content - "Well, if you're looking for a good laugh, you could always try reading the political news these days. But if you want something more informative, I highly recommend \"The Dictator's Handbook\" by Bruce Bueno de Mesquita and Alastair Smith. It's a great book that breaks down the motivations of political leaders and helps explain why they do the things they do. Plus, it's a lot less depressing than watching cable news all day."

Well I did ask it to be funny!

Now to implementing this in OIC - just a couple of steps - 

Step 1 - Create the connection 



Step 2 - Create a Lookup Table 

Just to make it flexible - 


Step 3 - Create the Integration 
























The Invoke is configured as follows - 


I use the request and response payloads from Postman - I then attend to the mapping - 



Activate and test - 
























The usual suspects - Tolstoy, Dostoyevsky and Gogol. no mention of Ivan Goncharov and his classic, Oblomov, or even Alexander Herzen; but that's it, you should have asked me and not ChatGPT.

My next post will cover more sober business applications of such.
 


 


No comments:

Post a Comment