Skip to content

Commit

Permalink
feat : adds observability (#83)
Browse files Browse the repository at this point in the history
* feat : adds observability

* use different models
  • Loading branch information
rajadilipkolli authored Aug 12, 2024
1 parent a552403 commit 08be301
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 34 deletions.
12 changes: 11 additions & 1 deletion rag/rag-springai-ollama-llm/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ services:
redis-stack:
image: redis/redis-stack-server
ports:
- '6379:6379'
- '6379:6379'
lgtm-stack:
image: grafana/otel-lgtm:0.7.1
extra_hosts: ['host.docker.internal:host-gateway']
container_name: lgtm-stack
environment:
- OTEL_METRIC_EXPORT_INTERVAL=500
ports:
- "3000:3000"
- "4317:4317"
- "4318:4318"
19 changes: 19 additions & 0 deletions rag/rag-springai-ollama-llm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-otlp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -87,8 +99,15 @@
<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis</artifactId>
<scope>test</scope>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>grafana</artifactId>
<scope>test</scope>
<version>1.20.1</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ spring.application.name=rag-springai-ollama-llm
spring.threads.virtual.enabled=true
spring.mvc.problemdetails.enabled=true

spring.ai.ollama.chat.options.model=llama3
spring.ai.ollama.chat.options.model=mistral
spring.ai.ollama.chat.options.temperature=0.3
spring.ai.ollama.chat.options.top-k=2
spring.ai.ollama.chat.options.top-p=0.2

spring.ai.ollama.embedding.options.model=llama3
spring.ai.ollama.embedding.options.model=nomic-embed-text

spring.ai.vectorstore.redis.index=vector_store
spring.ai.vectorstore.redis.prefix=ai
Expand All @@ -17,3 +17,12 @@ spring.ai.vectorstore.redis.initializeSchema=true
spring.ai.ollama.baseUrl=http://localhost:11434

spring.testcontainers.beans.startup=parallel

##Observability
spring.ai.chat.observations.include-completion=true
spring.ai.chat.observations.include-prompt=true

management.endpoints.web.exposure.include=*
management.metrics.tags.service.name=${spring.application.name}
management.tracing.sampling.probability=1.0
management.otlp.tracing.endpoint=http://localhost:4318/v1/traces
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.ai.llmragwithspringai.TestLlmRagWithSpringAiApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {TestLlmRagWithSpringAiApplication.class})
classes = {TestcontainersConfiguration.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

Expand Down
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));
}
}

0 comments on commit 08be301

Please sign in to comment.