@cobrowser/chatgpt 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/ChatGptUsageTokens.d.ts +6 -0
- package/dist/models/ChatGptUsageTokens.js +3 -0
- package/dist/models/CopilotSuggestion.d.ts +6 -0
- package/dist/models/CopilotSuggestion.js +2 -0
- package/dist/services/BaseService/BaseService.d.ts +6 -0
- package/dist/services/BaseService/BaseService.js +13 -0
- package/dist/services/CopilotService/CopilotService.d.ts +2 -1
- package/dist/services/CopilotService/CopilotService.js +4 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import ChatGptUsageTokens from '../../models/ChatGptUsageTokens';
|
|
2
3
|
declare class BaseService {
|
|
3
4
|
request: AxiosInstance;
|
|
4
5
|
readonly BASE_CHAT_COMPLETION_URL = "https://api.openai.com/v1/chat/completions";
|
|
@@ -16,6 +17,11 @@ declare class BaseService {
|
|
|
16
17
|
* @param response
|
|
17
18
|
*/
|
|
18
19
|
getResponseFirstChoice(response: AxiosResponse): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Filter the response from chatGpt API and only get the first choice
|
|
22
|
+
* @param response
|
|
23
|
+
*/
|
|
24
|
+
getResponseUsageTokens(response: AxiosResponse): ChatGptUsageTokens | undefined;
|
|
19
25
|
/**
|
|
20
26
|
* function to handle requests errors
|
|
21
27
|
* @param error
|
|
@@ -60,6 +60,19 @@ class BaseService {
|
|
|
60
60
|
}
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Filter the response from chatGpt API and only get the first choice
|
|
65
|
+
* @param response
|
|
66
|
+
*/
|
|
67
|
+
getResponseUsageTokens(response) {
|
|
68
|
+
var _a;
|
|
69
|
+
if ((_a = response.data) === null || _a === void 0 ? void 0 : _a.usage) {
|
|
70
|
+
const usage = response.data.usage;
|
|
71
|
+
logger_1.default.info(`ChatGpt response usage tokens: ${JSON.stringify(usage)}`);
|
|
72
|
+
return usage;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
63
76
|
/**
|
|
64
77
|
* function to handle requests errors
|
|
65
78
|
* @param error
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BaseService from '../BaseService/BaseService';
|
|
2
2
|
import ChatGptMessage from '../../models/ChatGptMessage';
|
|
3
|
+
import CopilotSuggestion from '../../models/CopilotSuggestion';
|
|
3
4
|
import Item from '../../models/Item';
|
|
4
5
|
export declare class CopilotService extends BaseService {
|
|
5
6
|
constructor(apiUrl?: string, model?: string, maxNumberOfChoices?: number);
|
|
@@ -15,7 +16,7 @@ export declare class CopilotService extends BaseService {
|
|
|
15
16
|
* this will make it easy to ask chatGpt for quick replies
|
|
16
17
|
* @param conversation
|
|
17
18
|
*/
|
|
18
|
-
suggest(conversation: string): Promise<
|
|
19
|
+
suggest(conversation: string): Promise<CopilotSuggestion | undefined>;
|
|
19
20
|
/**
|
|
20
21
|
* this will request chatGPT to recommend product or item based on the whole conversation
|
|
21
22
|
* @param conversation the whole chat conversation
|
|
@@ -53,7 +53,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
53
53
|
messages: [mainPromptMessage],
|
|
54
54
|
};
|
|
55
55
|
const response = yield this.request.post('', requestBody);
|
|
56
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
firstChoice: this.getResponseFirstChoice(response),
|
|
58
|
+
usageTokens: this.getResponseUsageTokens(response),
|
|
59
|
+
};
|
|
57
60
|
}
|
|
58
61
|
catch (e) {
|
|
59
62
|
this.handleErrors(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "e1faace27b50c02cb93e2d4c124ba2a36cdf589a"
|
|
42
42
|
}
|