4040import retrofit2 .adapter .rxjava2 .RxJava2CallAdapterFactory ;
4141import retrofit2 .converter .jackson .JacksonConverterFactory ;
4242
43+ import static com .plexpt .chatgpt .util .FormatDateUtil .formatDate ;
44+
4345
4446/**
4547 * open ai 客户端
@@ -80,7 +82,7 @@ public class ChatGPT {
8082
8183
8284 /**
83- * 初始化
85+ * 初始化:与服务端建立连接,成功后可直接与服务端进行对话
8486 */
8587 public ChatGPT init () {
8688 OkHttpClient .Builder client = new OkHttpClient .Builder ();
@@ -109,7 +111,7 @@ public ChatGPT init() {
109111 log .error (baseResponse .getError ().getMessage ());
110112 throw new ChatException (baseResponse .getError ().getMessage ());
111113 }
112- throw new ChatException ("error" );
114+ throw new ChatException ("ChatGPT init error! " );
113115 }
114116 return response ;
115117 });
@@ -139,8 +141,8 @@ public ChatGPT init() {
139141 /**
140142 * 最新版的GPT-3.5 chat completion 更加贴近官方网站的问答模型
141143 *
142- * @param chatCompletion 问答参数
143- * @return 答案
144+ * @param chatCompletion 问答参数,即咨询的内容
145+ * @return 服务端的问答响应
144146 */
145147 public ChatCompletionResponse chatCompletion (ChatCompletion chatCompletion ) {
146148 Single <ChatCompletionResponse > chatCompletionResponse =
@@ -149,17 +151,20 @@ public ChatCompletionResponse chatCompletion(ChatCompletion chatCompletion) {
149151 }
150152
151153 /**
152- * 简易版
154+ * 支持多个问答参数来与服务端进行对话
153155 *
154- * @param messages 问答参数
156+ * @param messages 问答参数,即咨询的内容
157+ * @return 服务端的问答响应
155158 */
156159 public ChatCompletionResponse chatCompletion (List <Message > messages ) {
157160 ChatCompletion chatCompletion = ChatCompletion .builder ().messages (messages ).build ();
158161 return this .chatCompletion (chatCompletion );
159162 }
160163
161164 /**
162- * 直接问
165+ * 与服务端进行对话
166+ * @param message 问答参数,即咨询的内容
167+ * @return 服务端的问答响应
163168 */
164169 public String chat (String message ) {
165170 ChatCompletion chatCompletion = ChatCompletion .builder ()
@@ -172,7 +177,7 @@ public String chat(String message) {
172177 /**
173178 * 余额查询
174179 *
175- * @return
180+ * @return 余额总金额及明细
176181 */
177182 public CreditGrantsResponse creditGrants () {
178183 Single <CreditGrantsResponse > creditGrants = this .apiClient .creditGrants ();
@@ -183,7 +188,7 @@ public CreditGrantsResponse creditGrants() {
183188 /**
184189 * 余额查询
185190 *
186- * @return
191+ * @return 余额总金额
187192 */
188193 public BigDecimal balance () {
189194 Single <SubscriptionData > subscription = apiClient .subscription ();
@@ -200,9 +205,9 @@ public BigDecimal balance() {
200205 }
201206
202207 /**
203- * 余额查询
208+ * 新建连接进行余额查询
204209 *
205- * @return
210+ * @return 余额总金额
206211 */
207212 public static BigDecimal balance (String key ) {
208213 ChatGPT chatGPT = ChatGPT .builder ()
@@ -212,9 +217,4 @@ public static BigDecimal balance(String key) {
212217
213218 return chatGPT .balance ();
214219 }
215-
216- public static String formatDate (Date date ) {
217- SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" , Locale .getDefault ());
218- return sdf .format (date );
219- }
220220}
0 commit comments