Skip to content

Commit 2517273

Browse files
authored
Local model (#68)
* Add Ollama Starter. Make OpenAi and Anthropic models optional * Examples are now responsible for detecting ConfigurationProperties * Cloud models are now optional
1 parent ade47b1 commit 2517273

File tree

9 files changed

+95
-27
lines changed

9 files changed

+95
-27
lines changed

examples-java/pom.xml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@
2424
<version>${project.version}</version>
2525
</dependency>
2626

27+
<!-- Ollama is always included as an option for local model hosting -->
2728
<dependency>
2829
<groupId>com.embabel.agent</groupId>
29-
<artifactId>embabel-agent-starter-openai</artifactId>
30-
</dependency>
31-
32-
<dependency>
33-
<groupId>com.embabel.agent</groupId>
34-
<artifactId>embabel-agent-starter-anthropic</artifactId>
30+
<artifactId>embabel-agent-starter-ollama</artifactId>
3531
</dependency>
3632

3733
<dependency>
@@ -60,6 +56,34 @@
6056
</build>
6157

6258
<profiles>
59+
<profile>
60+
<id>openai-models</id>
61+
<activation>
62+
<property>
63+
<name>env.OPENAI_API_KEY</name>
64+
</property>
65+
</activation>
66+
<dependencies>
67+
<dependency>
68+
<groupId>com.embabel.agent</groupId>
69+
<artifactId>embabel-agent-starter-openai</artifactId>
70+
</dependency>
71+
</dependencies>
72+
</profile>
73+
<profile>
74+
<id>anthropic-models</id>
75+
<activation>
76+
<property>
77+
<name>env.ANTHROPIC_API_KEY</name>
78+
</property>
79+
</activation>
80+
<dependencies>
81+
<dependency>
82+
<groupId>com.embabel.agent</groupId>
83+
<artifactId>embabel-agent-starter-anthropic</artifactId>
84+
</dependency>
85+
</dependencies>
86+
</profile>
6387
<profile>
6488
<id>enable-shell</id>
6589
<activation>

examples-java/src/main/java/com/embabel/example/JavaAgentShellApplication.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.embabel.agent.config.annotation.McpServers;
2121
import org.springframework.boot.SpringApplication;
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
23-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
23+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
2424

2525

2626
/**
@@ -36,7 +36,11 @@
3636
* @since 1.0
3737
*/
3838
@SpringBootApplication
39-
@EnableConfigurationProperties
39+
@ConfigurationPropertiesScan(
40+
basePackages = {
41+
"com.embabel.example"
42+
}
43+
)
4044
@EnableAgents(
4145
loggingTheme = LoggingThemes.SEVERANCE,
4246
mcpServers = {McpServers.DOCKER_DESKTOP}

examples-java/src/main/java/com/embabel/example/JavaAgentShellMcpClientApplication.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.embabel.agent.config.annotation.McpServers;
2121
import org.springframework.boot.SpringApplication;
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
23-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
23+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
2424

2525
/**
2626
* Spring Boot application that provides an interactive command-line shell for Embabel agents
@@ -35,7 +35,11 @@
3535
* @since 1.0
3636
*/
3737
@SpringBootApplication
38-
@EnableConfigurationProperties
38+
@ConfigurationPropertiesScan(
39+
basePackages = {
40+
"com.embabel.example"
41+
}
42+
)
3943
@EnableAgents(
4044
loggingTheme = LoggingThemes.STAR_WARS,
4145
mcpServers = {McpServers.DOCKER_DESKTOP}

examples-java/src/main/java/com/embabel/example/JavaMcpServerApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.embabel.agent.config.annotation.McpServers;
2020
import org.springframework.boot.SpringApplication;
2121
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
2223

2324
/**
2425
* Spring Boot application that runs Embabel agents as an MCP (Model Context Protocol) server.
@@ -32,6 +33,11 @@
3233
* @since 1.0
3334
*/
3435
@SpringBootApplication
36+
@ConfigurationPropertiesScan(
37+
basePackages = {
38+
"com.embabel.example"
39+
}
40+
)
3541
@EnableAgents(
3642
mcpServers = {McpServers.DOCKER_DESKTOP}
3743
)

examples-kotlin/pom.xml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@
1313

1414
<dependencies>
1515

16-
1716
<dependency>
1817
<groupId>com.embabel.example</groupId>
1918
<artifactId>examples-common</artifactId>
2019
<version>${project.version}</version>
2120
</dependency>
2221

22+
<!-- Ollama is always included as an option for local model hosting -->
2323
<dependency>
2424
<groupId>com.embabel.agent</groupId>
25-
<artifactId>embabel-agent-starter-openai</artifactId>
26-
</dependency>
27-
28-
<dependency>
29-
<groupId>com.embabel.agent</groupId>
30-
<artifactId>embabel-agent-starter-anthropic</artifactId>
25+
<artifactId>embabel-agent-starter-ollama</artifactId>
3126
</dependency>
3227

3328
<dependency>
@@ -61,6 +56,34 @@
6156
</build>
6257

6358
<profiles>
59+
<profile>
60+
<id>openai-models</id>
61+
<activation>
62+
<property>
63+
<name>env.OPENAI_API_KEY</name>
64+
</property>
65+
</activation>
66+
<dependencies>
67+
<dependency>
68+
<groupId>com.embabel.agent</groupId>
69+
<artifactId>embabel-agent-starter-openai</artifactId>
70+
</dependency>
71+
</dependencies>
72+
</profile>
73+
<profile>
74+
<id>anthropic-models</id>
75+
<activation>
76+
<property>
77+
<name>env.ANTHROPIC_API_KEY</name>
78+
</property>
79+
</activation>
80+
<dependencies>
81+
<dependency>
82+
<groupId>com.embabel.agent</groupId>
83+
<artifactId>embabel-agent-starter-anthropic</artifactId>
84+
</dependency>
85+
</dependencies>
86+
</profile>
6487
<profile>
6588
<id>enable-shell</id>
6689
<activation>

examples-kotlin/src/main/kotlin/com/embabel/example/KotlinAgentMcpServerApplication.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.embabel.example
1818
import com.embabel.agent.config.annotation.EnableAgents
1919
import com.embabel.agent.config.annotation.McpServers
2020
import org.springframework.boot.autoconfigure.SpringBootApplication
21+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
2122
import org.springframework.boot.runApplication
2223

2324
/**
@@ -29,10 +30,13 @@ import org.springframework.boot.runApplication
2930
*
3031
*/
3132
@SpringBootApplication
33+
@ConfigurationPropertiesScan(
34+
basePackages = ["com.embabel.example"]
35+
)
3236
@EnableAgents(
3337
mcpServers = [McpServers.DOCKER_DESKTOP, McpServers.DOCKER],
3438
)
35-
class JavaAgentMcpServerApplication
39+
class KotlinAgentMcpServerApplication
3640

3741
/**
3842
* Application entry point that starts the MCP server.
@@ -43,5 +47,5 @@ class JavaAgentMcpServerApplication
4347
* @param args Command line arguments passed to the application
4448
*/
4549
fun main(args: Array<String>) {
46-
runApplication<JavaAgentMcpServerApplication>(*args)
50+
runApplication<KotlinAgentMcpServerApplication>(*args)
4751
}

examples-kotlin/src/main/kotlin/com/embabel/example/KotlinAgentShellApplication.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.embabel.agent.config.annotation.EnableAgents
1919
import com.embabel.agent.config.annotation.LoggingThemes
2020
import com.embabel.agent.config.annotation.McpServers
2121
import org.springframework.boot.autoconfigure.SpringBootApplication
22+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
2223
import org.springframework.boot.runApplication
2324

2425
/**
@@ -38,6 +39,9 @@ import org.springframework.boot.runApplication
3839
* @see EnableAgents
3940
*/
4041
@SpringBootApplication
42+
@ConfigurationPropertiesScan(
43+
basePackages = ["com.embabel.example"]
44+
)
4145
@EnableAgents(
4246
loggingTheme = LoggingThemes.STAR_WARS,
4347
mcpServers = [McpServers.DOCKER, McpServers.DOCKER_DESKTOP],

examples-kotlin/src/main/kotlin/com/embabel/example/KotlinAgentShellMcpClientApplication.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.embabel.agent.config.annotation.EnableAgents
1919
import com.embabel.agent.config.annotation.LoggingThemes
2020
import com.embabel.agent.config.annotation.McpServers
2121
import org.springframework.boot.autoconfigure.SpringBootApplication
22+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
2223
import org.springframework.boot.runApplication
2324

2425
/**
@@ -38,6 +39,9 @@ import org.springframework.boot.runApplication
3839
* @see EnableAgents
3940
*/
4041
@SpringBootApplication
42+
@ConfigurationPropertiesScan(
43+
basePackages = ["com.embabel.example"]
44+
)
4145
@EnableAgents(
4246
loggingTheme = LoggingThemes.SEVERANCE,
4347
mcpServers = [McpServers.DOCKER_DESKTOP, McpServers.DOCKER],

scripts/support/check_env.bat

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ set ANTHROPIC_KEY_MISSING=false
77
if "%OPENAI_API_KEY%"=="" (
88
echo OPENAI_API_KEY environment variable is not set
99
echo OpenAI models will not be available
10-
echo Get an API key at https://platform.openai.com/api-keys
11-
echo Please set it with: set OPENAI_API_KEY=your_api_key
1210
set OPENAI_KEY_MISSING=true
1311
) else (
1412
echo OPENAI_API_KEY set: OpenAI models are available
@@ -17,16 +15,13 @@ if "%OPENAI_API_KEY%"=="" (
1715
if "%ANTHROPIC_API_KEY%"=="" (
1816
echo ANTHROPIC_API_KEY environment variable is not set
1917
echo Claude models will not be available
20-
echo Get an API key at https://www.anthropic.com/api
21-
echo Please set it with: set ANTHROPIC_API_KEY=your_api_key
2218
set ANTHROPIC_KEY_MISSING=true
2319
) else (
2420
echo ANTHROPIC_API_KEY set: Claude models are available
2521
)
2622

2723
if "%OPENAI_KEY_MISSING%"=="true" if "%ANTHROPIC_KEY_MISSING%"=="true" (
28-
echo ERROR: Both OPENAI_API_KEY and ANTHROPIC_API_KEY are missing.
29-
echo At least one API key is required to use language models.
30-
echo Please set at least one of these keys before running the application.
31-
exit /b 1
24+
echo Ollama models will be used if available
25+
echo Please check Ollama installation and set default model in application.properties
26+
echo For example: embabel.models.default-llm=llama3.1:8b
3227
)

0 commit comments

Comments
 (0)