close
close

Tutorial: So get Spring AI

Tutorial: So get Spring AI

// src/main/resources/application.resources
spring.ai.azure.openai.chat.options.deployment-name=gpt-35-turbo-16k

It is a property with value gpt-turbo-16k. Der spring.ai.azure.openai.chat.options.deployment-name It is important that the automatic configuration works with a Spring-Bean configuration program, through which the Grundlage a ChatClient is installed. Follow the Abhängigkeit pom.xml stellt diesen Customer says:


  org.springframework.ai
  spring-ai-azure-openai-spring-boot-starter

If Spring starts working on a project with a ChatClient, now that it is owned, a ChatClient is a spoiling of naming conventions in openai-Starter project for couples. I follow helloworld-Beispiel wird dieser ChatClient vom Controller aufgeufen:

package com.xkcd.ai.helloworld;

import org.springframework.ai.chat.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class SimpleAiController {

	private final ChatClient chatClient;

	@Autowired
	public SimpleAiController(ChatClient chatClient) {
		this.chatClient = chatClient;
	}

	@GetMapping("/ai/simple")
	public MapString,  generation(
			@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
		return Map.of("generation", chatClient.call(message));
	}

}

Here you are dealing with a typical Spring REST Controller, here chatClient-Member if @Autowired and a method is connected. This ChatClient is then used, the requests are below /ai/simple so bearbites. The endpoint method returns a map with a “generation” key, the return value of chatClient.call(message) entspricht.

Exit all features, use an API interface for Azure. Dieser wird as Omgebungsvariable festgelegt:

export SPRING_AI_AZURE_OPENAI_API_KEY=

The answer to the question is:

export SPRING_AI_AZURE_OPENAI_ENDPOINT=

If all the elements occur, you can complete your project with $ maven spring-boot:run ausführen. Uber localhost:8080/ai/simple sollten Sie nun een KI-generierten Witz abrufen können.

Other images in the Azure Repository demonstration, which may show the background of a similar feature. You can find an example of a prompt template on the Beispiel app:

// src/main/resources/prompts/joke-prompt.st
Tell me a {adjective} joke about {topic}

The controller is used as follows:

@Value("classpath:/prompts/joke-prompt.st")
	private Resource jokeResource;

I am still able to view the following information:

PromptTemplate promptTemplate = new PromptTemplate(jokeResource);

(FM)

Is there another interesting question about different themes from the IT-Welt lesson? Unsere kostenlosen newsletter If you want to know everything, it was cleared by IT professionals – directly in your inbox!