Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.19 KB

1-README-tell-me-a-joke.md

File metadata and controls

53 lines (38 loc) · 1.19 KB

Spring AI - Hello World

The code for this example is in the package com.xkcd.ai.helloworld.

In that package there is a Spring REST Controller named SimpleAiController.

The SimpleAiController accepts HTTP GET requests at http://localhost:8080/ai/simple

There is optional message parameter whose default value is "Tell me a joke". pl The response to the request is from the Azure OpenAI Service.

Building and running

Run the project from your IDE or use the Maven command line

./mvnw spring-boot:run

Access the endpoint

To get a response to the default request of "Tell me a joke" using the http command line utility

http http://localhost:8080/ai/simple

or using curl

curl http://localhost:8080/ai/simple

A sample response is

Why don't scientists trust atoms?

Because they make up everything!

Now using the text request parameter:

http GET localhost:8080/ai/simple message=='Tell me a joke about a cow.' 

or using curl

curl --get  --data-urlencode 'message=Tell me a joke about a cow.' http://localhost:8080/ai/simple 

A sample response is

Why did the cow go to outer space? To see the moooon!