You can connect to the OpenAI GPT-3 API including the chat models using the OpenAI API. Here is an example using Ruby:
Firstly, you need to install the required gem by running:
```
gem install openai
```
Then you can use below sample code to use Chat GPT:
```
require ‘openai’
Openai.api_key = ‘your-openai-key’
response = Openai::ChatCompletion.create(
model: “gpt-3.5-turbo”,
messages: [
{ role: “system”, content: “You are a helpful assistant.” },
{ role: “user”, content: “Who won the world series in 2020?” }
]
)
puts response.choices0.message[‘content’]
```
First, the ‘openai’ gem is required. Next, the ‘openai’ gem uses your API key to connect to the OpenAI API.
Then, we create a ChatCompletion using the create method.
However, note that the chat versions of the models take a slightly different set of parameters. In this case, the API needs to be fed an array of message objects, which can be of role ‘system’, ‘user’, or ‘assistant’. You can include as many messages as you would like, but one session of chat should be done under one API call, as the state of the conversation will not be saved across different calls also it won’t remember past requests.
Finally, the API response is printed to the console.
Don’t forget to replace ‘your-openai-key’ with your actual OpenAI key.