Skip to content

Commit

Permalink
Nightly build (langchain4j#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
dliubarskyi authored Jun 3, 2024
1 parent c90442d commit 2d8cfe5
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 204 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Nightly Build

on:
schedule:
- cron: '0 0 * * *' # daily at midnight UTC
workflow_dispatch:
pull_request:
branches:
- main

jobs:
java_build:
strategy:
matrix:
java_version: [ 8, 11, 17, 21 ]
include:
- java_version: '8'
included_modules: '-pl !langchain4j-local-ai,!langchain4j-milvus,!code-execution-engines/langchain4j-code-execution-engine-graalvm-polyglot,!langchain4j-cassandra,!langchain4j-infinispan,!langchain4j-neo4j,!langchain4j-opensearch,!langchain4j-azure-ai-search'
- java_version: '11'
included_modules: '-pl !langchain4j-local-ai,!langchain4j-milvus,!code-execution-engines/langchain4j-code-execution-engine-graalvm-polyglot,!langchain4j-infinispan,!langchain4j-neo4j'
- java_version: '17'
included_modules: '-pl !langchain4j-local-ai,!langchain4j-milvus,!code-execution-engines/langchain4j-code-execution-engine-graalvm-polyglot'
- java_version: '21'
included_modules: '-pl !langchain4j-local-ai,!langchain4j-milvus'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java_version }}
distribution: 'temurin'
cache: 'maven'

- name: Authenticate to Google Cloud
# Needed for langchain4j-vertex-ai and langchain4j-vertex-ai-gemini modules
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
credentials_json: ${{ secrets.GCP_CREDENTIALS_JSON }}

- name: Setup Testcontainers Cloud Client
# Needed for langchain4j-ollama and other modules using testcontainers
uses: atomicjar/testcontainers-cloud-setup-action@v1
with:
token: ${{ secrets.TC_CLOUD_TOKEN }}

- name: Build with JDK ${{ matrix.java_version }}
run: mvn -B -U --fail-at-end ${{ matrix.included_modules }} test
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
AZURE_SEARCH_ENDPOINT: ${{ secrets.AZURE_SEARCH_ENDPOINT }}
AZURE_SEARCH_KEY: ${{ secrets.AZURE_SEARCH_KEY }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
ELASTICSEARCH_CLOUD_API_KEY: ${{ secrets.ELASTICSEARCH_CLOUD_API_KEY }}
ELASTICSEARCH_CLOUD_URL: ${{ secrets.ELASTICSEARCH_CLOUD_URL }}
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }}
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_VERTEXAI_ENDPOINT: ${{ secrets.GCP_VERTEXAI_ENDPOINT }}
HF_API_KEY: ${{ secrets.HF_API_KEY }}
JINA_API_KEY: ${{ secrets.JINA_API_KEY }}
MILVUS_API_KEY: ${{ secrets.MILVUS_API_KEY }}
MILVUS_URI: ${{ secrets.MILVUS_URI }}
MISTRAL_AI_API_KEY: ${{ secrets.MISTRAL_AI_API_KEY }}
MONGODB_ATLAS_USERNAME: ${{ secrets.MONGODB_ATLAS_USERNAME }}
MONGODB_ATLAS_PASSWORD: ${{ secrets.MONGODB_ATLAS_PASSWORD }}
MONGODB_ATLAS_HOST: ${{ secrets.MONGODB_ATLAS_HOST }}
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
WEAVIATE_HOST: ${{ secrets.WEAVIATE_HOST }}
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
run: mvn -B -U --fail-at-end -DskipTests -DskipITs -DskipAnthropicITs -DskipLocalAiITs -DskipMilvusITs -DskipMongoDbAtlasITs -DskipOllamaITs -DskipVearchITs -DskipVertexAiGeminiITs -pl !langchain4j-core,!langchain4j-parent -Psign clean deploy
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
AZURE_SEARCH_ENDPOINT: ${{ secrets.AZURE_SEARCH_ENDPOINT }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.*;
import dev.langchain4j.model.anthropic.internal.client.AnthropicHttpException;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import dev.langchain4j.model.output.TokenUsage;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -64,11 +62,6 @@ class AnthropicChatModelIT {
.addParameter("location", OBJECT, property("properties", singletonMap("city", singletonMap("type", "string"))))
.build();

@AfterEach
void afterEach() throws InterruptedException {
Thread.sleep(10_000L); // to avoid hitting rate limits
}

@Test
void should_generate_answer_and_return_token_usage_and_finish_reason_stop() {

Expand Down Expand Up @@ -292,26 +285,6 @@ void should_fail_to_create_without_api_key() {
"It can be generated here: https://console.anthropic.com/settings/keys");
}

@Test
void should_fail_with_rate_limit_error() {

ChatLanguageModel model = AnthropicChatModel.builder()
.apiKey(System.getenv("ANTHROPIC_API_KEY"))
.maxTokens(1)
.logRequests(true)
.logResponses(true)
.build();

assertThatThrownBy(() -> {
for (int i = 0; i < 100; i++) {
model.generate("Hi");
}
})
.isExactlyInstanceOf(RuntimeException.class) // TODO return AnthropicHttpException (not wrapped)?
.hasRootCauseExactlyInstanceOf(AnthropicHttpException.class)
.hasMessageContaining("rate_limit_error");
}

@ParameterizedTest
@MethodSource("models_supporting_tools")
void should_execute_a_tool_then_answer(AnthropicChatModelName modelName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ImageContent;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.anthropic.internal.client.AnthropicHttpException;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.chat.TestStreamingResponseHandler;
import dev.langchain4j.model.output.Response;
import dev.langchain4j.model.output.TokenUsage;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import java.time.Duration;
import java.util.Base64;
import java.util.concurrent.ExecutionException;

import static dev.langchain4j.data.message.UserMessage.userMessage;
import static dev.langchain4j.internal.Utils.readBytes;
Expand All @@ -36,11 +33,6 @@ class AnthropicStreamingChatModelIT {
.logResponses(true)
.build();

@AfterEach
void afterEach() throws InterruptedException {
Thread.sleep(10_000L); // to avoid hitting rate limits
}

@Test
void should_stream_answer_and_return_token_usage_and_finish_reason_stop() {

Expand Down Expand Up @@ -150,26 +142,4 @@ void should_fail_to_create_without_api_key() {
.hasMessage("Anthropic API key must be defined. " +
"It can be generated here: https://console.anthropic.com/settings/keys");
}

@Test
void should_fail_with_rate_limit_error() {

StreamingChatLanguageModel model = AnthropicStreamingChatModel.builder()
.apiKey(System.getenv("ANTHROPIC_API_KEY"))
.maxTokens(1)
.logRequests(true)
.logResponses(true)
.build();

assertThatThrownBy(() -> {
for (int i = 0; i < 100; i++) {
TestStreamingResponseHandler<AiMessage> handler = new TestStreamingResponseHandler<>();
model.generate("Hi", handler);
handler.get();
}
})
.isExactlyInstanceOf(ExecutionException.class)
.hasRootCauseExactlyInstanceOf(AnthropicHttpException.class)
.hasMessageContaining("rate_limit_error");
}
}
Loading

0 comments on commit 2d8cfe5

Please sign in to comment.