Last active
October 31, 2024 10:37
-
-
Save ThomasVitale/6a4e468636a5a15ff8fbe5966a63761a to your computer and use it in GitHub Desktop.
Java 23 + Spring AI Ollama + JBang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env jbang "$0" "$@" ; exit $? | |
//JAVA 23 | |
//PREVIEW | |
//REPOS mavencentral,https://repo.spring.io/milestone | |
//DEPS org.springframework.boot:spring-boot-starter:3.3.5 | |
//DEPS org.springframework.ai:spring-ai-ollama-spring-boot-starter:1.0.0-M3 | |
//JAVA_OPTIONS -Dspring.main.web-application-type=none | |
//JAVA_OPTIONS -Dspring.ai.ollama.init.pull-model-strategy=always | |
//JAVA_OPTIONS -Dspring.ai.ollama.chat.options.model=llama3.2:1b | |
package com.thomasvitale.ai; | |
import org.springframework.ai.chat.client.ChatClient; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.annotation.Bean; | |
@SpringBootApplication | |
public class Application { | |
void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@Bean | |
CommandLineRunner chatClient(ChatClient.Builder chatClientBuilder) { | |
return _ -> { | |
var response = chatClientBuilder.build() | |
.prompt("What is the capital of Denmark?") | |
.call() | |
.content(); | |
System.out.println(response); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pre-requisites: Ollama is up and running.
Run with JBang: