Skip to content

Commit 1eb97c9

Browse files
committed
add the chat model wrapper, chat response and unify docs
1 parent 51d409c commit 1eb97c9

File tree

4 files changed

+372
-22
lines changed

4 files changed

+372
-22
lines changed
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
package com.intellijava.core.model;
2+
3+
import java.util.List;
4+
5+
import com.intellijava.core.model.OpenaiLanguageResponse.Choice;
6+
import com.intellijava.core.model.OpenaiLanguageResponse.Usage;
7+
8+
/**
9+
*
10+
* OpenaiChatResponse is a model class used to parse the response from the OpenAI ChatGPT API.
11+
* choices, Usage and Message are nested classes.
12+
*
13+
* @author github.com/Barqawiz
14+
*/
15+
public class OpenaiChatResponse extends BaseRemoteModel {
16+
17+
private String object;
18+
private long created;
19+
private String model;
20+
private Usage usage;
21+
private List<Choice> choices;
22+
23+
/**
24+
* OpenaiChatResponse default constructor.
25+
*/
26+
public OpenaiChatResponse() {
27+
28+
}
29+
30+
/**
31+
* A nested class for the API response's choice represents the model output.
32+
*/
33+
public static class Choice {
34+
private Message message;
35+
private String finish_reason;
36+
private int index;
37+
38+
/**
39+
* Choice default constructor.
40+
*/
41+
public Choice() {
42+
43+
}
44+
45+
/**
46+
* Gets the model message.
47+
*
48+
* @return message
49+
*/
50+
public Message getMessage() {
51+
return message;
52+
}
53+
54+
/**
55+
* Sets the model message
56+
*
57+
* @param the message object of the model response.
58+
*/
59+
public void setMessage(Message message) {
60+
this.message = message;
61+
}
62+
63+
/**
64+
* Gets the reason to end the message for validating missing response reasons.
65+
*
66+
* @return reason string
67+
*/
68+
public String getFinish_reason() {
69+
return finish_reason;
70+
}
71+
72+
/**
73+
*
74+
* Sets the reason to end the message text
75+
*
76+
* @param finish_reason
77+
*/
78+
public void setFinish_reason(String finish_reason) {
79+
this.finish_reason = finish_reason;
80+
}
81+
82+
/**
83+
* Gets the index property of the choice object
84+
*
85+
* @return the index of the choice object
86+
*/
87+
public int getIndex() {
88+
return index;
89+
}
90+
91+
/**
92+
* Sets the index property of the choice object
93+
*
94+
* @param index the index of the choice object
95+
*/
96+
public void setIndex(int index) {
97+
this.index = index;
98+
}
99+
}
100+
101+
/**
102+
* Usage is a nested class that represents a Usage object returned in the API response.
103+
*/
104+
public static class Usage {
105+
private int prompt_tokens;
106+
private int completion_tokens;
107+
private int total_tokens;
108+
109+
/**
110+
* Usage default constructor.
111+
*/
112+
public Usage() {
113+
114+
}
115+
116+
/**
117+
* Gets the prompt_tokens property
118+
*
119+
* @return the value of prompt_tokens property
120+
*/
121+
public int getPrompt_tokens() {
122+
return prompt_tokens;
123+
}
124+
/**
125+
* Sets the prompt_tokens property
126+
*
127+
* @param prompt_tokens the new value of the prompt_tokens property
128+
*/
129+
public void setPrompt_tokens(int prompt_tokens) {
130+
this.prompt_tokens = prompt_tokens;
131+
}
132+
/**
133+
* Gets the completion_tokens property
134+
*
135+
* @return the value of completion_tokens property
136+
*/
137+
public int getCompletion_tokens() {
138+
return completion_tokens;
139+
}
140+
/**
141+
* Sets the completion_tokens property
142+
*
143+
* @param completion_tokens the new value of the completion_tokens property
144+
*/
145+
public void setCompletion_tokens(int completion_tokens) {
146+
this.completion_tokens = completion_tokens;
147+
}
148+
/**
149+
* Gets the total_tokens property
150+
*
151+
* @return the value of total_tokens property
152+
*/
153+
public int getTotal_tokens() {
154+
return total_tokens;
155+
}
156+
/**
157+
* Sets the total_tokens property
158+
*
159+
* @param total_tokens the new value of the total_tokens property
160+
*/
161+
public void setTotal_tokens(int total_tokens) {
162+
this.total_tokens = total_tokens;
163+
}
164+
165+
}
166+
167+
/**
168+
* Message represents a message exchanged in a chat session.
169+
*/
170+
public static class Message {
171+
private String role;
172+
private String content;
173+
174+
public Message() {}
175+
176+
/**
177+
* Gets the role of the sender of the message.
178+
*
179+
* @return the role of the sender of the message.
180+
*/
181+
public String getRole() {
182+
return role;
183+
}
184+
185+
/**
186+
* Sets the role of the sender of the message.
187+
*
188+
* @param role the role of the sender of the message.
189+
*/
190+
public void setRole(String role) {
191+
this.role = role;
192+
}
193+
194+
/**
195+
* Gets the content of the message.
196+
*
197+
* @return the content of the message.
198+
*/
199+
public String getContent() {
200+
return content;
201+
}
202+
203+
/**
204+
* Sets the content of the message.
205+
*
206+
* @param content the content of the message.
207+
*/
208+
public void setContent(String content) {
209+
this.content = content;
210+
}
211+
}
212+
213+
/**
214+
* Gets the object type of the API response.
215+
*
216+
* @return the value of object property
217+
*/
218+
public String getObject() {
219+
return object;
220+
}
221+
222+
/**
223+
* Sets the object type of the API response.
224+
*
225+
* @param object the new value of the object property
226+
*/
227+
public void setObject(String object) {
228+
this.object = object;
229+
}
230+
231+
/**
232+
* Gets the timestamp for the API response.
233+
*
234+
* @return the value of created property
235+
*/
236+
public long getCreated() {
237+
return created;
238+
}
239+
240+
241+
/**
242+
* Set the timestamp for the API response.
243+
*
244+
* @param created the timestamp when the API request was created.
245+
*/
246+
public void setCreated(long created) {
247+
this.created = created;
248+
}
249+
250+
/**
251+
* Gets the name of the language model
252+
*
253+
* @return the model id or name used to generate the API response
254+
*/
255+
public String getModel() {
256+
return model;
257+
}
258+
259+
/**
260+
* Setsthe name of the language model
261+
*
262+
* @param model the model id or name used to generate the API response
263+
*/
264+
public void setModel(String model) {
265+
this.model = model;
266+
}
267+
268+
/**
269+
* Gets the usage statistics for generating the API response.
270+
*
271+
* @return the usage object that contains usage statistics of the API request
272+
*/
273+
public Usage getUsage() {
274+
return usage;
275+
}
276+
277+
/**
278+
* Set the usage statistics for generating the API response.
279+
*
280+
* @param usage the usage object that contains usage statistics of the API request
281+
*/
282+
public void setUsage(Usage usage) {
283+
this.usage = usage;
284+
}
285+
286+
/**
287+
* Gets the choices property
288+
*
289+
* @return list of Choice objects that contain the generated completions and additional information
290+
*/
291+
public List<Choice> getChoices() {
292+
return choices;
293+
}
294+
295+
/**
296+
* Sets the choices property
297+
*
298+
* @param choices list of Choice objects that contain the generated completions and additional information
299+
*/
300+
public void setChoices(List<Choice> choices) {
301+
this.choices = choices;
302+
}
303+
}

0 commit comments

Comments
 (0)