PlexPt / chatgpt-java

ChatGPT Java SDK。支持 GPT-4o、 GPT4 API。开箱即用。An unofficial Java SDK for seamless integration with ChatGPT's GPT-3.5 and GPT-4 APIs. Ready-to-use, simple setup, and efficient for building AI-powered applications.
https://chat.plexpt.com/
GNU General Public License v3.0
3.6k stars 706 forks source link

如何指定模型名称 #296

Closed Tamrac-web closed 4 months ago

Tamrac-web commented 4 months ago

请问如何指定ChatGPTStream 使用的模型名称

Tamrac-web commented 4 months ago

image 补充图片

PlexPt commented 4 months ago
     ConsoleStreamListener listener = new ConsoleStreamListener();
        Message message = Message.of("写一段七言绝句诗,题目是:火锅!");
        ChatCompletion chatCompletion = ChatCompletion.builder()
                .model("gpt-4")
                .messages(Arrays.asList(message))
                .build();
        chatGPTStream.streamChatCompletion(chatCompletion, listener);
Tamrac-web commented 4 months ago

指定模型名称和指定apihost 无法兼得吗,请问一下有配置文件设置 url 与 key 的地方吗 @PlexPt

PlexPt commented 4 months ago

请仔细阅读文档,这两个在不同位置设置的

Tamrac-web commented 4 months ago

大佬,你仓库remark里太模糊了,可以指一下路吗

zone


发件人: plex @.> 发送时间: Tuesday, July 2, 2024 6:41:58 PM 收件人: PlexPt/chatgpt-java @.> 抄送: Tamrac @.>; Author @.> 主题: Re: [PlexPt/chatgpt-java] 如何指定模型名称 (Issue #296)

请仔细阅读文档,这两个在不同位置设置的

― Reply to this email directly, view it on GitHubhttps://github.com/PlexPt/chatgpt-java/issues/296#issuecomment-2202704877, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AWMVCSFHCHYFNXFWBTXVRJDZKJ7XNAVCNFSM6AAAAABKHGMF6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBSG4YDIOBXG4. You are receiving this because you authored the thread.Message ID: @.***>

PlexPt commented 4 months ago

把你截图的代码和我贴出来的结合看即可

Tamrac-web commented 4 months ago

谢谢!已解决!!!!!!!! 这里贴一下解决代码以防后面有我这样的小白:


  SseEmitter sseEmitter = new SseEmitter(-1L);
        SseStreamListener listener = new SseStreamListener(sseEmitter);

        ChatGPTStream chatGPTStream = ChatGPTStream.builder()
            .timeout(600)
            .apiHost("http://localhost:49090/")
            .apiKey("key")
            .build()
            .init();

        ChatCompletion chatCompletion = ChatCompletion.builder()
            .model("gpt-4")
            .messages(messages)
            .build();

        chatGPTStream
        .streamChatCompletion(chatCompletion,listener);
        listener.setOnComplate(m -> {
            sseEmitter.complete();
        });

        return  sseEmitter;