-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : adds observability * use different models
- Loading branch information
1 parent
a552403
commit 08be301
Showing
6 changed files
with
90 additions
and
34 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
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
31 changes: 2 additions & 29 deletions
31
...m/src/test/java/com/learning/ai/llmragwithspringai/TestLlmRagWithSpringAiApplication.java
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 |
---|---|---|
@@ -1,40 +1,13 @@ | ||
package com.learning.ai.llmragwithspringai; | ||
|
||
import static com.redis.testcontainers.RedisStackContainer.DEFAULT_IMAGE_NAME; | ||
import static com.redis.testcontainers.RedisStackContainer.DEFAULT_TAG; | ||
|
||
import com.redis.testcontainers.RedisStackContainer; | ||
import com.learning.ai.llmragwithspringai.config.TestcontainersConfiguration; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.testcontainers.ollama.OllamaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class TestLlmRagWithSpringAiApplication { | ||
|
||
@Bean | ||
@ServiceConnection | ||
OllamaContainer ollama(DynamicPropertyRegistry properties) { | ||
// The model name to use (e.g., "orca-mini", "mistral", "llama2", "codellama", "phi", or | ||
// "tinyllama") | ||
return new OllamaContainer( | ||
DockerImageName.parse("langchain4j/ollama-llama3:latest").asCompatibleSubstituteFor("ollama/ollama")); | ||
} | ||
|
||
@Bean | ||
RedisStackContainer redisContainer(DynamicPropertyRegistry properties) { | ||
RedisStackContainer redis = new RedisStackContainer(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG)); | ||
properties.add("spring.ai.vectorstore.redis.uri", () -> "redis://%s:%d" | ||
.formatted(redis.getHost(), redis.getMappedPort(6379))); | ||
return redis; | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(LlmRagWithSpringAiApplication::main) | ||
.with(TestLlmRagWithSpringAiApplication.class) | ||
.with(TestcontainersConfiguration.class) | ||
.run(args); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
.../src/test/java/com/learning/ai/llmragwithspringai/config/TestcontainersConfiguration.java
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,46 @@ | ||
package com.learning.ai.llmragwithspringai.config; | ||
|
||
import com.redis.testcontainers.RedisStackContainer; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.testcontainers.grafana.LgtmStackContainer; | ||
import org.testcontainers.ollama.OllamaContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class TestcontainersConfiguration { | ||
|
||
@Bean | ||
@ServiceConnection | ||
OllamaContainer ollama() throws IOException, InterruptedException { | ||
// The model name to use (e.g., "orca-mini", "mistral", "llama2", "codellama", "phi", or | ||
// "tinyllama") | ||
OllamaContainer ollamaContainer = new OllamaContainer( | ||
DockerImageName.parse("langchain4j/ollama-mistral:latest").asCompatibleSubstituteFor("ollama/ollama")); | ||
ollamaContainer.start(); | ||
ollamaContainer.execInContainer("ollama", "pull", "nomic-embed-text"); | ||
return ollamaContainer; | ||
} | ||
|
||
@Bean | ||
RedisStackContainer redisContainer(DynamicPropertyRegistry properties) { | ||
RedisStackContainer redis = new RedisStackContainer( | ||
RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(RedisStackContainer.DEFAULT_TAG)); | ||
properties.add("spring.ai.vectorstore.redis.uri", () -> "redis://%s:%d" | ||
.formatted(redis.getHost(), redis.getMappedPort(6379))); | ||
return redis; | ||
} | ||
|
||
@Bean | ||
@Scope("singleton") | ||
@ServiceConnection("otel/opentelemetry-collector-contrib") | ||
LgtmStackContainer lgtmStackContainer() { | ||
return new LgtmStackContainer(DockerImageName.parse("grafana/otel-lgtm").withTag("0.7.1")) | ||
.withStartupTimeout(Duration.ofMinutes(2)); | ||
} | ||
} |