Kotlin examples update (#5)
* Update kotlin-function-callback Leverage Spring AI 1.0.0-M5 new Kotlin reflection capabilities. * Fix rag-with-kotlin Leverage Spring AI 1.0.0-M5 new Kotlin reflection capabilities.
This commit is contained in:
committed by
GitHub
parent
4ddd9135f0
commit
7f8bfbcecb
@@ -12,13 +12,6 @@ import org.springframework.context.annotation.Description
|
||||
@SpringBootApplication
|
||||
class KotlinFunctionCallbackApplication {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<KotlinFunctionCallbackApplication>(*args)
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun init(chatClientBuilder: ChatClient.Builder) = CommandLineRunner {
|
||||
try {
|
||||
@@ -38,6 +31,7 @@ class KotlinFunctionCallbackApplication {
|
||||
|
||||
@Configuration
|
||||
class Config {
|
||||
|
||||
@Bean
|
||||
fun weatherFunctionInfo(currentWeather: (WeatherRequest) -> WeatherResponse): FunctionCallback {
|
||||
return FunctionCallback.builder()
|
||||
@@ -55,3 +49,7 @@ class Config {
|
||||
MockKotlinWeatherService().invoke(request)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<KotlinFunctionCallbackApplication>(*args)
|
||||
}
|
||||
|
||||
@@ -45,21 +45,17 @@ enum class Unit(val unitName: String) {
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonClassDescription("Weather API request")
|
||||
data class WeatherRequest(
|
||||
@get:JsonProperty(required = true, value = "location")
|
||||
@get:JsonPropertyDescription("The city and state e.g. San Francisco, CA")
|
||||
val location: String = "",
|
||||
val location: String,
|
||||
|
||||
@get:JsonProperty(required = true, value = "lat")
|
||||
@get:JsonPropertyDescription("The city latitude")
|
||||
val lat: Double = 0.0,
|
||||
val lat: Double,
|
||||
|
||||
@get:JsonProperty(required = true, value = "lon")
|
||||
@get:JsonPropertyDescription("The city longitude")
|
||||
val lon: Double = 0.0,
|
||||
val lon: Double,
|
||||
|
||||
@get:JsonProperty(required = true, value = "unit")
|
||||
@get:JsonPropertyDescription("Temperature unit")
|
||||
val unit: Unit = Unit.C
|
||||
val unit: Unit
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.0-SNAPSHOT</version>
|
||||
<version>3.3.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
@@ -133,15 +133,33 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.example.rag_with_kotlin
|
||||
|
||||
import org.springframework.ai.chat.client.ChatClient
|
||||
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor
|
||||
import org.springframework.ai.chat.client.entity
|
||||
import org.springframework.ai.document.Document
|
||||
import org.springframework.ai.vectorstore.VectorStore
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
@@ -49,13 +50,12 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
bean {
|
||||
val cc = ref<ChatClient>()
|
||||
val dogAdoptionSuggestion = cc
|
||||
cc
|
||||
.prompt(" do you have any neurotic dogs? ")
|
||||
.call()
|
||||
.entity<DogAdoptionSuggestion>()
|
||||
println(dogAdoptionSuggestion)
|
||||
|
||||
|
||||
.entity<DogAdoptionSuggestion>().also {
|
||||
print(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
addInitializers(context)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
delete from dog;
|
||||
delete from vector_store ;
|
||||
|
||||
INSERT INTO dog (id, name, description, dob, owner, gender, image) VALUES
|
||||
(97, 'Rocky', 'A brown Chihuahua known for being protective.', '2019-01-28', NULL, 'm', 'https://raw.githubusercontent.com/joshlong-attic/dog-images/main/chihuahua-1.png');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user