Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev http client #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,33 @@
<flatten-maven-plugin>1.2.7</flatten-maven-plugin>
<hutool.version>5.8.18</hutool.version>
<okhttp.version>4.10.0</okhttp.version>
<luna-common.version>2.4.4</luna-common.version>
<httpclient5.version>5.2.1</httpclient5.version>
<jtokkit.version>0.4.0</jtokkit.version>
</properties>

<dependencyManagement>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>5.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -110,6 +134,12 @@
<version>${okhttp.version}</version>
</dependency>

<dependency>
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-common</artifactId>
<version>${luna-common.version}</version>
</dependency>

<dependency>
<groupId>com.knuddels</groupId>
<artifactId>jtokkit</artifactId>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/lzhpo/chatgpt/DefaultOpenAiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.lzhpo.chatgpt.entity.moderations.ModerationRequest;
import com.lzhpo.chatgpt.entity.moderations.ModerationResponse;
import com.lzhpo.chatgpt.entity.users.UserResponse;
import com.lzhpo.chatgpt.sse.Listener;
import com.lzhpo.chatgpt.utils.JsonUtils;
import java.net.URI;
import java.util.Map;
Expand Down Expand Up @@ -92,10 +93,10 @@ public CompletionResponse completions(CompletionRequest request) {
}

@Override
public void streamCompletions(CompletionRequest request, EventSourceListener listener) {
public void streamCompletions(CompletionRequest request, Listener listener) {
request.setStream(true);
Request clientRequest = createRequest(COMPLETIONS, createRequestBody(request));
RealEventSource realEventSource = new RealEventSource(clientRequest, listener);
RealEventSource realEventSource = new RealEventSource(clientRequest, (EventSourceListener) listener);
realEventSource.connect(okHttpClient);
}

Expand All @@ -110,10 +111,10 @@ public ChatCompletionResponse chatCompletions(ChatCompletionRequest request) {
}

@Override
public void streamChatCompletions(ChatCompletionRequest request, EventSourceListener listener) {
public void streamChatCompletions(ChatCompletionRequest request, Listener listener) {
request.setStream(true);
Request clientRequest = createRequest(CHAT_COMPLETIONS, createRequestBody(request));
RealEventSource realEventSource = new RealEventSource(clientRequest, listener);
RealEventSource realEventSource = new RealEventSource(clientRequest, (EventSourceListener) listener);
realEventSource.connect(okHttpClient);
}

Expand Down
Loading