Skip to content

Commit

Permalink
Merge pull request #174 from dRAGon-Okinawa/staging
Browse files Browse the repository at this point in the history
Enhance CI/CD Workflow and Testing Suite with Environment Variables and Upgrades
  • Loading branch information
amengus87 authored Jul 25, 2024
2 parents b51b081 + 934729b commit 93fb73e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
packages: write
attestations: write
id-token: write
env:
DRAGON_CICD: true
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=dRAGon-Okinawa_dRAGon&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=dRAGon-Okinawa_dRAGon)
[![codecov](https://codecov.io/gh/dRAGon-Okinawa/dRAGon/graph/badge.svg?token=VTTK5JXXTU)](https://codecov.io/gh/dRAGon-Okinawa/dRAGon)

# dRAGon
> Dynamic Retrieval Augmented Generation for Optimized Nimble
# dRAGon - Dynamic Retrieval Augmented Generation for Optimized Nimble
dRAGon is a multi-modal RAG engine which can search over multiple kind of documents to generate good quality answers for LLMs.

[Your journey to the dRAGon starts > here <](https://dragon.okinawa)
[Your journey to the dRAGon starts > here <](https://docs.dragon.okinawa)

![dRAGon](https://raw.githubusercontent.com/dragon-okinawa/dragon/main/static/img/dragon_okinawa.jpg)

Expand Down
16 changes: 7 additions & 9 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'

implementation 'dev.langchain4j:langchain4j-open-ai:0.32.0'
implementation 'dev.langchain4j:langchain4j:0.32.0'
implementation 'dev.langchain4j:langchain4j-core:0.32.0'
implementation 'dev.langchain4j:langchain4j-embeddings:0.32.0'
implementation 'dev.langchain4j:langchain4j-pgvector:0.32.0'
implementation 'dev.langchain4j:langchain4j-open-ai:0.32.0'
implementation 'dev.langchain4j:langchain4j-easy-rag:0.32.0'
implementation 'dev.langchain4j:langchain4j:0.33.0'
implementation 'dev.langchain4j:langchain4j-core:0.33.0'
implementation 'dev.langchain4j:langchain4j-embeddings:0.33.0'
implementation 'dev.langchain4j:langchain4j-pgvector:0.33.0'
implementation 'dev.langchain4j:langchain4j-easy-rag:0.33.0'
implementation 'dev.langchain4j:langchain4j-open-ai:0.33.0'
implementation 'dev.langchain4j:langchain4j-mistral-ai:0.33.0'

implementation platform('org.dizitart:nitrite-bom:4.3.0')
implementation 'org.dizitart:nitrite'
Expand All @@ -51,8 +51,6 @@ dependencies {
testImplementation 'org.awaitility:awaitility:4.2.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.github.lambdua:client:0.20.9'
testImplementation 'io.github.lambdua:service:0.21.2'

compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

import ai.dragon.job.silo.ingestor.dto.embedding.EmbeddingModelDefinition;
import dev.langchain4j.model.embedding.bge.small.en.v15.BgeSmallEnV15QuantizedEmbeddingModel;
import dev.langchain4j.model.embedding.onnx.bgesmallenv15q.BgeSmallEnV15QuantizedEmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModelName;

Expand Down Expand Up @@ -40,7 +40,7 @@ public EmbeddingModelDefinition getModelDefinition() throws ClassNotFoundExcepti
.builder()
.languages(List.of("en"))
.embeddingModelClassName(
"dev.langchain4j.model.embedding.bge.small.en.v15.BgeSmallEnV15QuantizedEmbeddingModel")
"dev.langchain4j.model.embedding.onnx.bgesmallenv15q.BgeSmallEnV15QuantizedEmbeddingModel")
.embeddingModelName("BgeSmallEnV15QuantizedEmbeddingModel")
.embeddingModelWithSettings(parameters -> {
// TODO : Ability to specify a different Thread Pool Size :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public List<Document> listIngestorDocuments() throws Exception {
}

public void checkIngestorLoaderSettings() throws Exception {
throw new UnsupportedOperationException("checkIngestorLoaderSettings method is not implemented.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void onEvent(CollectionEventInfo<?> collectionEventInfo) {
}

public void onChangeEvent(CollectionEventInfo<?> collectionEventInfo, T entity) {
throw new UnsupportedOperationException("onChangeEvent method is not implemented.");
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public void run(String... args) throws Exception {
return;
case Error:
System.exit(1);
return;
case Executed:
System.exit(0);
return;
}
}

Expand Down
8 changes: 8 additions & 0 deletions backend/src/test/java/ai/dragon/DragonApplicationTests.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package ai.dragon;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
class DragonApplicationTests {
@Autowired
private ApplicationContext context;

@Test
void contextLoads() {
assertNotNull(context);
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,100 @@
package ai.dragon.controller.api.raag;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.time.Duration;
import java.util.List;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ActiveProfiles;

import com.theokanning.openai.model.Model;
import com.theokanning.openai.service.OpenAiService;

import ai.dragon.entity.FarmEntity;
import ai.dragon.enumeration.LanguageModelType;
import ai.dragon.repository.FarmRepository;
import ai.dragon.test.AbstractTest;
import dev.ai4j.openai4j.OpenAiClient;
import dev.ai4j.openai4j.completion.CompletionRequest;
import dev.ai4j.openai4j.completion.CompletionResponse;
import dev.langchain4j.model.mistralai.internal.api.MistralAiModelResponse;
import dev.langchain4j.model.mistralai.internal.client.MistralAiClient;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class OpenAiCompatibleV1ApiControllerTest {
public class OpenAiCompatibleV1ApiControllerTest extends AbstractTest {
@LocalServerPort
private int serverPort;

@Autowired
private FarmRepository farmRepository;

@BeforeAll
static void beforeAll(@Autowired FarmRepository farmRepository) {
farmRepository.deleteAll();
}

@AfterAll
static void afterAll(@Autowired FarmRepository farmRepository) {
farmRepository.deleteAll();
}

@BeforeEach
void beforeEach(@Autowired FarmRepository farmRepository) {
farmRepository.deleteAll();
}

@Test
void listModels() throws Exception {
farmRepository.deleteAll();
FarmEntity farm = new FarmEntity();
farm.setRaagIdentifier("awesome-raag");
farmRepository.save(farm);

OpenAiService service = new OpenAiService("TODO_PUT_KEY_HERE",
String.format("http://localhost:%d/api/raag/v1/", serverPort));
List<Model> models = service.listModels();
assertFalse(models.isEmpty());
assertEquals(1, models.size());

MistralAiClient client = MistralAiClient.builder()
.apiKey("TODO_PUT_KEY_HERE")
.baseUrl(String.format("http://localhost:%d/api/raag/v1/", serverPort))
.timeout(Duration.ofSeconds(10))
.logRequests(false)
.logResponses(false)
.build();
MistralAiModelResponse modelsResponse = client.listModels();
assertNotNull(modelsResponse);
assertEquals(1, modelsResponse.getData().size());
assertEquals(farm.getRaagIdentifier(), modelsResponse.getData().get(0).getId());
}

@Test
@EnabledIf("canRunOpenAiRelatedTests")
void testFarmNoSiloOpenAI() {
String apiKeySetting = String.format("apiKey=%s", System.getenv("OPENAI_API_KEY"));
String modelNameSetting = "modelName=gpt-4o";

FarmEntity farm = new FarmEntity();
farm.setRaagIdentifier("dragon-raag");
farm.setLanguageModel(LanguageModelType.OpenAiModel);
farm.setLanguageModelSettings(List.of(apiKeySetting, modelNameSetting));
farmRepository.save(farm);

OpenAiClient client = OpenAiClient.builder()
.openAiApiKey("TODO_PUT_KEY_HERE")
.baseUrl(String.format("http://localhost:%d/api/raag/v1/", serverPort))
.build();
CompletionRequest request = CompletionRequest.builder()
.model("dragon-raag")
.prompt("Just say 'HELLO' in lowercased letters.")
.build();
CompletionResponse response = client.completion(request).execute();
assertNotNull(response);
assertNotNull(response.choices());
assertNotEquals(0, response.choices().size());
assertEquals("hello", response.choices().get(0).text());
}
}
7 changes: 7 additions & 0 deletions backend/src/test/java/ai/dragon/test/AbstractTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ai.dragon.test;

public abstract class AbstractTest {
protected boolean canRunOpenAiRelatedTests() {
return System.getenv("DRAGON_CICD") != null || System.getenv("OPENAI_API_KEY") != null;
}
}

0 comments on commit 93fb73e

Please sign in to comment.