- Java - 17
- Maven - 3.x.x >
1. Clone the application
git clone https://github.com/jrojas-t/demo-example-spring-boot-chatgpt.git
2. Configuration
open src/main/resources/application.yaml
, and change openai-service.api-key: YOUR_API_KEY
you need to generate an api key at (Generate API KEY)
3. Build and run the app using maven
Finally, You can run the app by typing the following command from the root directory of the project -
mvn spring-boot:run
curl --location 'http://localhost:8080/api/v1/chat' \
--header 'Content-Type: application/json' \
--data '{"question":"¿Quien pinto la mona lisa?"}'
'
# Output
{
"id": "chatcmpl-7GVV9uhSU82zoOr2GCWrIlb5dWaWZ",
"object": "chat.completion",
"model": "gpt-3.5-turbo-0301",
"created": "+4613067-04-10",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "La Mona Lisa fue pintada por el famoso artista italiano Leonardo da Vinci en el siglo XVI."
}
}
],
"usage": {
"prompt_tokens": "19",
"completion_tokens": "22",
"total_tokens": "41"
}
}