@cobrowser/chatgpt 0.7.15 → 0.7.17
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.
|
@@ -3,6 +3,7 @@ import BaseService from '../BaseService/BaseService';
|
|
|
3
3
|
export declare class AssistantService extends BaseService {
|
|
4
4
|
assistantId: string | undefined;
|
|
5
5
|
threadId: string | undefined;
|
|
6
|
+
runId: string | undefined;
|
|
6
7
|
constructor(apiKey?: string, assistantId?: string, threadId?: string);
|
|
7
8
|
/**
|
|
8
9
|
* Create new thread
|
|
@@ -15,5 +16,5 @@ export declare class AssistantService extends BaseService {
|
|
|
15
16
|
*
|
|
16
17
|
* @param message
|
|
17
18
|
*/
|
|
18
|
-
getReply(message: string): Promise<ChatGptResponse | undefined>;
|
|
19
|
+
getReply(message: string, instructions?: string, functionOutputs?: string): Promise<ChatGptResponse | undefined>;
|
|
19
20
|
}
|
|
@@ -31,6 +31,12 @@ class AssistantService extends BaseService_1.default {
|
|
|
31
31
|
writable: true,
|
|
32
32
|
value: void 0
|
|
33
33
|
});
|
|
34
|
+
Object.defineProperty(this, "runId", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
34
40
|
this.assistantId = assistantId;
|
|
35
41
|
this.threadId = threadId;
|
|
36
42
|
}
|
|
@@ -51,7 +57,7 @@ class AssistantService extends BaseService_1.default {
|
|
|
51
57
|
*
|
|
52
58
|
* @param message
|
|
53
59
|
*/
|
|
54
|
-
getReply(message) {
|
|
60
|
+
getReply(message, instructions, functionOutputs) {
|
|
55
61
|
var _a;
|
|
56
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
63
|
if (!this.assistantId || !this.threadId) {
|
|
@@ -60,15 +66,23 @@ class AssistantService extends BaseService_1.default {
|
|
|
60
66
|
}
|
|
61
67
|
const openai = new openai_1.default({ apiKey: this.openaiApiKey });
|
|
62
68
|
let run;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (isRepeatedMessage) {
|
|
66
|
-
const runs = yield openai.beta.threads.runs.list(this.threadId, { order: "desc", limit: 1 });
|
|
67
|
-
run = runs.data[0];
|
|
69
|
+
if (functionOutputs && this.runId) {
|
|
70
|
+
run = yield openai.beta.threads.runs.submitToolOutputsAndPoll(this.threadId, this.runId, { tool_outputs: JSON.parse(functionOutputs) });
|
|
68
71
|
}
|
|
69
72
|
else {
|
|
70
|
-
yield openai.beta.threads.messages.
|
|
71
|
-
|
|
73
|
+
const lastThreadMessasges = yield openai.beta.threads.messages.list(this.threadId, { order: "desc", limit: 2 });
|
|
74
|
+
const isRepeatedMessage = lastThreadMessasges.data.find(msg => msg.content[0].type === 'text' && msg.content[0].text.value === message);
|
|
75
|
+
if (isRepeatedMessage) {
|
|
76
|
+
const runs = yield openai.beta.threads.runs.list(this.threadId, { order: "desc", limit: 1 });
|
|
77
|
+
run = runs.data[0];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
yield openai.beta.threads.messages.create(this.threadId, { role: "user", content: message });
|
|
81
|
+
run = yield openai.beta.threads.runs.create(this.threadId, { assistant_id: (_a = this.assistantId) !== null && _a !== void 0 ? _a : '', additional_instructions: instructions });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (run) {
|
|
85
|
+
this.runId = run.id;
|
|
72
86
|
}
|
|
73
87
|
while (['queued', 'in_progress', 'cancelling'].includes(run.status)) {
|
|
74
88
|
yield new Promise(resolve => setTimeout(resolve, 500));
|
|
@@ -87,6 +101,13 @@ class AssistantService extends BaseService_1.default {
|
|
|
87
101
|
};
|
|
88
102
|
}
|
|
89
103
|
}
|
|
104
|
+
if (run.status === 'requires_action') {
|
|
105
|
+
return {
|
|
106
|
+
requiredActions: JSON.stringify(run.required_action),
|
|
107
|
+
threadId: run.thread_id,
|
|
108
|
+
usageTokens: run.usage,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
90
111
|
return undefined;
|
|
91
112
|
});
|
|
92
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.17",
|
|
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.2",
|
|
25
25
|
"axios": "^1.6.1",
|
|
26
26
|
"axios-mock-adapter": "^1.22.0",
|
|
27
|
-
"openai": "^4.
|
|
27
|
+
"openai": "^4.52.7"
|
|
28
28
|
},
|
|
29
29
|
"directories": {
|
|
30
30
|
"dist": "dist"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"bugs": {
|
|
40
40
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "cf1fbd8ba217c2b86386dfd59765308750e0e4f5"
|
|
43
43
|
}
|