Skip to content

Commit

Permalink
[ISSUE apache#4047] fix dependencies check failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jevinjiang committed Apr 10, 2024
1 parent 3331997 commit 126b29d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
dependencies {
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
implementation project(":eventmesh-common")
implementation 'com.theokanning.openai-gpt3-java:service:0.18.2'
implementation 'io.cloudevents:cloudevents-http-vertx:2.3.0'
implementation 'io.vertx:vertx-web:4.4.6'
implementation 'com.theokanning.openai-gpt3-java:service:0.18.2'

testImplementation "org.apache.httpcomponents:httpclient"
compileOnly 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import org.apache.commons.lang3.StringUtils;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.apache.eventmesh.common.utils.JsonUtils;
import org.apache.eventmesh.connector.chatgpt.source.config.ChatGPTSourceConfig;
import org.apache.eventmesh.connector.chatgpt.source.config.ChatGPTSourceConnectorConfig;
import org.apache.eventmesh.connector.chatgpt.source.config.OpenaiConfig;
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
import org.apache.eventmesh.openconnect.util.ConfigUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
Expand All @@ -37,9 +39,14 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


class ChatGPTSourceConnectorTest {

private static final Logger LOGGER = LoggerFactory.getLogger("ChatGPTSourceConnectorTest");

private ChatGPTSourceConnector connector;
private ChatGPTSourceConnectorConfig config;
private CloseableHttpClient httpClient;
Expand All @@ -48,9 +55,23 @@ class ChatGPTSourceConnectorTest {

private final String expectedParseMessage = "User 13356288979 from Tianjin store placed an order with order number 11221122";


public boolean checkOpenAi() throws Exception {
ChatGPTSourceConfig sourceConfig = (ChatGPTSourceConfig) ConfigUtil.parse(connector.configClass());
OpenaiConfig openaiConfig = sourceConfig.getOpenaiConfig();
if (StringUtils.isBlank(openaiConfig.getToken())) {
return false;
}
return true;
}

@BeforeEach
void setUp() throws Exception {
connector = new ChatGPTSourceConnector();
if (!checkOpenAi()) {
LOGGER.error("please set openai token in the config");
return;
}
ChatGPTSourceConfig sourceConfig = (ChatGPTSourceConfig) ConfigUtil.parse(connector.configClass());
config = sourceConfig.getConnectorConfig();
connector.init(sourceConfig);
Expand All @@ -63,6 +84,13 @@ void setUp() throws Exception {

@Test
void testPoll() throws Exception {
ChatGPTSourceConfig sourceConfig = (ChatGPTSourceConfig) ConfigUtil.parse(connector.configClass());
OpenaiConfig openaiConfig = sourceConfig.getOpenaiConfig();
if (StringUtils.isBlank(openaiConfig.getToken())) {
LOGGER.error("please set openai token in the config");
return;
}

final int batchSize = 10;

for (int i = 0; i < batchSize; i++) {
Expand Down Expand Up @@ -125,8 +153,15 @@ HttpResponse mockStructuredParseRequest() throws Exception {

@AfterEach
void tearDown() throws Exception {
connector.stop();
httpClient.close();
if (!checkOpenAi()) {
return;
}
if (connector != null) {
connector.stop();
}
if (httpClient != null) {
httpClient.close();
}
}

class TestEvent {
Expand Down
3 changes: 3 additions & 0 deletions tools/dependency-check/known-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,6 @@ zookeeper-3.7.1.jar
zookeeper-jute-3.7.1.jar
zstd-jni-1.5.0-2.jar
zstd-jni-1.5.2-2.jar
service-0.18.2.jar
client-0.18.2.jar
api-0.18.2.jar

0 comments on commit 126b29d

Please sign in to comment.