-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8aa61e8
commit 0ff40fb
Showing
8 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>llm</artifactId> | ||
<version>0.4.2</version> | ||
</parent> | ||
|
||
<artifactId>llm-ollama</artifactId> | ||
<name>LLM Adapter :: Ollama</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.ai</groupId> | ||
<artifactId>spring-ai-ollama</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
llm/ollama/src/main/kotlin/io/github/llmagentbuilder/llm/ollama/OllamaChatModelProvider.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.llmagentbuilder.llm.ollama | ||
|
||
import io.github.llmagentbuilder.core.ChatModelProvider | ||
import io.github.llmagentbuilder.core.MapToObject | ||
import org.springframework.ai.chat.model.ChatModel | ||
import org.springframework.ai.model.function.FunctionCallbackResolver | ||
import org.springframework.ai.ollama.OllamaChatModel | ||
import org.springframework.ai.ollama.api.OllamaApi | ||
import org.springframework.ai.ollama.api.OllamaModel | ||
import org.springframework.ai.ollama.api.OllamaOptions | ||
|
||
class OllamaChatModelProvider : ChatModelProvider { | ||
override fun configKey(): String { | ||
return "ollama" | ||
} | ||
|
||
override fun provideChatModel( | ||
functionCallbackResolver: FunctionCallbackResolver, | ||
config: Map<String, Any?>? | ||
): ChatModel? { | ||
val ollamaConfig = MapToObject.toObject<OllamaConfig>(config) | ||
if (ollamaConfig?.enabled == false) { | ||
return null | ||
} | ||
val model = ollamaConfig?.model ?: OllamaModel.PHI3.id() | ||
return OllamaChatModel.builder() | ||
.ollamaApi(OllamaApi()) | ||
.defaultOptions(OllamaOptions.builder().model(model).build()) | ||
.functionCallbackResolver(functionCallbackResolver) | ||
.build() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...llama/src/main/kotlin/io/github/llmagentbuilder/llm/ollama/OllamaChatOptionsConfigurer.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.llmagentbuilder.llm.ollama | ||
|
||
import io.github.llmagentbuilder.core.ChatOptionsConfigurer | ||
import org.springframework.ai.chat.prompt.ChatOptions | ||
import org.springframework.ai.ollama.api.OllamaOptions | ||
|
||
class OllamaChatOptionsConfigurer : ChatOptionsConfigurer { | ||
override fun supports(chatOptions: ChatOptions?): Boolean { | ||
return chatOptions is OllamaOptions | ||
} | ||
|
||
override fun configure( | ||
chatOptions: ChatOptions?, | ||
config: ChatOptionsConfigurer.ChatOptionsConfig | ||
): ChatOptions { | ||
val stops = config.stopSequence ?: listOf() | ||
return chatOptions?.let { | ||
val options = OllamaOptions.fromOptions(it as OllamaOptions) | ||
options.stop = ((options.stopSequences ?: listOf()) + stops) | ||
return options | ||
} ?: OllamaOptions.builder().stop(stops).build() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
llm/ollama/src/main/kotlin/io/github/llmagentbuilder/llm/ollama/OllamaConfig.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.github.llmagentbuilder.llm.ollama | ||
|
||
data class OllamaConfig( | ||
val enabled: Boolean? = true, | ||
val model: String? = null, | ||
) |
1 change: 1 addition & 0 deletions
1
...ama/src/main/resources/META-INF/services/io.github.llmagentbuilder.core.ChatModelProvider
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.github.llmagentbuilder.llm.ollama.OllamaChatModelProvider |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/io.github.llmagentbuilder.core.ChatOptionsConfigurer
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.github.llmagentbuilder.llm.ollama.OllamaChatOptionsConfigurer |
This file contains 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