@cobrowser/chatgpt 0.7.50 → 0.7.51
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/ChatGptMessage.d.ts +8 -8
- package/dist/models/ChatGptMessage.js +7 -7
- package/dist/models/ChatGptResponse.d.ts +1 -1
- package/dist/models/ChatGptUsageTokens.d.ts +2 -2
- package/dist/prompts/copilot-base-prompt.txt +4 -0
- package/dist/services/AssistantService/AssistantService.d.ts +1 -1
- package/dist/services/BaseService/BaseService.d.ts +1 -1
- package/dist/services/ChatService/ChatService.d.ts +1 -1
- package/dist/services/ChatService/ChatService.js +5 -5
- package/dist/services/CopilotService/CopilotService.d.ts +1 -1
- package/dist/services/CopilotService/CopilotService.js +2 -2
- package/dist/services/ResponseService/ResponseService.d.ts +1 -1
- package/dist/services/TranslationService/TranslationService.d.ts +1 -1
- package/dist/services/TranslationService/TranslationService.js +7 -7
- package/package.json +3 -4
- 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/ChatGPTUsageTokens.d.ts +0 -6
- package/dist/models/ChatGptResponse.js +0 -2
- package/dist/models/ChatGptUsageTokens.js +0 -2
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export declare enum
|
|
1
|
+
export declare enum ChatGPTRole {
|
|
2
2
|
USER = "user",
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
SYSTEM = "system",
|
|
4
|
+
ASSISTANT = "assistant"
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface ChatGPTRequestBody {
|
|
7
7
|
model: string;
|
|
8
8
|
response_format?: {
|
|
9
9
|
type: string;
|
|
10
10
|
};
|
|
11
|
-
messages:
|
|
11
|
+
messages: ChatGPTMessage[];
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
14
|
-
role:
|
|
13
|
+
interface ChatGPTMessage {
|
|
14
|
+
role: ChatGPTRole;
|
|
15
15
|
content: string;
|
|
16
16
|
}
|
|
17
|
-
export default
|
|
17
|
+
export default ChatGPTMessage;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(
|
|
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 = {}));
|
|
@@ -8,6 +8,10 @@ OUTPUT FORMAT — HARD
|
|
|
8
8
|
Your response must ONLY contain a valid JSON array of 2 to 3 strings.
|
|
9
9
|
Each string must be a complete customer-facing response.
|
|
10
10
|
|
|
11
|
+
OUTPUT SANITIZATION — HARD
|
|
12
|
+
- Never show citations, references, IDs, or source markers (e.g. filecite, turn0fileX)
|
|
13
|
+
- Always remove any internal markers from the final message
|
|
14
|
+
|
|
11
15
|
CONSISTENCY RULE — HARD
|
|
12
16
|
All responses MUST follow the exact same decision path and outcome.
|
|
13
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';
|
|
2
2
|
import BaseService from '../BaseService/BaseService';
|
|
3
|
-
import ChatGPTResponse from '../../models/
|
|
3
|
+
import ChatGPTResponse from '../../models/ChatGptResponse';
|
|
4
4
|
export declare class AssistantService extends BaseService {
|
|
5
5
|
assistantId: string | undefined;
|
|
6
6
|
threadId: string | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
-
import ChatGPTUsageTokens from '../../models/
|
|
2
|
+
import ChatGPTUsageTokens from '../../models/ChatGptUsageTokens';
|
|
3
3
|
declare class BaseService {
|
|
4
4
|
readonly BASE_CHAT_COMPLETION_URL = "https://api.openai.com/v1/chat/completions";
|
|
5
5
|
request: AxiosInstance;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseService from '../BaseService/BaseService';
|
|
2
|
-
import ChatGPTResponse from 'src/models/
|
|
2
|
+
import ChatGPTResponse from 'src/models/ChatGptResponse';
|
|
3
3
|
import ConversationHistory from 'src/models/ConversationHistory';
|
|
4
4
|
export declare class ChatService extends BaseService {
|
|
5
5
|
#private;
|
|
@@ -19,7 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
var _ChatService_instances, _ChatService_formatConversationHistory;
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.ChatService = void 0;
|
|
22
|
-
const
|
|
22
|
+
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
23
23
|
const constants_1 = require("../../utils/constants");
|
|
24
24
|
const logger_1 = __importDefault(require("../logger"));
|
|
25
25
|
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
@@ -66,7 +66,7 @@ exports.ChatService = ChatService;
|
|
|
66
66
|
_ChatService_instances = new WeakSet(), _ChatService_formatConversationHistory = function _ChatService_formatConversationHistory(context, conversationHistory) {
|
|
67
67
|
const formatted = [
|
|
68
68
|
{
|
|
69
|
-
role:
|
|
69
|
+
role: ChatGptMessage_1.ChatGPTRole.SYSTEM,
|
|
70
70
|
content: context || constants_1.DEFAULT_PROMPT,
|
|
71
71
|
}
|
|
72
72
|
];
|
|
@@ -76,19 +76,19 @@ _ChatService_instances = new WeakSet(), _ChatService_formatConversationHistory =
|
|
|
76
76
|
for (const body of messageBody) {
|
|
77
77
|
if (body.type === constants_1.MESSAGE_TYPES.text && message.from === constants_1.MESSAGE_SENDER.visitor) {
|
|
78
78
|
formatted.push({
|
|
79
|
-
role:
|
|
79
|
+
role: ChatGptMessage_1.ChatGPTRole.USER,
|
|
80
80
|
content: body.text
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
else if (body.type === constants_1.MESSAGE_TYPES.text && message.from === constants_1.MESSAGE_SENDER.chatbot) {
|
|
84
84
|
formatted.push({
|
|
85
|
-
role:
|
|
85
|
+
role: ChatGptMessage_1.ChatGPTRole.ASSISTANT,
|
|
86
86
|
content: body.text
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
else if (body.type === constants_1.MESSAGE_TYPES.button && message.from === constants_1.MESSAGE_SENDER.chatbot) {
|
|
90
90
|
formatted.push({
|
|
91
|
-
role:
|
|
91
|
+
role: ChatGptMessage_1.ChatGPTRole.ASSISTANT,
|
|
92
92
|
content: body.label
|
|
93
93
|
});
|
|
94
94
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseService from '../BaseService/BaseService';
|
|
2
|
-
import ChatGPTResponse from '../../models/
|
|
2
|
+
import ChatGPTResponse from '../../models/ChatGptResponse';
|
|
3
3
|
export declare class CopilotService extends BaseService {
|
|
4
4
|
#private;
|
|
5
5
|
assistantId: string | undefined;
|
|
@@ -19,7 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
var _CopilotService_instances, _CopilotService_processSuggestions, _CopilotService_prepareAssistantResponseAnswer;
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.CopilotService = void 0;
|
|
22
|
-
const
|
|
22
|
+
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
23
23
|
const helper_1 = require("../../utils/helper");
|
|
24
24
|
const logger_1 = __importDefault(require("../logger"));
|
|
25
25
|
const openai_1 = __importDefault(require("openai"));
|
|
@@ -117,7 +117,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
117
117
|
|
|
118
118
|
${suggestionLanguage ? `The replies must be in ${suggestionLanguage}.` : ''}
|
|
119
119
|
`.trim(), mainPromptMessage = {
|
|
120
|
-
role:
|
|
120
|
+
role: ChatGptMessage_1.ChatGPTRole.USER,
|
|
121
121
|
content: mainPrompt,
|
|
122
122
|
},
|
|
123
123
|
// the body we need to send to the request
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseService from '../BaseService/BaseService';
|
|
2
|
-
import ChatGPTResponse from '../../models/
|
|
2
|
+
import ChatGPTResponse from '../../models/ChatGptResponse';
|
|
3
3
|
export declare class TranslationService extends BaseService {
|
|
4
4
|
constructor(apiKey?: string, model?: string, apiUrl?: string, maxNumberOfChoices?: number);
|
|
5
5
|
/**
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TranslationService = void 0;
|
|
16
16
|
const constants_1 = require("../../utils/constants");
|
|
17
|
-
const
|
|
17
|
+
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
18
18
|
const helper_1 = require("../../utils/helper");
|
|
19
19
|
const logger_1 = __importDefault(require("../logger"));
|
|
20
20
|
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
@@ -50,14 +50,14 @@ class TranslationService extends BaseService_1.default {
|
|
|
50
50
|
response_format: { type: 'json_object' },
|
|
51
51
|
messages: [
|
|
52
52
|
{
|
|
53
|
-
role:
|
|
53
|
+
role: ChatGptMessage_1.ChatGPTRole.SYSTEM,
|
|
54
54
|
content: `
|
|
55
55
|
${yield (0, helper_1.readPrompt)('autotranslation-base-prompt.txt')}
|
|
56
56
|
<ADDITIONAL_INSTRUCTIONS>${additionalInstructions}</ADDITIONAL_INSTRUCTIONS>
|
|
57
57
|
`,
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
|
-
role:
|
|
60
|
+
role: ChatGptMessage_1.ChatGPTRole.USER,
|
|
61
61
|
content: translateText,
|
|
62
62
|
},
|
|
63
63
|
],
|
|
@@ -92,11 +92,11 @@ class TranslationService extends BaseService_1.default {
|
|
|
92
92
|
response_format: { type: 'json_object' },
|
|
93
93
|
messages: [
|
|
94
94
|
{
|
|
95
|
-
role:
|
|
95
|
+
role: ChatGptMessage_1.ChatGPTRole.SYSTEM,
|
|
96
96
|
content: constants_1.LANGUAGE_DETECTION_SYSTEM_ROLE,
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
|
-
role:
|
|
99
|
+
role: ChatGptMessage_1.ChatGPTRole.USER,
|
|
100
100
|
content: translateText,
|
|
101
101
|
}
|
|
102
102
|
],
|
|
@@ -131,11 +131,11 @@ class TranslationService extends BaseService_1.default {
|
|
|
131
131
|
response_format: { type: 'json_object' },
|
|
132
132
|
messages: [
|
|
133
133
|
{
|
|
134
|
-
role:
|
|
134
|
+
role: ChatGptMessage_1.ChatGPTRole.SYSTEM,
|
|
135
135
|
content: constants_1.WORD_FREQUENCY_LANGUAGE_DETECTION_SYSTEM_ROLE,
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
role:
|
|
138
|
+
role: ChatGptMessage_1.ChatGPTRole.USER,
|
|
139
139
|
content: translateText,
|
|
140
140
|
}
|
|
141
141
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.51",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@cobrowser/logger": "^2.0.7",
|
|
25
25
|
"@cobrowser/xss-validation": "^2.0.3",
|
|
26
26
|
"axios": "^1.16.0",
|
|
27
|
-
"openai": "^6.
|
|
27
|
+
"openai": "^6.38.0"
|
|
28
28
|
},
|
|
29
29
|
"directories": {
|
|
30
30
|
"dist": "dist"
|
|
@@ -42,6 +42,5 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"axios-mock-adapter": "^2.1.0"
|
|
45
|
-
}
|
|
46
|
-
"gitHead": "c31dea8d5882f65809dda8f5b5aef14e5b9c2b3e"
|
|
45
|
+
}
|
|
47
46
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare enum ChatGptRole {
|
|
2
|
-
USER = "user",
|
|
3
|
-
ASSISTANT = "assistant",
|
|
4
|
-
SYSTEM = "system"
|
|
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["ASSISTANT"] = "assistant";
|
|
8
|
-
ChatGptRole["SYSTEM"] = "system";
|
|
9
|
-
})(ChatGptRole = exports.ChatGptRole || (exports.ChatGptRole = {}));
|