-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from dRAGon-Okinawa/staging
Enhance CI/CD Workflow and Testing Suite with Environment Variables and Upgrades
- Loading branch information
Showing
10 changed files
with
102 additions
and
27 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
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
81 changes: 69 additions & 12 deletions
81
backend/src/test/java/ai/dragon/controller/api/raag/OpenAiCompatibleV1ApiControllerTest.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,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()); | ||
} | ||
} |
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,7 @@ | ||
package ai.dragon.test; | ||
|
||
public abstract class AbstractTest { | ||
protected boolean canRunOpenAiRelatedTests() { | ||
return System.getenv("DRAGON_CICD") != null || System.getenv("OPENAI_API_KEY") != null; | ||
} | ||
} |