@cobrowser/chatgpt 0.7.31 → 0.7.32-dev.0
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/constants.d.ts +2 -2
- package/dist/constants.js +19 -23
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/ConversationHistory.d.ts +3 -3
- package/dist/models/Item.d.ts +2 -2
- package/dist/services/AssistantService/AssistantService.d.ts +3 -3
- package/dist/services/AssistantService/AssistantService.js +14 -13
- package/dist/services/BaseService/BaseService.d.ts +6 -14
- package/dist/services/BaseService/BaseService.js +7 -65
- package/dist/services/ChatService/ChatService.d.ts +1 -2
- package/dist/services/ChatService/ChatService.js +9 -14
- package/dist/services/CopilotService/CopilotService.d.ts +14 -8
- package/dist/services/CopilotService/CopilotService.js +145 -54
- package/dist/services/ResponseService/ResponseService.d.ts +37 -0
- package/dist/services/ResponseService/ResponseService.js +213 -0
- package/dist/services/TranslationService/TranslationService.d.ts +4 -4
- package/dist/services/TranslationService/TranslationService.js +11 -14
- package/package.json +4 -5
- package/dist/models/ChatGPTMessage.d.ts +0 -17
- package/dist/models/ChatGPTMessage.js +0 -9
- package/dist/models/ChatGPTResponse.d.ts +0 -8
- package/dist/models/ChatGPTResponse.js +0 -2
- package/dist/models/ChatGPTUsageTokens.d.ts +0 -6
- package/dist/models/ChatGPTUsageTokens.js +0 -2
- package/dist/models/Response.d.ts +0 -3
- package/dist/models/Response.js +0 -2
- package/dist/utils/Response.d.ts +0 -4
- package/dist/utils/Response.js +0 -11
- package/dist/utils/constants.d.ts +0 -13
- package/dist/utils/constants.js +0 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.32-dev.0",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"precommit": "npm run lint && npm run test && npm run upgrade && npm run security"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cobrowser/logger": "^2.0.
|
|
25
|
-
"@cobrowser/xss-validation": "^2.0.1",
|
|
24
|
+
"@cobrowser/logger": "^2.0.6",
|
|
26
25
|
"axios": "^1.6.1",
|
|
27
26
|
"axios-mock-adapter": "^1.22.0",
|
|
28
|
-
"openai": "^
|
|
27
|
+
"openai": "^6.3.0"
|
|
29
28
|
},
|
|
30
29
|
"directories": {
|
|
31
30
|
"dist": "dist"
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"bugs": {
|
|
41
40
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "246db1800e2c2238ae01d99a69c971fe6ecd4795"
|
|
44
43
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare enum ChatGPTRole {
|
|
2
|
-
USER = "user",
|
|
3
|
-
SYSTEM = "system",
|
|
4
|
-
ASSISTANT = "assistant"
|
|
5
|
-
}
|
|
6
|
-
export interface ChatGPTRequestBody {
|
|
7
|
-
model: string;
|
|
8
|
-
response_format?: {
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
messages: ChatGPTMessage[];
|
|
12
|
-
}
|
|
13
|
-
interface ChatGPTMessage {
|
|
14
|
-
role: ChatGPTRole;
|
|
15
|
-
content: string;
|
|
16
|
-
}
|
|
17
|
-
export default ChatGPTMessage;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChatGPTRole = void 0;
|
|
4
|
-
var ChatGPTRole;
|
|
5
|
-
(function (ChatGPTRole) {
|
|
6
|
-
ChatGPTRole["USER"] = "user";
|
|
7
|
-
ChatGPTRole["SYSTEM"] = "system";
|
|
8
|
-
ChatGPTRole["ASSISTANT"] = "assistant";
|
|
9
|
-
})(ChatGPTRole = exports.ChatGPTRole || (exports.ChatGPTRole = {}));
|
package/dist/models/Response.js
DELETED
package/dist/utils/Response.d.ts
DELETED
package/dist/utils/Response.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const MESSAGE_SENDER: {
|
|
2
|
-
visitor: string;
|
|
3
|
-
chatbot: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const MESSAGE_TYPES: {
|
|
6
|
-
text: string;
|
|
7
|
-
button: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const DEFAULT_PROMPT = "\n You are a helpful assistant. Your role is to address visitor \n queries related to the ongoing conversation and the last message received. Please ensure \n that responses remain within the ongoing conversation. Politely decline any user queries \n that is not present in the ongoing conversation. \n\n You will always respond with a JSON. It will be in the format: \n\n { answer: '', suggestions: [], connectWithAgent: true or false }\n\n Fields in the JSON:\n\n Answer: It will consist of the user's query answer based on the ongoing conversation. \n Restrict this field to 100 characters.\n\n Suggestions: Request 2 suggestions from user's perspective that he can ask. \n It should be an array of strings. Restrict each suggestion to 50 characters.\n \n ConnectWithAgent: It is a boolean. It should be set to true if the user's query is \n not found in the ongoing conversation. Politely tell the user to talk to a real agent. \n Also when it is true, do not provide any suggestions.\n";
|
|
10
|
-
export declare const DESTINATION_LANGUAGE = "English";
|
|
11
|
-
export declare const LANGUAGE_DETECTION_SYSTEM_ROLE = "\n You are a language detection assistant. Your task is to analyze short text input and determine \n its language using ISO language code. Respond only in JSON format with two key-value pairs: \n - 'languageCode': the detected language's ISO code (or undefined if detection fails).\n - 'isError': a boolean value (true if detection fails, false otherwise).\n";
|
|
12
|
-
export declare const WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = "\n You are a language detection assistant. Your task is to analyze the most frequently occurring words in the given text \n and determine the language based on those words. Respond only in JSON format with two key-value pairs: \n - 'languageCode': the detected language's ISO code (or undefined if detection fails).\n - 'isError': a boolean value (true if detection fails, false otherwise).\n";
|
|
13
|
-
export declare const TRANSLATION_SYSTEM_ROLE = "\n You are a translator that responds exclusively in JSON format. Your response must be a JSON object containing:\n - 'translations': it is an array of objects. Each object in the array must contain:\n - 'original': The original input message before translation.\n - 'translation: The translated version of 'original', ensuring it is natural, culturally appropriate, and commonly used by native speakers.\n - 'isError': a boolean value (true if translation fails, false otherwise).\n\n **You MUST return the JSON format even if you fail to translate the text. In this case, translations field will be empty array and isError should be true.** \n\n Ensure that 'translation' accurately represents the meaning of 'original' while considering cultural nuances, usual expressions, and natural phrasing in the target language.\n\n Your response must follow this structure strictly.\n";
|
package/dist/utils/constants.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TRANSLATION_SYSTEM_ROLE = exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = exports.LANGUAGE_DETECTION_SYSTEM_ROLE = exports.DESTINATION_LANGUAGE = exports.DEFAULT_PROMPT = exports.MESSAGE_TYPES = exports.MESSAGE_SENDER = void 0;
|
|
4
|
-
// Message sender in conversation history
|
|
5
|
-
exports.MESSAGE_SENDER = {
|
|
6
|
-
visitor: 'visitor',
|
|
7
|
-
chatbot: 'chatbot'
|
|
8
|
-
};
|
|
9
|
-
// Message types in conversation history
|
|
10
|
-
exports.MESSAGE_TYPES = {
|
|
11
|
-
text: 'text',
|
|
12
|
-
button: 'button'
|
|
13
|
-
};
|
|
14
|
-
// Default prompt for ChatGPT
|
|
15
|
-
exports.DEFAULT_PROMPT = `
|
|
16
|
-
You are a helpful assistant. Your role is to address visitor
|
|
17
|
-
queries related to the ongoing conversation and the last message received. Please ensure
|
|
18
|
-
that responses remain within the ongoing conversation. Politely decline any user queries
|
|
19
|
-
that is not present in the ongoing conversation.
|
|
20
|
-
|
|
21
|
-
You will always respond with a JSON. It will be in the format:
|
|
22
|
-
|
|
23
|
-
{ answer: '', suggestions: [], connectWithAgent: true or false }
|
|
24
|
-
|
|
25
|
-
Fields in the JSON:
|
|
26
|
-
|
|
27
|
-
Answer: It will consist of the user's query answer based on the ongoing conversation.
|
|
28
|
-
Restrict this field to 100 characters.
|
|
29
|
-
|
|
30
|
-
Suggestions: Request 2 suggestions from user's perspective that he can ask.
|
|
31
|
-
It should be an array of strings. Restrict each suggestion to 50 characters.
|
|
32
|
-
|
|
33
|
-
ConnectWithAgent: It is a boolean. It should be set to true if the user's query is
|
|
34
|
-
not found in the ongoing conversation. Politely tell the user to talk to a real agent.
|
|
35
|
-
Also when it is true, do not provide any suggestions.
|
|
36
|
-
`;
|
|
37
|
-
// Default destination language
|
|
38
|
-
exports.DESTINATION_LANGUAGE = 'English';
|
|
39
|
-
// Language detection system role
|
|
40
|
-
exports.LANGUAGE_DETECTION_SYSTEM_ROLE = `
|
|
41
|
-
You are a language detection assistant. Your task is to analyze short text input and determine
|
|
42
|
-
its language using ISO language code. Respond only in JSON format with two key-value pairs:
|
|
43
|
-
- 'languageCode': the detected language's ISO code (or undefined if detection fails).
|
|
44
|
-
- 'isError': a boolean value (true if detection fails, false otherwise).
|
|
45
|
-
`;
|
|
46
|
-
// Word frequency language detection system role
|
|
47
|
-
exports.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE = `
|
|
48
|
-
You are a language detection assistant. Your task is to analyze the most frequently occurring words in the given text
|
|
49
|
-
and determine the language based on those words. Respond only in JSON format with two key-value pairs:
|
|
50
|
-
- 'languageCode': the detected language's ISO code (or undefined if detection fails).
|
|
51
|
-
- 'isError': a boolean value (true if detection fails, false otherwise).
|
|
52
|
-
`;
|
|
53
|
-
// Message translation system role
|
|
54
|
-
exports.TRANSLATION_SYSTEM_ROLE = `
|
|
55
|
-
You are a translator that responds exclusively in JSON format. Your response must be a JSON object containing:
|
|
56
|
-
- 'translations': it is an array of objects. Each object in the array must contain:
|
|
57
|
-
- 'original': The original input message before translation.
|
|
58
|
-
- 'translation: The translated version of 'original', ensuring it is natural, culturally appropriate, and commonly used by native speakers.
|
|
59
|
-
- 'isError': a boolean value (true if translation fails, false otherwise).
|
|
60
|
-
|
|
61
|
-
**You MUST return the JSON format even if you fail to translate the text. In this case, translations field will be empty array and isError should be true.**
|
|
62
|
-
|
|
63
|
-
Ensure that 'translation' accurately represents the meaning of 'original' while considering cultural nuances, usual expressions, and natural phrasing in the target language.
|
|
64
|
-
|
|
65
|
-
Your response must follow this structure strictly.
|
|
66
|
-
`;
|