# ai-openai-helloworld **Repository Path**: HesenjanJava/ai-openai-helloworld ## Basic Information - **Project Name**: ai-openai-helloworld - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-12 - **Last Updated**: 2024-04-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Spring AI with OpenAI This project contains a web service that will accept HTTP GET requests at `http://localhost:8080/ai/simple`. There is optional `message` parameter whose default value is "Tell me a joke". The response to the request is from the OpenAI ChatGPT Service. ## Prerequisites Before using the AI commands, make sure you have a developer token from OpenAI. Create an account at [OpenAI Signup](https://platform.openai.com/signup) and generate the token at [API Keys](https://platform.openai.com/account/api-keys). The Spring AI project defines a configuration property named `spring.ai.openai.api-key` that you should set to the value of the `API Key` obtained from `openai.com`. Exporting an environment variable is one way to set that configuration property. ```shell export SPRING_AI_OPENAI_API_KEY= ``` Setting the API key is all you need to run the application. However, you can find more information on setting started in the [Spring AI reference documentation section on OpenAI Chat](https://docs.spring.io/spring-ai/reference/api/clients/openai-chat.html). ## Building and running ``` ./mvnw spring-boot:run ``` ## Access the endpoint To get a response to the default request of "Tell me a joke" ```shell curl localhost:8080/ai/simple ``` A sample response is ```text Sure, here's a classic one for you: Why don't scientists trust atoms? Because they make up everything! ``` Now using the `message` request parameter ```shell curl --get --data-urlencode 'message=Tell me a joke about a cow.' localhost:8080/ai/simple ``` A sample response is ```text Why did the cow go to space? Because it wanted to see the mooooon! ``` Alternatively use the [httpie](https://httpie.io/) client ```shell http localhost:8080/ai/simple message=='Tell me a joke about a cow.' ```