Code Monkey home page Code Monkey logo

ai-openai-helloworld's Introduction

Simple Spring AI

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.

Prerequisite

Before using the AI commands, make sure you have a developer token from OpenAI.

Create an account at OpenAI Signup and generate the token at 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.

export SPRING_AI_OPENAI_API_KEY=<INSERT KEY HERE>

Building and running

./mvnw spring-boot:run

Access the endpoint

To get a response to the default request of "Tell me a joke"

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

A sample response is

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

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 space?

Because it wanted to see the mooooon!

Alternatively use the httpie clinet

http 

ai-openai-helloworld's People

Contributors

markpollack avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.