Skip to content

Commit fdb96d8

Browse files
jevinjiangJiangShuJu
and
JiangShuJu
authored
[ISSUE #4047] Support chatGPT source connector (#4817)
* [ISSUE #4047] Support chatGPT source connector * [ISSUE #4047] Add OpenAI configuration and adjust DTO * [ISSUE #4047] Join parse request support * [ISSUE #4047] impl Parse request * [ISSUE #4047] fix code style * [ISSUE #4047] fix code style * [ISSUE #4047] fix dependencies check failed * [ISSUE #4047] fix dependencies check * [ISSUE #4047] fix license check * [ISSUE #4047] fix review question * [ISSUE #4047] fix review question * [ISSUE #4047] add default value * [ISSUE #4047] fix test * [ISSUE #4047] default timeout value is zero , not timeout . * [ISSUE #4047] fix review * [ISSUE #4047] fix license check --------- Co-authored-by: JiangShuJu <[email protected]>
1 parent a899e54 commit fdb96d8

File tree

22 files changed

+1297
-0
lines changed

22 files changed

+1297
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
dependencies {
19+
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
20+
implementation project(":eventmesh-common")
21+
implementation 'com.theokanning.openai-gpt3-java:service:0.18.2'
22+
implementation 'io.cloudevents:cloudevents-http-vertx:2.3.0'
23+
implementation 'io.vertx:vertx-web:4.4.6'
24+
25+
testImplementation "org.apache.httpcomponents:httpclient"
26+
compileOnly 'org.projectlombok:lombok'
27+
annotationProcessor 'org.projectlombok:lombok'
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
pluginType=connector
18+
pluginName=chatgpt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.config;
19+
20+
import org.apache.eventmesh.openconnect.api.config.Config;
21+
22+
import lombok.Data;
23+
import lombok.EqualsAndHashCode;
24+
25+
@Data
26+
@EqualsAndHashCode(callSuper = true)
27+
public class ChatGPTServerConfig extends Config {
28+
29+
private boolean sourceEnable;
30+
31+
private boolean sinkEnable;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.server;
19+
20+
import org.apache.eventmesh.connector.chatgpt.config.ChatGPTServerConfig;
21+
import org.apache.eventmesh.connector.chatgpt.source.connector.ChatGPTSourceConnector;
22+
import org.apache.eventmesh.openconnect.Application;
23+
import org.apache.eventmesh.openconnect.util.ConfigUtil;
24+
25+
public class ChatGPTConnectServer {
26+
27+
public static void main(String[] args) throws Exception {
28+
ChatGPTServerConfig serverConfig = ConfigUtil.parse(ChatGPTServerConfig.class, "server-config.yml");
29+
30+
if (serverConfig.isSourceEnable()) {
31+
Application chatGPTSourceApp = new Application();
32+
chatGPTSourceApp.run(ChatGPTSourceConnector.class);
33+
}
34+
35+
if (serverConfig.isSinkEnable()) {
36+
// TODO support sink connector
37+
}
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.source.config;
19+
20+
import org.apache.eventmesh.openconnect.api.config.SourceConfig;
21+
22+
import lombok.Data;
23+
import lombok.EqualsAndHashCode;
24+
25+
@Data
26+
@EqualsAndHashCode(callSuper = true)
27+
public class ChatGPTSourceConfig extends SourceConfig {
28+
29+
public ChatGPTSourceConnectorConfig connectorConfig;
30+
31+
public OpenaiProxyConfig openaiProxyConfig;
32+
33+
public OpenaiConfig openaiConfig;
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.source.config;
19+
20+
import lombok.Data;
21+
22+
@Data
23+
public class ChatGPTSourceConnectorConfig {
24+
25+
private String connectorName = "chatgptSource";
26+
27+
private String path = "/chatgpt";
28+
29+
private int port = 3756;
30+
31+
private int idleTimeout;
32+
33+
private boolean proxyEnable = false;
34+
35+
private String parsePromptFileName = "prompt";
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.source.config;
19+
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import lombok.Data;
25+
26+
@Data
27+
public class OpenaiConfig {
28+
29+
private String token;
30+
private String model = "gpt-3.5-turbo";
31+
private long timeout;
32+
private Double temperature;
33+
private Integer maxTokens;
34+
private Boolean logprob;
35+
private Double topLogprobs;
36+
private Map<String, Integer> logitBias;
37+
private Double frequencyPenalty;
38+
private Double presencePenalty;
39+
private String user = "eventMesh";
40+
private List<String> stop;
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.connector.chatgpt.source.config;
19+
20+
import lombok.Data;
21+
22+
@Data
23+
public class OpenaiProxyConfig {
24+
25+
private String host;
26+
27+
private int port;
28+
29+
}

0 commit comments

Comments
 (0)