From 280b66933e1f63772859fbbb3b6b0365087376f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5?= <184172133@qq.com> Date: Tue, 10 Oct 2023 22:04:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=BB=9F=E4=B8=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatglm/session/Configuration.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/cn/bugstack/chatglm/session/Configuration.java diff --git a/src/main/java/cn/bugstack/chatglm/session/Configuration.java b/src/main/java/cn/bugstack/chatglm/session/Configuration.java new file mode 100644 index 0000000..9d22ac1 --- /dev/null +++ b/src/main/java/cn/bugstack/chatglm/session/Configuration.java @@ -0,0 +1,78 @@ +package cn.bugstack.chatglm.session; + +import cn.bugstack.chatglm.IOpenAiApi; +import lombok.*; +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import okhttp3.sse.EventSource; +import okhttp3.sse.EventSources; + +/** + * @author 小傅哥,微信:fustack + * @description 配置文件 + * @github https://github.com/fuzhengwei + * @Copyright 公众号:bugstack虫洞栈 | 博客:https://bugstack.cn - 沉淀、分享、成长,让自己和他人都能有所收获! + */ +@Slf4j +@NoArgsConstructor +@AllArgsConstructor +public class Configuration { + + // 智普Ai ChatGlM 请求地址 + @Getter + @Setter + private String apiHost = "https://open.bigmodel.cn/api/paas/"; + + // 智普Ai https://open.bigmodel.cn/usercenter/apikeys - apiSecretKey = {apiKey}.{apiSecret} + private String apiSecretKey; + + public void setApiSecretKey(String apiSecretKey) { + this.apiSecretKey = apiSecretKey; + String[] arrStr = apiSecretKey.split("\\."); + if (arrStr.length != 2) { + throw new RuntimeException("invalid apiSecretKey"); + } + this.apiKey = arrStr[0]; + this.apiSecret = arrStr[1]; + } + + @Getter + private String apiKey; + @Getter + private String apiSecret; + + // Api 服务 + @Setter + @Getter + private IOpenAiApi openAiApi; + + @Getter + @Setter + private OkHttpClient okHttpClient; + + public EventSource.Factory createRequestFactory() { + return EventSources.createFactory(okHttpClient); + } + + // OkHttp 配置信息 + @Setter + @Getter + private HttpLoggingInterceptor.Level level = HttpLoggingInterceptor.Level.HEADERS; + @Setter + @Getter + private long connectTimeout = 450; + @Setter + @Getter + private long writeTimeout = 450; + @Setter + @Getter + private long readTimeout = 450; + + // http keywords + public static final String SSE_CONTENT_TYPE = "text/event-stream"; + public static final String DEFAULT_USER_AGENT = "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"; + public static final String APPLICATION_JSON = "application/json"; + public static final String JSON_CONTENT_TYPE = APPLICATION_JSON + "; charset=utf-8"; + +} -- GitLab