Skip to content

Commit

Permalink
Push works
Browse files Browse the repository at this point in the history
  • Loading branch information
cheroliv committed Sep 25, 2024
1 parent d9c0ca0 commit 25772c9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 32 deletions.
47 changes: 20 additions & 27 deletions buildSrc/src/main/kotlin/school/ai/AssistantManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,31 @@ object AssistantManager {
| La spécialisation de ${System.getProperty("user.name")} est dans l'ingenieurie de pédagogie pour adulte,
| et le software craftmanship avec les méthodes agiles.
| $assistantName ta mission est d'aider ${System.getProperty("user.name")} dans l'activité d'écriture de formation et génération de code.
| Réponds moi à ce premier échange uniquement en maximum 200 mots"""
.trimMargin()
| Réponds moi à ce premier échange uniquement en maximum 120 mots""".trimMargin()

fun Project.createOllamaChatModel(): OllamaChatModel =
fun Project.createOllamaChatModel(model: String = "smollm:135m"): OllamaChatModel =
OllamaChatModel.builder().apply {
baseUrl(project.findProperty("ollama.baseUrl") as? String ?: "http://localhost:11434")
modelName(project.findProperty("ollama.modelName") as? String ?: "phi3.5")
temperature(project.findProperty("ollama.temperature") as? Double ?: 0.8)
timeout(Duration.ofSeconds(project.findProperty("ollama.timeout") as? Long ?: 6_000))
logRequests(true)
logResponses(true)
}.build()
baseUrl(project.findProperty("ollama.baseUrl") as? String ?: "http://localhost:11434")
modelName(project.findProperty("ollama.modelName") as? String ?: model)
temperature(project.findProperty("ollama.temperature") as? Double ?: 0.8)
timeout(Duration.ofSeconds(project.findProperty("ollama.timeout") as? Long ?: 6_000))
logRequests(true)
logResponses(true)
}.build()

fun Project.createOllamaStreamingChatModel(): OllamaStreamingChatModel =
OllamaStreamingChatModel
.builder()
.apply {
baseUrl(project.findProperty("ollama.baseUrl") as? String ?: "http://localhost:11434")
modelName(project.findProperty("ollama.modelName") as? String ?: "phi3.5")
temperature(project.findProperty("ollama.temperature") as? Double ?: 0.8)
timeout(Duration.ofSeconds(project.findProperty("ollama.timeout") as? Long ?: 6_000))
logRequests(true)
logResponses(true)
}.build()
fun Project.createOllamaStreamingChatModel(model: String = "smollm:135m"): OllamaStreamingChatModel =
OllamaStreamingChatModel.builder().apply {
baseUrl(project.findProperty("ollama.baseUrl") as? String ?: "http://localhost:11434")
modelName(project.findProperty("ollama.modelName") as? String ?: model)
temperature(project.findProperty("ollama.temperature") as? Double ?: 0.8)
timeout(Duration.ofSeconds(project.findProperty("ollama.timeout") as? Long ?: 6_000))
logRequests(true)
logResponses(true)
}.build()


suspend fun generateStreamingResponse(
model: StreamingChatLanguageModel,
promptMessage: String
model: StreamingChatLanguageModel, promptMessage: String
): Either<Throwable, Response<AiMessage>> = catch {
suspendCancellableCoroutine { continuation ->
model.generate(promptMessage, object : StreamingResponseHandler<AiMessage> {
Expand All @@ -79,9 +75,6 @@ object AssistantManager {

val Project.apiKey: String
get() = Properties().apply {
"$projectDir/private.properties"
.let(::File)
.inputStream()
.use(::load)
"$projectDir/private.properties".let(::File).inputStream().use(::load)
}["OPENAI_API_KEY"] as String
}
71 changes: 66 additions & 5 deletions buildSrc/src/main/kotlin/school/ai/AssistantPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,75 @@ class AssistantPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.run {
task("helloOllama") {
task("helloOllamaMistral") {
group = "school-ai"
description = "Display the ollama chatgpt prompt request."
doFirst { createOllamaChatModel().run { generate(userMessage).let(::println) } }
description = "Display the ollama mistral chatgpt prompt request."
doFirst {
createOllamaChatModel(model = "mistral")
.run { generate(userMessage).let(::println) }
}
}

task("helloOllamaStreamMistral") {
group = "school-ai"
description = "Display the ollama mistral chatgpt stream prompt request."
doFirst {
runBlocking {
createOllamaStreamingChatModel("mistral").run {
when (val answer = generateStreamingResponse(this, userMessage)) {
is Right ->
"Complete response received: \n${answer.value.content().text()}".run(::println)

is Left ->
"Error during response generation: \n${answer.value}".run(::println)
}
}
}
}
}




task("helloOllamaPhi") {
group = "school-ai"
description = "Display the ollama phi3.5 chatgpt prompt request."
doFirst {
createOllamaChatModel(model = "phi3.5")
.run { generate(userMessage).let(::println) }
}
}

task("helloOllamaStream") {
task("helloOllamaStreamPhi") {
group = "school-ai"
description = "Display the ollama chatgpt stream prompt request."
description = "Display the ollama phi3.5 chatgpt stream prompt request."
doFirst {
runBlocking {
createOllamaStreamingChatModel("phi3.5").run {
when (val answer = generateStreamingResponse(this, userMessage)) {
is Right ->
"Complete response received: \n${answer.value.content().text()}".run(::println)

is Left ->
"Error during response generation: \n${answer.value}".run(::println)
}
}
}
}
}

task("helloOllamaSmollM") {
group = "school-ai"
description = "Display the ollama mistral chatgpt prompt request."
doFirst {
createOllamaChatModel()
.run { generate(userMessage).let(::println) }
}
}

task("helloOllamaStreamSmollM") {
group = "school-ai"
description = "Display the ollama mistral chatgpt stream prompt request."
doFirst {
runBlocking {
createOllamaStreamingChatModel().run {
Expand All @@ -40,6 +100,7 @@ class AssistantPlugin : Plugin<Project> {
}
}


task("displayAIPrompt") {
group = "school-ai"
description = "Dislpay on console AI prompt assistant"
Expand Down

0 comments on commit 25772c9

Please sign in to comment.