@ckeditor/ckeditor5-ai 40.0.0 → 40.2.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/LICENSE.md +2 -2
- package/README.md +1 -1
- package/build/ai.js +77 -2
- package/build/translations/af.js +1 -1
- package/build/translations/ar.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/bs.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de-ch.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/es-co.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/fa.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/jv.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sr-latn.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/tk.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/ug.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/ur.js +1 -1
- package/build/translations/uz.js +1 -0
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/ckeditor5-metadata.json +1 -1
- package/lang/contexts.json +4 -1
- package/lang/translations/af.po +60 -16
- package/lang/translations/ar.po +60 -16
- package/lang/translations/bg.po +60 -16
- package/lang/translations/bn.po +60 -16
- package/lang/translations/bs.po +60 -16
- package/lang/translations/ca.po +60 -16
- package/lang/translations/cs.po +60 -16
- package/lang/translations/da.po +60 -16
- package/lang/translations/de-ch.po +60 -16
- package/lang/translations/de.po +60 -16
- package/lang/translations/el.po +60 -16
- package/lang/translations/en-au.po +60 -16
- package/lang/translations/en.po +60 -16
- package/lang/translations/es-co.po +60 -16
- package/lang/translations/es.po +60 -16
- package/lang/translations/et.po +60 -16
- package/lang/translations/fa.po +60 -16
- package/lang/translations/fi.po +60 -16
- package/lang/translations/fr.po +60 -16
- package/lang/translations/gl.po +95 -51
- package/lang/translations/he.po +60 -16
- package/lang/translations/hi.po +60 -16
- package/lang/translations/hr.po +93 -49
- package/lang/translations/hu.po +60 -16
- package/lang/translations/id.po +60 -16
- package/lang/translations/it.po +60 -16
- package/lang/translations/ja.po +60 -16
- package/lang/translations/jv.po +60 -16
- package/lang/translations/ko.po +60 -16
- package/lang/translations/lt.po +60 -16
- package/lang/translations/lv.po +60 -16
- package/lang/translations/ms.po +60 -16
- package/lang/translations/nl.po +60 -16
- package/lang/translations/no.po +60 -16
- package/lang/translations/pl.po +60 -16
- package/lang/translations/pt-br.po +60 -16
- package/lang/translations/pt.po +60 -16
- package/lang/translations/ro.po +60 -16
- package/lang/translations/ru.po +60 -16
- package/lang/translations/sk.po +60 -16
- package/lang/translations/sr-latn.po +95 -51
- package/lang/translations/sr.po +60 -16
- package/lang/translations/sv.po +60 -16
- package/lang/translations/th.po +60 -16
- package/lang/translations/tk.po +60 -16
- package/lang/translations/tr.po +60 -16
- package/lang/translations/ug.po +96 -52
- package/lang/translations/uk.po +60 -16
- package/lang/translations/ur.po +60 -16
- package/lang/translations/uz.po +226 -0
- package/lang/translations/vi.po +60 -16
- package/lang/translations/zh-cn.po +60 -16
- package/lang/translations/zh.po +60 -16
- package/package.json +4 -3
- package/src/adapters/aiadapter.d.ts +48 -0
- package/src/adapters/aiadapter.js +23 -0
- package/src/adapters/aitextadapter.d.ts +146 -0
- package/src/adapters/aitextadapter.js +23 -0
- package/src/adapters/awstextadapter.d.ts +178 -0
- package/src/adapters/awstextadapter.js +23 -0
- package/src/adapters/openaitextadapter.d.ts +181 -0
- package/src/adapters/openaitextadapter.js +23 -0
- package/src/aiassistant.d.ts +386 -419
- package/src/aiassistant.js +1 -1
- package/src/aiassistantediting.d.ts +45 -45
- package/src/aiassistantediting.js +1 -1
- package/src/aiassistantui.d.ts +52 -46
- package/src/aiassistantui.js +1 -1
- package/src/aiconfig.d.ts +69 -0
- package/src/aiconfig.js +23 -0
- package/src/augmentation.d.ts +27 -26
- package/src/index.d.ts +13 -9
- package/src/index.js +1 -1
- package/src/ui/aiassistantcontroller.d.ts +109 -59
- package/src/ui/aiassistantcontroller.js +1 -1
- package/src/ui/dropdown/aicommandslistview.d.ts +22 -22
- package/src/ui/dropdown/aicommandslistview.js +1 -1
- package/src/ui/dropdown/buttonlabelwithhighlightview.d.ts +29 -29
- package/src/ui/dropdown/buttonlabelwithhighlightview.js +1 -1
- package/src/ui/dropdown/labelwithhighlightview.d.ts +25 -0
- package/src/ui/dropdown/labelwithhighlightview.js +23 -0
- package/src/ui/form/aiformcontentarea.d.ts +48 -48
- package/src/ui/form/aiformcontentarea.js +1 -1
- package/src/ui/form/aiformerrorview.d.ts +26 -26
- package/src/ui/form/aiformerrorview.js +1 -1
- package/src/ui/form/aiformpromptview.d.ts +46 -46
- package/src/ui/form/aiformpromptview.js +1 -1
- package/src/ui/form/aiformtoolbarview.d.ts +54 -41
- package/src/ui/form/aiformtoolbarview.js +1 -1
- package/src/ui/form/aiformview.d.ts +142 -131
- package/src/ui/form/aiformview.js +1 -1
- package/src/ui/form/aihistorylistitemview.d.ts +18 -18
- package/src/ui/form/aihistorylistitemview.js +1 -1
- package/src/ui/form/aihistorylistview.d.ts +35 -35
- package/src/ui/form/aihistorylistview.js +1 -1
- package/src/ui/form/prompthistory.d.ts +20 -20
- package/src/ui/form/prompthistory.js +1 -1
- package/src/ui/showaiassistantcommand.d.ts +29 -26
- package/src/ui/showaiassistantcommand.js +1 -1
- package/src/utils/common-translations.d.ts +9 -9
- package/src/utils/common-translations.js +1 -1
- package/theme/ai-form.css +58 -11
- package/theme/ai.css +20 -15
- package/src/aiconnector.d.ts +0 -44
- package/src/aiconnector.js +0 -23
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module ai/adapters/aitextadapter
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
10
|
+
import { default as AIAdapter } from './aiadapter';
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base class for AI adapters that perform text-related requests.
|
|
13
|
+
*
|
|
14
|
+
* Concrete AI text adapter implementation plugin, after loaded by the editor, will set itself as
|
|
15
|
+
* {@link module:ai/adapters/aiadapter~AIAdapter#textAdapter `AIAdapter#textAdapter`}.
|
|
16
|
+
*
|
|
17
|
+
* Then, features making text-related AI requests will use that concrete adapter through
|
|
18
|
+
* {@link module:ai/adapters/aitextadapter~AITextAdapter#makeRequest `AIAdapter#textAdapter#makeRequest()`}.
|
|
19
|
+
*
|
|
20
|
+
* You can create your own adapter that may connect to any model by extending this abstract class.
|
|
21
|
+
*/
|
|
22
|
+
export default abstract class AITextAdapter extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* Abort controller instance.
|
|
25
|
+
*
|
|
26
|
+
* It is used by {@link ~AITextAdapter#abort `abort()`}.
|
|
27
|
+
*
|
|
28
|
+
* It should be passed to the mechanism that performs the request (e.g. `fetch()`).
|
|
29
|
+
*/
|
|
30
|
+
abortController: AbortController;
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
static get requires(): readonly [typeof AIAdapter];
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
init(): void;
|
|
39
|
+
/**
|
|
40
|
+
* The method that stops the current request and then recreates the abort controller instance.
|
|
41
|
+
*
|
|
42
|
+
* It should be called when the currently processed request should be aborted (e.g. when the user closes the UI as the request is
|
|
43
|
+
* processed).
|
|
44
|
+
*/
|
|
45
|
+
abort(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Makes the AI request to the AI API service and processes the response from the service.
|
|
48
|
+
*
|
|
49
|
+
* Internally, it uses {@link ~AITextAdapter#sendRequest `sendRequest()`}.
|
|
50
|
+
*
|
|
51
|
+
* If you are creating a custom adapter, implement `sendRequest()` rather than extending this method.
|
|
52
|
+
*
|
|
53
|
+
* Implements basic error handling for errors thrown by `sendRequest()`:
|
|
54
|
+
*
|
|
55
|
+
* * {@link module:ai/adapters/aiadapter~AIRequestError `AIRequestError`} is re-thrown, and it is expected to be handled by the feature
|
|
56
|
+
* that made the request (e.g. by displaying some error notification).
|
|
57
|
+
* * {@link module:utils/ckeditorerror~CKEditorError `CKEditorError`} is unexpected, is logged to the console, and re-thrown.
|
|
58
|
+
* * `'AbortError'` is expected and is silenced. It is thrown when the request is aborted and does not need to be handled.
|
|
59
|
+
*
|
|
60
|
+
* @returns A Promise that resolves with the AI-generated response.
|
|
61
|
+
*/
|
|
62
|
+
makeRequest(requestData: AITextAdapterRequestData): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Abstract method.
|
|
65
|
+
*
|
|
66
|
+
* Creates the request using provided `requestData`. Makes the request to the AI service endpoint. Handles the AI service response.
|
|
67
|
+
*
|
|
68
|
+
* If you want to extend an existing adapter, you can overload this method to do some additional processing or make an external call.
|
|
69
|
+
*
|
|
70
|
+
* If you want to create a custom adapter, the main logic related to making and handling the request should be implemented here.
|
|
71
|
+
* Make sure to properly implement {@link ~AITextAdapterRequestData#onData `onData()`} callback handling.
|
|
72
|
+
*/
|
|
73
|
+
abstract sendRequest(requestData: AITextAdapterRequestData): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export type AITextAdapterRequestData = {
|
|
76
|
+
/**
|
|
77
|
+
* The user's query.
|
|
78
|
+
*/
|
|
79
|
+
query: string;
|
|
80
|
+
/**
|
|
81
|
+
* The context on which the query is used.
|
|
82
|
+
*
|
|
83
|
+
* May be empty. In such case, it is assumed that the user wanted to create new textual content.
|
|
84
|
+
*/
|
|
85
|
+
context: string;
|
|
86
|
+
/**
|
|
87
|
+
* A callback that is called whenever the data received by the adapter is updated.
|
|
88
|
+
*
|
|
89
|
+
* If the adapter does not use streaming, and receives the whole answer at once, it should call `onData()` once, when the data is
|
|
90
|
+
* received.
|
|
91
|
+
*
|
|
92
|
+
* If the adapter uses streaming, the adapter should internally build the whole received data and fire `onData()` callback with the
|
|
93
|
+
* full update data each time. For example, if during streaming, the adapter receives following chunks: `'<p>T'`, `'his is an'`, and
|
|
94
|
+
* `' example</p>'`, then it should fire `onData()` with: `'<p>T'`, `'<p>This is an'`, and `'<p>This is an example</p>'`.
|
|
95
|
+
*/
|
|
96
|
+
onData: AITextAdapterDataCallback;
|
|
97
|
+
/**
|
|
98
|
+
* ID of the performed action. This is a unique ID for each feature and each action that triggers the AI request.
|
|
99
|
+
*
|
|
100
|
+
* The main role for `actionId` is to distinguish which feature made the call. The action ID can be used in extended and custom adapters
|
|
101
|
+
* to customize the request.
|
|
102
|
+
*
|
|
103
|
+
* Each AI feature describes what action IDs it creates and uses. For example, the AI Assistant feature uses `actionId` values like
|
|
104
|
+
* `'aiAssistant:custom'`, or `'aiAssistant:command:improveWriting'`.
|
|
105
|
+
*/
|
|
106
|
+
actionId: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Object with headers to set in the request to the AI service.
|
|
110
|
+
*
|
|
111
|
+
* If the provided value is an `object`, it is simply used as provided.
|
|
112
|
+
*
|
|
113
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the headers object.
|
|
114
|
+
* This way, you can perform an authorization request to your application and receive the authorization token (and also implement
|
|
115
|
+
* any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.
|
|
116
|
+
*
|
|
117
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
118
|
+
* possible to further customize the headers.
|
|
119
|
+
*
|
|
120
|
+
* If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display
|
|
121
|
+
* an error notification.
|
|
122
|
+
*/
|
|
123
|
+
export type RequestHeaders = Record<string, string> | ((actionId: string) => Promise<Record<string, string>>);
|
|
124
|
+
/**
|
|
125
|
+
* Additional configuration parameters for the AI request. Use it to customize how the AI service generates responses.
|
|
126
|
+
*
|
|
127
|
+
* See the reference for the AI service of your choice to learn what parameters can be used with that service or model.
|
|
128
|
+
*
|
|
129
|
+
* If the provided value is an `object`, it is passed to the request as provided.
|
|
130
|
+
*
|
|
131
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the request parameters
|
|
132
|
+
* object. This gives you more flexibility to provide parameters for the AI model.
|
|
133
|
+
*
|
|
134
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
135
|
+
* possible to further customize the parameters.
|
|
136
|
+
*
|
|
137
|
+
* If the function fails for any reason, the promise should be rejected. In this case, the feature that made the request should display
|
|
138
|
+
* an error notification.
|
|
139
|
+
*/
|
|
140
|
+
export type RequestParameters = Record<string, any> | ((actionId: string) => Promise<Record<string, any>>);
|
|
141
|
+
/**
|
|
142
|
+
* Callback called each time the AI text adapter receives data.
|
|
143
|
+
*
|
|
144
|
+
* @params content The received data.
|
|
145
|
+
*/
|
|
146
|
+
export type AITextAdapterDataCallback = (content: string) => any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* +---------------------------------------------------------------------------------+
|
|
8
|
+
* | |
|
|
9
|
+
* | Hello stranger! |
|
|
10
|
+
* | |
|
|
11
|
+
* | |
|
|
12
|
+
* | What you're currently looking at is the source code of a legally protected, |
|
|
13
|
+
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
|
|
14
|
+
* | are forbidden and will result in legal consequences. |
|
|
15
|
+
* | |
|
|
16
|
+
* | |
|
|
17
|
+
* +---------------------------------------------------------------------------------+
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
const _0x1815=['aitextadapter-send-request-failed','aborted','get','textAdapter','requires','assign','reject','AI_ERROR_GET_PARAMETERS','plugins','editor','locale','catch','object','error','makeRequest','application/json','_prepareRequestParameters','resolve','AI_ERROR_GET_HEADERS','abortController','name','init'];(function(_0xe0dee9,_0x181505){const _0x2a31c7=function(_0x309565){while(--_0x309565){_0xe0dee9['push'](_0xe0dee9['shift']());}};_0x2a31c7(++_0x181505);}(_0x1815,0x9f));const _0x2a31=function(_0xe0dee9,_0x181505){_0xe0dee9=_0xe0dee9-0x0;let _0x2a31c7=_0x1815[_0xe0dee9];return _0x2a31c7;};import{Plugin as _0x3ec880}from'ckeditor5/src/core';import{CKEditorError as _0x3f8600}from'ckeditor5/src/utils';import{default as _0x53b5d5,AIRequestError as _0x290c08}from'./aiadapter';import{getTranslation as _0x2cdcff}from'../utils/common-translations';export default class P extends _0x3ec880{static get[_0x2a31('0x15')](){return[_0x53b5d5];}constructor(_0x4810e1){super(_0x4810e1),this[_0x2a31('0xe')]=new AbortController();}[_0x2a31('0x10')](){this[_0x2a31('0x4')][_0x2a31('0x3')][_0x2a31('0x13')](_0x53b5d5)[_0x2a31('0x14')]=this;}['abort'](){this[_0x2a31('0xe')]['signal'][_0x2a31('0x12')]||(this[_0x2a31('0xe')]['abort'](),this['abortController']=new AbortController());}async[_0x2a31('0x9')](_0x314f9a){return this['sendRequest'](_0x314f9a)[_0x2a31('0x6')](_0x5f3688=>{if(_0x5f3688 instanceof _0x290c08)return Promise[_0x2a31('0x1')](_0x5f3688);if('AbortError'==_0x5f3688[_0x2a31('0xf')])return Promise[_0x2a31('0xc')]();throw console[_0x2a31('0x8')](_0x5f3688),new _0x3f8600(_0x2a31('0x11'),null);});}async['_prepareRequestHeaders'](_0x5a420e,_0x1c601b){const _0x4b5f79=this[_0x2a31('0x4')][_0x2a31('0x5')],_0xf03070={'Content-Type':_0x2a31('0xa')};if(_0x2a31('0x7')==typeof _0x5a420e)Object[_0x2a31('0x0')](_0xf03070,_0x5a420e);else{if(_0x5a420e)try{const _0x367809=await _0x5a420e(_0x1c601b);Object[_0x2a31('0x0')](_0xf03070,_0x367809);}catch(_0x512424){return Promise[_0x2a31('0x1')](new _0x290c08(_0x2cdcff(_0x4b5f79,_0x2a31('0xd'))));}}return _0xf03070;}async[_0x2a31('0xb')](_0xc1484c,_0x3704a3){const _0x135dcd=this['editor'][_0x2a31('0x5')];if(_0x2a31('0x7')==typeof _0xc1484c)return _0xc1484c;try{return await _0xc1484c(_0x3704a3);}catch(_0x16787a){return Promise[_0x2a31('0x1')](new _0x290c08(_0x2cdcff(_0x135dcd,_0x2a31('0x2'))));}}}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module ai/adapters/awstextadapter
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
import { type Editor } from 'ckeditor5/src/core';
|
|
10
|
+
import { default as AITextAdapter, type AITextAdapterRequestData, type RequestHeaders, type RequestParameters } from './aitextadapter';
|
|
11
|
+
import { type BedrockRuntimeClientConfig } from '@aws-sdk/client-bedrock-runtime';
|
|
12
|
+
/**
|
|
13
|
+
* Adapter for AI text-related requests that supports AWS Bedrock service.
|
|
14
|
+
*
|
|
15
|
+
* See also {@link module:ai/adapters/aitextadapter~AITextAdapter}.
|
|
16
|
+
*/
|
|
17
|
+
export default class AWSTextAdapter extends AITextAdapter {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get pluginName(): "AWSTextAdapter";
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
constructor(editor: Editor);
|
|
26
|
+
/**
|
|
27
|
+
* Performs the request to the AWS Bedrock service or to the endpoint provided in the editor configuration.
|
|
28
|
+
*
|
|
29
|
+
* If you want to extend this adapter, you can overload this method to do some additional processing or make an external call.
|
|
30
|
+
*/
|
|
31
|
+
sendRequest({ query, context, onData, actionId }: AITextAdapterRequestData): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Prepares the actual full prompt for the request to the AWS Bedrock API.
|
|
34
|
+
*
|
|
35
|
+
* The prompt may differ depending on what model is used.
|
|
36
|
+
*
|
|
37
|
+
* You can overload this method to customize the prompts that are sent to the AI service.
|
|
38
|
+
*
|
|
39
|
+
* @param query The user's query. The instruction which the model should perform.
|
|
40
|
+
* @param context The context for the instruction. Usually this will be a part of the editor content. Can be empty.
|
|
41
|
+
* @param model Model that is used to perform the request.
|
|
42
|
+
* @param actionId ID of the performed action. See {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId}.
|
|
43
|
+
*/
|
|
44
|
+
preparePrompt(query: string, context: string, model: string, actionId: string): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* For given `model`, returns the family to which this model belongs.
|
|
47
|
+
*
|
|
48
|
+
* For example, for `anthropic.claude-instant-v1` will return `anthropic.claude`.
|
|
49
|
+
*
|
|
50
|
+
* Throws {@link module:ai/adapters/aiadapter~AIRequestError `AIRequestError`} if given `model` is not supported.
|
|
51
|
+
*/
|
|
52
|
+
getModelFamily(model: string): AWSModelFamily;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The configuration for the AWS Bedrock adapter.
|
|
56
|
+
*
|
|
57
|
+
* The properties defined in this config are set in the `config.ai.aws` namespace.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* ClassicEditor
|
|
61
|
+
* .create( editorElement, {
|
|
62
|
+
* ai: {
|
|
63
|
+
* aws: {
|
|
64
|
+
* apiUrl: 'https://url.to.your.application/ai'
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* } )
|
|
68
|
+
* .then( ... )
|
|
69
|
+
* .catch( ... );
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* See {@link module:ai/aiconfig~AIConfig the full AI configuration}.
|
|
73
|
+
*
|
|
74
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
75
|
+
*/
|
|
76
|
+
export interface AWSTextAdapterConfig {
|
|
77
|
+
/**
|
|
78
|
+
* The URL to which the AI service request will be sent.
|
|
79
|
+
*
|
|
80
|
+
* Set this value only if you want to connect to AWS Bedrock using a proxy endpoint.
|
|
81
|
+
*
|
|
82
|
+
* If `apiUrl` is not provided, the AWS-SDK library will be used to process the request. It will set a proper URL on its own.
|
|
83
|
+
*/
|
|
84
|
+
apiUrl?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Object with headers to set in the request to the AI service.
|
|
87
|
+
*
|
|
88
|
+
* **These headers are only used when connecting to AWS through the proxy endpoint (i.e. when `apiUrl` is set).**
|
|
89
|
+
*
|
|
90
|
+
* Otherwise, AWS-SDK library is used, and it sets the request headers on its own. In this mode, the request headers cannot be
|
|
91
|
+
* customized.
|
|
92
|
+
*
|
|
93
|
+
* If the provided value is an `object`, it is simply used as provided.
|
|
94
|
+
*
|
|
95
|
+
* ```js
|
|
96
|
+
* {
|
|
97
|
+
* ai: {
|
|
98
|
+
* aws: {
|
|
99
|
+
* requestHeaders: {
|
|
100
|
+
* 'Authorization': 'Bearer YOUR_API_KEY'
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
* // ...
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the headers object.
|
|
109
|
+
* This way, you can perform an authorization request to your application and receive the authorization token (and also implement
|
|
110
|
+
* any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.
|
|
111
|
+
*
|
|
112
|
+
* ```js
|
|
113
|
+
* {
|
|
114
|
+
* ai: {
|
|
115
|
+
* aws: {
|
|
116
|
+
* requestHeaders: async () => {
|
|
117
|
+
* const jwt = await fetch( 'https://example.com/jwt-endpoint' );
|
|
118
|
+
*
|
|
119
|
+
* return {
|
|
120
|
+
* 'Authorization': 'Bearer ' + jwt
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
* // ...
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
130
|
+
* possible to further customize the headers.
|
|
131
|
+
*
|
|
132
|
+
* If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display
|
|
133
|
+
* an error notification.
|
|
134
|
+
*/
|
|
135
|
+
requestHeaders?: RequestHeaders;
|
|
136
|
+
/**
|
|
137
|
+
* Additional configuration parameters for the AI service request. Use it to customize how the AI service generates responses.
|
|
138
|
+
*
|
|
139
|
+
* The exact configuration (available parameters) depends on the used model. Keep in mind that some properties are not supported by some
|
|
140
|
+
* models.
|
|
141
|
+
*
|
|
142
|
+
* See [AWS model parameters reference](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html) to learn more.
|
|
143
|
+
*
|
|
144
|
+
* If the provided value is an `object`, it is passed to the request as provided.
|
|
145
|
+
*
|
|
146
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the request parameters
|
|
147
|
+
* object. This gives you more flexibility to provide parameters for the AI model.
|
|
148
|
+
*
|
|
149
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
150
|
+
* possible to further customize the parameters.
|
|
151
|
+
*
|
|
152
|
+
* If the function fails for any reason, the promise should be rejected. In this case, the feature that made the request should display
|
|
153
|
+
* an error notification.
|
|
154
|
+
*
|
|
155
|
+
* Defaults to:
|
|
156
|
+
*
|
|
157
|
+
* ```json
|
|
158
|
+
* {
|
|
159
|
+
* model: 'anthropic.claude-v2',
|
|
160
|
+
* max_tokens_to_sample: 500,
|
|
161
|
+
* temperature: 1,
|
|
162
|
+
* top_k: 250,
|
|
163
|
+
* top_p: 1,
|
|
164
|
+
* anthropic_version: 'bedrock-2023-05-31',
|
|
165
|
+
* stream: true
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
requestParameters?: RequestParameters;
|
|
170
|
+
/**
|
|
171
|
+
* Configuration for AWS-SDK Bedrock Runtime Client.
|
|
172
|
+
*
|
|
173
|
+
* If `apiUrl` is not provided, this configuration will be used to initialize the Bedrock Runtime Client which will be used to process
|
|
174
|
+
* the requests. The adapter will make requests directly to the AWS Bedrock service.
|
|
175
|
+
*/
|
|
176
|
+
bedrockClientConfig?: BedrockRuntimeClientConfig;
|
|
177
|
+
}
|
|
178
|
+
export type AWSModelFamily = 'anthropic.claude' | 'ai21.j2' | 'cohere.command' | 'meta.llama';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* +---------------------------------------------------------------------------------+
|
|
8
|
+
* | |
|
|
9
|
+
* | Hello stranger! |
|
|
10
|
+
* | |
|
|
11
|
+
* | |
|
|
12
|
+
* | What you're currently looking at is the source code of a legally protected, |
|
|
13
|
+
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
|
|
14
|
+
* | are forbidden and will result in legal consequences. |
|
|
15
|
+
* | |
|
|
16
|
+
* | |
|
|
17
|
+
* +---------------------------------------------------------------------------------+
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
const _0x4e44=['signal','ai.aws.requestParameters.anthropic_version','ai.aws.requestParameters.top_k','sendRequest','from','_readStreamableResponse','decode','getReader','_prepareRequestParameters','locale','text','_requestParameters','body','ai.aws.apiUrl','ai21.j2','ai.aws.bedrockClientConfig','_apiUrl','utf-8','\x0a[/INST]','_requestHeaders','\x0a\x0aAssistant:','Human:\x0a','preparePrompt','editor','send','data','Your\x20task\x20is\x20to\x20generate\x20HTML\x20content\x20accordingly\x20to\x20the\x20given\x20instruction.\x20Never\x20include\x20<img>\x20tag\x20in\x20your\x20response\x20even\x20if\x20asked\x20for.\x20Your\x20answer\x20must\x20be\x20a\x20well-structured\x20and\x20properly\x20formatted\x20HTML\x20code.\x20Answer\x20only\x20with\x20the\x20generated\x20HTML\x20content.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.','cohere.command','_bedrockClientConfig','test','define','_processProxyRequest','bytes','abortController','ai.aws.requestParameters','_cleanUpData','chunk','Instruction:\x0a','meta.llama','get','bedrock-2023-05-31','_readStaticResponse','ai.aws.requestParameters.model','read','application/json','_processAWSRequest','Your\x20task\x20is\x20to\x20execute\x20the\x20instruction\x20using\x20the\x20provided\x20HTML\x20content.\x20Follow\x20the\x20instruction\x20closely.\x20Your\x20answer\x20must\x20be\x20a\x20properly\x20formatted\x20HTML\x20code.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.','completion','generation','<<SYS>>\x0a','AWSTextAdapter','utf8','ai.aws.requestParameters.stream','ai.aws.requestHeaders','config','startsWith','completions','parse','generations','ai.aws.requestParameters.max_tokens_to_sample','\x0a<</SYS>>\x0a[INST]\x0a','json','ai.aws.requestParameters.top_p','</span>','<span>','_readAsyncIterableResponse','resolve','getModelFamily','stringify'];(function(_0x4d8f66,_0x4e44b2){const _0x55e7ba=function(_0x7434cf){while(--_0x7434cf){_0x4d8f66['push'](_0x4d8f66['shift']());}};_0x55e7ba(++_0x4e44b2);}(_0x4e44,0x1aa));const _0x55e7=function(_0x4d8f66,_0x4e44b2){_0x4d8f66=_0x4d8f66-0x0;let _0x55e7ba=_0x4e44[_0x4d8f66];return _0x55e7ba;};import{default as _0x25bbce}from'./aitextadapter';import{AIRequestError as _0x596325}from'./aiadapter';import{BedrockRuntimeClient as _0x436082,InvokeModelCommand as _0x2a0295,InvokeModelWithResponseStreamCommand as _0x3209c0}from'@aws-sdk/client-bedrock-runtime';import{getTranslation as _0x41c689}from'../utils/common-translations';export default class H extends _0x25bbce{static get['pluginName'](){return _0x55e7('0x26');}constructor(_0x3c349d){super(_0x3c349d),_0x3c349d['config'][_0x55e7('0x1b')](_0x55e7('0x16'))||(_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x12')](_0x55e7('0x1e'),'anthropic.claude-v2'),_0x3c349d[_0x55e7('0x2a')]['define'](_0x55e7('0x2f'),0x7d0),_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x12')]('ai.aws.requestParameters.temperature',0x1),_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x12')](_0x55e7('0x32'),0x1),_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x12')](_0x55e7('0x3b'),0xfa),_0x3c349d['config'][_0x55e7('0x12')](_0x55e7('0x3a'),_0x55e7('0x1c')),_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x12')](_0x55e7('0x28'),!0x0)),this[_0x55e7('0x4')]=_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x1b')](_0x55e7('0x1')),this['_bedrockClientConfig']=_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x1b')](_0x55e7('0x3')),this[_0x55e7('0x7')]=_0x3c349d['config']['get'](_0x55e7('0x29')),this[_0x55e7('0x44')]=_0x3c349d[_0x55e7('0x2a')][_0x55e7('0x1b')]('ai.aws.requestParameters');}async[_0x55e7('0x3c')]({query:_0x280baf,context:_0xabe2cb,onData:_0x38e37,actionId:_0x2d8bc4}){const {model:_0x2f32dc,stream:_0x2aa8f7,..._0x447459}=await this[_0x55e7('0x41')](this[_0x55e7('0x44')],_0x2d8bc4),_0x15170a={'prompt':await this[_0x55e7('0xa')](_0x280baf,_0xabe2cb,_0x2f32dc,_0x2d8bc4),..._0x447459};this[_0x55e7('0x4')]?await this[_0x55e7('0x13')](_0x15170a,_0x2f32dc,_0x2aa8f7,_0x38e37,_0x2d8bc4):await this[_0x55e7('0x21')](_0x15170a,_0x2f32dc,_0x2aa8f7,_0x38e37);}async[_0x55e7('0xa')](_0x4e4cb6,_0x27e3cc,_0x2c06c7,_0x2796fe){let _0x5e817f,_0x336034;return _0x27e3cc?(_0x5e817f=_0x55e7('0x22'),_0x336034=_0x55e7('0x19')+_0x4e4cb6+'\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a'+(_0x27e3cc[_0x55e7('0x2b')]('<')?_0x27e3cc:_0x55e7('0x34')+_0x27e3cc+_0x55e7('0x33'))):(_0x5e817f=_0x55e7('0xe'),_0x336034=_0x4e4cb6),_0x55e7('0x1a')==this['getModelFamily'](_0x2c06c7)?_0x55e7('0x25')+_0x5e817f+_0x55e7('0x30')+_0x336034+_0x55e7('0x6'):_0x55e7('0x9')+_0x5e817f+'\x0a'+_0x336034+_0x55e7('0x8');}[_0x55e7('0x37')](_0x4df8f7){if(/^anthropic\.claude/['test'](_0x4df8f7))return'anthropic.claude';if(/^ai21\.j2/[_0x55e7('0x11')](_0x4df8f7))return _0x55e7('0x2');if(/^cohere\.command/[_0x55e7('0x11')](_0x4df8f7))return _0x55e7('0xf');if(/^meta\.llama/[_0x55e7('0x11')](_0x4df8f7))return _0x55e7('0x1a');throw new _0x596325(_0x41c689(this[_0x55e7('0xb')][_0x55e7('0x42')],'AI_ERROR_UNSUPPORTED_MODEL',_0x4df8f7));}async[_0x55e7('0x13')](_0xbfc1fe,_0x52ff12,_0x2cea8a,_0x49c904,_0x6a68c5){const _0x3d4441={'method':'POST','headers':await this['_prepareRequestHeaders'](this[_0x55e7('0x7')],_0x6a68c5),'body':JSON[_0x55e7('0x38')]({..._0xbfc1fe,'model':_0x52ff12,'stream':_0x2cea8a}),'signal':this[_0x55e7('0x15')][_0x55e7('0x39')]},_0x347f4f=await fetch(this[_0x55e7('0x4')],_0x3d4441);_0x2cea8a?await this[_0x55e7('0x3e')](_0x347f4f,_0x52ff12,_0x49c904):await this[_0x55e7('0x1d')](_0x347f4f,_0x52ff12,_0x49c904);}async[_0x55e7('0x21')](_0x579636,_0x4f4184,_0x4219f8,_0x32decb){const _0x55521a=new _0x436082(this[_0x55e7('0x10')]),_0x242860={'body':JSON[_0x55e7('0x38')](_0x579636),'contentType':'application/json','accept':_0x55e7('0x20'),'modelId':_0x4f4184};let _0x34ec7c;if(_0x4219f8){const _0x5eb774=new _0x3209c0(_0x242860);_0x34ec7c=await _0x55521a['send'](_0x5eb774,{'abortSignal':this[_0x55e7('0x15')][_0x55e7('0x39')]}),await this[_0x55e7('0x35')](_0x34ec7c,_0x4f4184,_0x32decb);}else{const _0x9fd913=new _0x2a0295(_0x242860);_0x34ec7c=await _0x55521a[_0x55e7('0xc')](_0x9fd913,{'abortSignal':this[_0x55e7('0x15')]['signal']}),await this[_0x55e7('0x1d')](_0x34ec7c,_0x4f4184,_0x32decb);}}async[_0x55e7('0x35')](_0x2e8305,_0x23f610,_0x84720d){const _0x5ebc2a=_0x2e8305[_0x55e7('0x0')],_0x2be7a3=(_0x5ebc2a[Symbol['asyncIterator']](),new TextDecoder('utf-8'));let _0x50f02b='';for await(const _0x102488 of _0x5ebc2a)if(_0x102488['chunk']){const _0x43cbec=_0x2be7a3[_0x55e7('0x3f')](_0x102488[_0x55e7('0x18')][_0x55e7('0x14')]),_0x50779c=JSON[_0x55e7('0x2d')](_0x43cbec);_0x50f02b+=this[_0x55e7('0x17')](_0x50779c,_0x23f610),_0x84720d(_0x50f02b);}return Promise[_0x55e7('0x36')]();}async[_0x55e7('0x3e')](_0x5202e0,_0x3c8c02,_0x302bcf){const _0x5c4b7e=_0x5202e0['body'],_0x46945a=new TextDecoder(_0x55e7('0x5'));let _0x15311c='';const _0x523f89=_0x5c4b7e[_0x55e7('0x40')]();let _0x52cbb9=!0x1;for(;!_0x52cbb9;){const {done:_0x4dc4f3,value:_0x25c9a0}=await _0x523f89[_0x55e7('0x1f')]();if(_0x52cbb9=_0x4dc4f3,_0x52cbb9)break;const _0x545974=_0x46945a[_0x55e7('0x3f')](_0x25c9a0),_0xed12d8=JSON[_0x55e7('0x2d')](_0x545974);_0x15311c+=this[_0x55e7('0x17')](_0xed12d8,_0x3c8c02),_0x302bcf(_0x15311c);}return Promise[_0x55e7('0x36')]();}async['_readStaticResponse'](_0x2f19e5,_0x14df5d,_0xc54ca){let _0x574d93;return _0x574d93=_0x2f19e5 instanceof Response?await _0x2f19e5[_0x55e7('0x31')]():JSON[_0x55e7('0x2d')](Buffer[_0x55e7('0x3d')](_0x2f19e5[_0x55e7('0x0')])['toString'](_0x55e7('0x27'))),(_0xc54ca(this[_0x55e7('0x17')](_0x574d93,_0x14df5d)),Promise[_0x55e7('0x36')]());}[_0x55e7('0x17')](_0x1ad77d,_0x5bf695){switch(this['getModelFamily'](_0x5bf695)){case'anthropic.claude':return _0x1ad77d[_0x55e7('0x23')];case _0x55e7('0x2'):return _0x1ad77d[_0x55e7('0x2c')][0x0][_0x55e7('0xd')][_0x55e7('0x43')];case'cohere.command':return _0x1ad77d[_0x55e7('0x2e')][0x0][_0x55e7('0x43')];case _0x55e7('0x1a'):return _0x1ad77d[_0x55e7('0x24')];}}}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module ai/adapters/openaitextadapter
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
import { type Editor } from 'ckeditor5/src/core';
|
|
10
|
+
import { default as AITextAdapter, type AITextAdapterRequestData, type RequestHeaders, type RequestParameters } from './aitextadapter';
|
|
11
|
+
/**
|
|
12
|
+
* Adapter for AI text-related requests that supports OpenAI and Azure OpenAI services.
|
|
13
|
+
*
|
|
14
|
+
* See also {@link module:ai/adapters/aitextadapter~AITextAdapter}.
|
|
15
|
+
*/
|
|
16
|
+
export default class OpenAITextAdapter extends AITextAdapter {
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static get pluginName(): "OpenAITextAdapter";
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
constructor(editor: Editor);
|
|
25
|
+
/**
|
|
26
|
+
* Performs the request to the OpenAI service, Azure OpenAI service, or to the endpoint provided in the editor configuration.
|
|
27
|
+
*
|
|
28
|
+
* If you want to extend this adapter, you can overload this method to do some additional processing or make an external call.
|
|
29
|
+
*/
|
|
30
|
+
sendRequest({ query, context, onData, actionId }: AITextAdapterRequestData): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Prepares the actual request messages to be sent as a part of the request to the AI service.
|
|
33
|
+
*
|
|
34
|
+
* See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more.
|
|
35
|
+
*
|
|
36
|
+
* This method returns two messages, one "system message" with general instructions for the model and one "user message"
|
|
37
|
+
* with the actual instruction to perform.
|
|
38
|
+
*
|
|
39
|
+
* The messages are different, based on whether there is any `context` provided. If no `context` is provided, it is assumed that
|
|
40
|
+
* the user wants to generate new content. If `context` is provided, it is assumed that the user wants to process this `context`
|
|
41
|
+
* (e.g. translate) or generate something based on `context` (e.g. summary).
|
|
42
|
+
*
|
|
43
|
+
* You can overload this method to customize the messages that are sent to the AI service.
|
|
44
|
+
*
|
|
45
|
+
* @param query The user's query. The instruction which the model should perform.
|
|
46
|
+
* @param context The context for the instruction. Usually this will be a part of the editor content. Can be empty.
|
|
47
|
+
* @param actionId ID of the performed action. See {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId}.
|
|
48
|
+
*/
|
|
49
|
+
prepareMessages(query: string, context: string, actionId: string): Promise<Array<RequestMessageItem>>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The configuration for the OpenAI adapter.
|
|
53
|
+
*
|
|
54
|
+
* The properties defined in this config are set in the `config.ai.openAI` namespace.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* ClassicEditor
|
|
58
|
+
* .create( editorElement, {
|
|
59
|
+
* ai: {
|
|
60
|
+
* openAI: {
|
|
61
|
+
* requestHeaders: {
|
|
62
|
+
* Authorization: 'Bearer OPENAI_API_KEY'
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* } )
|
|
67
|
+
* .then( ... )
|
|
68
|
+
* .catch( ... );
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* See {@link module:ai/aiconfig~AIConfig the full AI configuration}.
|
|
72
|
+
*
|
|
73
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
74
|
+
*/
|
|
75
|
+
export interface OpenAITextAdapterConfig {
|
|
76
|
+
/**
|
|
77
|
+
* The URL to which the AI service request will be sent.
|
|
78
|
+
*
|
|
79
|
+
* By default, requests are sent to the OpenAI API service. Change this value to make requests to Azure OpenAI API or use proxy endpoint
|
|
80
|
+
* in your application instead.
|
|
81
|
+
*
|
|
82
|
+
* Defaults to `'https://api.openai.com/v1/chat/completions'`.
|
|
83
|
+
*/
|
|
84
|
+
apiUrl?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Object with headers to set in the request to the AI service API.
|
|
87
|
+
*
|
|
88
|
+
* If the provided value is an `object`, it is simply used as provided.
|
|
89
|
+
*
|
|
90
|
+
* If you are connecting directly to the OpenAI API, use your OpenAI API key in the following way:
|
|
91
|
+
*
|
|
92
|
+
* ```js
|
|
93
|
+
* {
|
|
94
|
+
* ai: {
|
|
95
|
+
* openAI: {
|
|
96
|
+
* requestHeaders: {
|
|
97
|
+
* 'Authorization': 'Bearer YOUR_API_KEY'
|
|
98
|
+
* }
|
|
99
|
+
* // ...
|
|
100
|
+
* }
|
|
101
|
+
* // ..
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* **Important: use your API key ONLY in a development environment or for testing purposes!**
|
|
107
|
+
* In the production environment, pass your request through a proxy endpoint.
|
|
108
|
+
*
|
|
109
|
+
* If you are using a proxy service to send requests to the OpenAI API, `requestHeaders` can be used to implement authorization for your
|
|
110
|
+
* requests.
|
|
111
|
+
*
|
|
112
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the headers object.
|
|
113
|
+
* This way, you can perform an authorization request to your application and receive the authorization token (and also implement
|
|
114
|
+
* any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.
|
|
115
|
+
*
|
|
116
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
117
|
+
* possible to further customize the headers.
|
|
118
|
+
*
|
|
119
|
+
* ```js
|
|
120
|
+
* {
|
|
121
|
+
* ai: {
|
|
122
|
+
* openAI: {
|
|
123
|
+
* requestHeaders: async () => {
|
|
124
|
+
* const jwt = await fetch( 'https://example.com/jwt-endpoint' );
|
|
125
|
+
*
|
|
126
|
+
* return {
|
|
127
|
+
* 'Authorization': 'Bearer ' + jwt
|
|
128
|
+
* };
|
|
129
|
+
* }
|
|
130
|
+
* // ...
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display
|
|
137
|
+
* an error notification.
|
|
138
|
+
*/
|
|
139
|
+
requestHeaders?: RequestHeaders;
|
|
140
|
+
/**
|
|
141
|
+
* Additional configuration parameters for the AI service request. Use it to customize how the AI service generates responses.
|
|
142
|
+
*
|
|
143
|
+
* See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more about available parameters.
|
|
144
|
+
*
|
|
145
|
+
* If the provided value is an `object`, it is passed to the request as provided.
|
|
146
|
+
*
|
|
147
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the request parameters
|
|
148
|
+
* object. This gives you more flexibility to provide parameters for the AI model.
|
|
149
|
+
*
|
|
150
|
+
* The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
|
|
151
|
+
* possible to further customize the parameters.
|
|
152
|
+
*
|
|
153
|
+
* If the function fails for any reason, the promise should be rejected. In this case, the feature that made the request should display
|
|
154
|
+
* an error notification.
|
|
155
|
+
*
|
|
156
|
+
* Defaults to:
|
|
157
|
+
*
|
|
158
|
+
* ```json
|
|
159
|
+
* {
|
|
160
|
+
* model: 'gpt-3.5-turbo',
|
|
161
|
+
* max_tokens: 2000,
|
|
162
|
+
* temperature: 1,
|
|
163
|
+
* top_p: 1
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
requestParameters?: RequestParameters;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Single message item, in the format required for the OpenAI request.
|
|
171
|
+
*
|
|
172
|
+
* Example:
|
|
173
|
+
*
|
|
174
|
+
* ```json
|
|
175
|
+
* { role: 'system', content: 'You are a helpful assistant.' }
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more.
|
|
179
|
+
*/
|
|
180
|
+
type RequestMessageItem = Record<string, string>;
|
|
181
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* +---------------------------------------------------------------------------------+
|
|
8
|
+
* | |
|
|
9
|
+
* | Hello stranger! |
|
|
10
|
+
* | |
|
|
11
|
+
* | |
|
|
12
|
+
* | What you're currently looking at is the source code of a legally protected, |
|
|
13
|
+
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
|
|
14
|
+
* | are forbidden and will result in legal consequences. |
|
|
15
|
+
* | |
|
|
16
|
+
* | |
|
|
17
|
+
* +---------------------------------------------------------------------------------+
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
const _0x167a=['prepareMessages','ai.openAI.requestHeaders','AI_ERROR_CONTEXT_LENGTH','filter','POST','_prepareRequestHeaders','_cleanUpData','split','length','_requestParameters','Your\x20task\x20is\x20to\x20generate\x20HTML\x20content\x20accordingly\x20to\x20the\x20given\x20instruction.\x20Never\x20include\x20<img>\x20tag\x20in\x20your\x20response\x20even\x20if\x20asked\x20for.\x20Your\x20answer\x20must\x20be\x20a\x20well-structured\x20and\x20properly\x20formatted\x20HTML\x20code.\x20Answer\x20only\x20with\x20the\x20generated\x20HTML\x20content.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.','get','_readStreamableResponse','_apiUrl','_isBufferIncomplete','ai.openAI.requestParameters.top_p','delta','_readStaticResponse','choices','user','getReader','read','signal','reject','ai.openAI.requestParameters.temperature','content','config','includes','context_length_exceeded','sendRequest','[DONE]','</span>','text','resolve','editor','_requestHeaders','stream','define','parse','Instruction:\x0a','locale','json','gpt-3.5-turbo','pluginName','system','abortController','ai.openAI.apiUrl'];(function(_0x5ed576,_0x167a22){const _0xd3c009=function(_0x2302b0){while(--_0x2302b0){_0x5ed576['push'](_0x5ed576['shift']());}};_0xd3c009(++_0x167a22);}(_0x167a,0x1f2));const _0xd3c0=function(_0x5ed576,_0x167a22){_0x5ed576=_0x5ed576-0x0;let _0xd3c009=_0x167a[_0x5ed576];return _0xd3c009;};import{default as _0x34e1f6}from'./aitextadapter';import{AIRequestError as _0xc9f95f}from'./aiadapter';import{getTranslation as _0x556c66}from'../utils/common-translations';export default class M extends _0x34e1f6{static get[_0xd3c0('0xf')](){return'OpenAITextAdapter';}constructor(_0x182769){super(_0x182769),_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x9')](_0xd3c0('0x12'),'https://api.openai.com/v1/chat/completions'),_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x9')]('ai.openAI.requestParameters.model',_0xd3c0('0xe')),_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x9')]('ai.openAI.requestParameters.max_tokens',0x7d0),_0x182769[_0xd3c0('0x2d')]['define'](_0xd3c0('0x2b'),0x1),_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x9')](_0xd3c0('0x22'),0x1),_0x182769[_0xd3c0('0x2d')]['define']('ai.openAI.requestParameters.stream',!0x0),this[_0xd3c0('0x20')]=_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x1e')]('ai.openAI.apiUrl'),this[_0xd3c0('0x7')]=_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x1e')](_0xd3c0('0x14'))||{},this[_0xd3c0('0x1c')]=_0x182769[_0xd3c0('0x2d')][_0xd3c0('0x1e')]('ai.openAI.requestParameters');}async[_0xd3c0('0x1')]({query:_0x1d319c,context:_0x56bb43,onData:_0x56bd9c,actionId:_0x378a60}){const _0x14f400=this[_0xd3c0('0x6')][_0xd3c0('0xc')],_0x1210a1=await this[_0xd3c0('0x13')](_0x1d319c,_0x56bb43,_0x378a60),_0x1d082f=await this[_0xd3c0('0x18')](this['_requestHeaders'],_0x378a60),_0x3f454e=await this['_prepareRequestParameters'](this['_requestParameters'],_0x378a60),_0x258b54={'messages':_0x1210a1,..._0x3f454e},_0x1a838f={'method':_0xd3c0('0x17'),'headers':_0x1d082f,'body':JSON['stringify'](_0x258b54),'signal':this[_0xd3c0('0x11')][_0xd3c0('0x29')]},_0x216d4e=await fetch(this[_0xd3c0('0x20')],_0x1a838f);if(_0x216d4e['ok'])return _0x3f454e[_0xd3c0('0x8')]?await this[_0xd3c0('0x1f')](_0x216d4e,_0x56bd9c):await this[_0xd3c0('0x24')](_0x216d4e,_0x56bd9c),Promise[_0xd3c0('0x5')]();{const _0x478e6d=await _0x216d4e[_0xd3c0('0x4')]();return _0x478e6d['includes'](_0xd3c0('0x0'))?Promise['reject'](new _0xc9f95f(_0x556c66(_0x14f400,_0xd3c0('0x15')))):_0x478e6d[_0xd3c0('0x2e')]('Moderation')?Promise[_0xd3c0('0x2a')](new _0xc9f95f(_0x556c66(_0x14f400,'AI_ERROR_MODERATION'))):Promise[_0xd3c0('0x2a')](new Error(_0x478e6d));}}async[_0xd3c0('0x13')](_0x1a4332,_0x4d1628,_0x2d16e9){let _0x11ae76,_0x56696f;return _0x4d1628?(_0x11ae76='Your\x20task\x20is\x20to\x20execute\x20the\x20instruction\x20using\x20the\x20provided\x20HTML\x20content.\x20Follow\x20the\x20instruction\x20closely.\x20Your\x20answer\x20must\x20be\x20a\x20properly\x20formatted\x20HTML\x20code.\x20Do\x20not\x20add\x20any\x20additional\x20remarks\x20or\x20notes.\x20Do\x20not\x20act\x20like\x20a\x20chatbot\x20or\x20a\x20real\x20person.',_0x56696f=_0xd3c0('0xb')+_0x1a4332+'\x0aYou\x20must\x20keep\x20the\x20text\x20formatting.\x0a\x0aContent:\x0a'+(_0x4d1628['startsWith']('<')?_0x4d1628:'<span>'+_0x4d1628+_0xd3c0('0x3'))):(_0x11ae76=_0xd3c0('0x1d'),_0x56696f=_0x1a4332),[{'role':_0xd3c0('0x10'),'content':_0x11ae76},{'role':_0xd3c0('0x26'),'content':_0x56696f}];}async[_0xd3c0('0x1f')](_0xe917c5,_0xfb6860){const _0x12c2cd=_0xe917c5['body'][_0xd3c0('0x27')](),_0x3e9b4c=new TextDecoder();let _0x11e726='',_0x5eaa34='',_0xe619ac='',_0x32fcc6=!0x1;for(;!_0x32fcc6;){const {done:_0x22380a,value:_0x5e6813}=await _0x12c2cd[_0xd3c0('0x28')](),_0xfb20e2=_0x11e726+_0x3e9b4c['decode'](_0x5e6813);let _0xbc6030='';_0x32fcc6=_0x22380a;try{_0xbc6030=this[_0xd3c0('0x19')](_0xfb20e2),_0x11e726='';}catch(_0x2f204e){_0x11e726=_0xfb20e2;continue;}_0x5eaa34+=_0xbc6030,!_0x32fcc6&&this[_0xd3c0('0x21')](_0x5eaa34)||_0x5eaa34&&(_0xe619ac+=_0x5eaa34,_0x5eaa34='',_0xfb6860(_0xe619ac));}return Promise['resolve']();}async[_0xd3c0('0x24')](_0x2f7c06,_0x379fa7){return _0x379fa7((await _0x2f7c06[_0xd3c0('0xd')]())[_0xd3c0('0x25')][0x0]['message'][_0xd3c0('0x2c')]),Promise[_0xd3c0('0x5')]();}[_0xd3c0('0x21')](_0x2b267d){const _0x3c85a2=_0x2b267d[_0xd3c0('0x1a')]('<')[_0xd3c0('0x1b')]!==_0x2b267d[_0xd3c0('0x1a')]('>')[_0xd3c0('0x1b')],_0x11271c=_0x2b267d[_0xd3c0('0x1b')]<0x1e;return _0x3c85a2&&_0x11271c;}[_0xd3c0('0x19')](_0x568390){return _0x568390[_0xd3c0('0x1a')](/\n(?![^{]*\})/g)['map'](_0x3e666b=>_0x3e666b['replace']('data:\x20',''))[_0xd3c0('0x16')](_0x31d13b=>_0x31d13b&&_0x31d13b[_0xd3c0('0x1b')]>0x0&&_0xd3c0('0x2')!==_0x31d13b)['map'](_0x11fb0f=>{const {choices:_0x234a5c}=JSON[_0xd3c0('0xa')](_0x11fb0f);if(_0x234a5c[0x0]&&_0x234a5c[0x0][_0xd3c0('0x23')]&&_0x234a5c[0x0]['delta'][_0xd3c0('0x2c')])return _0x234a5c[0x0][_0xd3c0('0x23')]['content'];})[_0xd3c0('0x16')](_0x4da758=>_0x4da758)['join']('');}}
|