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

流式请求不支持gpt4吗? #279

Closed
qixing-ai opened this issue May 16, 2024 · 1 comment
Closed

流式请求不支持gpt4吗? #279

qixing-ai opened this issue May 16, 2024 · 1 comment

Comments

@qixing-ai
Copy link

No description provided.

@qixing-ai
Copy link
Author

自问自答吧:

@service
public class ChatService {

@Value("${api-key}")
private String apiKey;

@Value("${proxy.host}")
private String proxyHost;

@Value("${proxy.port}")
private int proxyPort;

@Value("${api-baseurl}")
private String baseUrl;

@Value("${api-model}")
private String model;

public SseEmitter createChatStream(List<Message> messages) {
    Proxy proxy = Proxys.http(proxyHost, proxyPort);

    ChatGPTStream chatGPTStream = ChatGPTStream.builder()
            .timeout(600)
            .apiKey(apiKey)
            .proxy(proxy)
            .apiHost(baseUrl)
            .build()
            .init();

    SseEmitter sseEmitter = new SseEmitter(Long.MAX_VALUE);
    GPTEventSourceListener listener = new GPTEventSourceListener(sseEmitter);
    ChatCompletion chatCompletion = ChatCompletion.builder()
            .messages(messages)
            .model(model)
            .stream(true)
            .build();
    chatGPTStream.streamChatCompletion(chatCompletion, listener);
    return sseEmitter;
}

}

@PlexPt PlexPt closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants