ChatGPT API Integration
Summary:
Posting a small groovy snippet to allow chatGPT API integration.
This is meant as a bit of fun with no practical applications at the moment.
You will need to generate an API Key here: https://platform.openai.com/overview and replace it in the code below as bearerToken
Code Snippet (add any code snippets that support your topic, if applicable):
String ChatGPT_API(String Prompt){ def bearerToken ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" def json = JsonOutput.toJson([model: 'gpt-3.5-turbo', messages: [[ role: 'user', content:Prompt ]]]) Connection ChatGPTconnection = connection("https://api.openai.com/v1/chat/completions", "user", "password") HttpResponse<String> jsonResponse = ChatGPTconnection.post() .header("Content-Type", 'application/json') //.header=headers .header("Authorization", 'Bearer '+bearerToken) .body(json)
Tagged:
2