@promptbook/openai 0.103.0-35 → 0.103.0-37
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/esm/index.es.js +114 -1
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +5 -1
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +4 -0
- package/esm/typings/src/book-components/_common/Tooltip/Tooltip.d.ts +47 -0
- package/esm/typings/src/errors/0-index.d.ts +3 -0
- package/esm/typings/src/errors/NotAllowed.d.ts +9 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +1 -0
- package/esm/typings/src/execution/Executables.d.ts +3 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +5 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +44 -0
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +17 -0
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +16 -0
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -15
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +12 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +7 -1
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -0
- package/esm/typings/src/types/Updatable.d.ts +19 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +114 -1
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
19
19
|
* @generated
|
|
20
20
|
* @see https://github.com/webgptorg/promptbook
|
|
21
21
|
*/
|
|
22
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-37';
|
|
23
23
|
/**
|
|
24
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
25
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -65,6 +65,19 @@ const $isRunningInWebWorker = new Function(`
|
|
|
65
65
|
* TODO: [🎺]
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* This error indicates that promptbook operation is not allowed
|
|
70
|
+
*
|
|
71
|
+
* @public exported from `@promptbook/core`
|
|
72
|
+
*/
|
|
73
|
+
class NotAllowed extends Error {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.name = 'NotAllowed';
|
|
77
|
+
Object.setPrototypeOf(this, NotAllowed.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
/**
|
|
69
82
|
* This error type indicates that some part of the code is not implemented yet
|
|
70
83
|
*
|
|
@@ -3622,11 +3635,18 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3622
3635
|
* @param options which are relevant are directly passed to the OpenAI client
|
|
3623
3636
|
*/
|
|
3624
3637
|
constructor(options) {
|
|
3638
|
+
var _a;
|
|
3625
3639
|
if (options.isProxied) {
|
|
3626
3640
|
throw new NotYetImplementedError(`Proxy mode is not yet implemented for OpenAI assistants`);
|
|
3627
3641
|
}
|
|
3628
3642
|
super(options);
|
|
3643
|
+
this.isCreatingNewAssistantsAllowed = false;
|
|
3629
3644
|
this.assistantId = options.assistantId;
|
|
3645
|
+
this.isCreatingNewAssistantsAllowed = (_a = options.isCreatingNewAssistantsAllowed) !== null && _a !== void 0 ? _a : false;
|
|
3646
|
+
if (this.assistantId === null && !this.isCreatingNewAssistantsAllowed) {
|
|
3647
|
+
throw new NotAllowed(`Assistant ID is null and creating new assistants is not allowed - this configuration does not make sense`);
|
|
3648
|
+
}
|
|
3649
|
+
// <- TODO: !!! `OpenAiAssistantExecutionToolsOptions` - Allow `assistantId: null` together with `isCreatingNewAssistantsAllowed: true`
|
|
3630
3650
|
// TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
|
|
3631
3651
|
}
|
|
3632
3652
|
get title() {
|
|
@@ -3771,7 +3791,99 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3771
3791
|
},
|
|
3772
3792
|
});
|
|
3773
3793
|
}
|
|
3794
|
+
async createNewAssistant() {
|
|
3795
|
+
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3796
|
+
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3797
|
+
}
|
|
3798
|
+
const client = await this.getClient();
|
|
3799
|
+
/*
|
|
3800
|
+
TODO: !!!
|
|
3801
|
+
async function downloadFile(url: string, folder = './tmp'): Promise<string> {
|
|
3802
|
+
const filename = path.basename(url.split('?')[0]);
|
|
3803
|
+
const filepath = path.join(folder, filename);
|
|
3804
|
+
|
|
3805
|
+
if (!fs.existsSync(folder)) fs.mkdirSync(folder);
|
|
3806
|
+
|
|
3807
|
+
const res = await fetch(url);
|
|
3808
|
+
if (!res.ok) throw new Error(`Download error: ${url}`);
|
|
3809
|
+
const buffer = await res.arrayBuffer();
|
|
3810
|
+
fs.writeFileSync(filepath, Buffer.from(buffer));
|
|
3811
|
+
console.log(`📥 File downloaded: ${filename}`);
|
|
3812
|
+
|
|
3813
|
+
return filepath;
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
async function uploadFileToOpenAI(filepath: string) {
|
|
3817
|
+
const file = await client.files.create({
|
|
3818
|
+
file: fs.createReadStream(filepath),
|
|
3819
|
+
purpose: 'assistants',
|
|
3820
|
+
});
|
|
3821
|
+
console.log(`⬆️ File uploaded to OpenAI: ${file.filename} (${file.id})`);
|
|
3822
|
+
return file;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
// 🌐 URL addresses of files to upload
|
|
3826
|
+
const fileUrls = [
|
|
3827
|
+
'https://raw.githubusercontent.com/vercel/next.js/canary/packages/next/README.md',
|
|
3828
|
+
'https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/How_to_call_the_Assistants_API_with_Node.js.ipynb',
|
|
3829
|
+
];
|
|
3830
|
+
|
|
3831
|
+
// 1️⃣ Download files from URL
|
|
3832
|
+
const localFiles = [];
|
|
3833
|
+
for (const url of fileUrls) {
|
|
3834
|
+
const filepath = await downloadFile(url);
|
|
3835
|
+
localFiles.push(filepath);
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3838
|
+
// 2️⃣ Upload files to OpenAI
|
|
3839
|
+
const uploadedFiles = [];
|
|
3840
|
+
for (const filepath of localFiles) {
|
|
3841
|
+
const file = await uploadFileToOpenAI(filepath);
|
|
3842
|
+
uploadedFiles.push(file.id);
|
|
3843
|
+
}
|
|
3844
|
+
*/
|
|
3845
|
+
// 3️⃣ Create assistant with uploaded files
|
|
3846
|
+
const assistant = await client.beta.assistants.create({
|
|
3847
|
+
name: 'Next.js documentation assistant',
|
|
3848
|
+
description: 'Assistant that can answer questions about Next.js and working with APIs.',
|
|
3849
|
+
model: 'gpt-4o',
|
|
3850
|
+
instructions: spaceTrim$1(`
|
|
3851
|
+
Answer clearly and comprehensively.
|
|
3852
|
+
Quote parts from uploaded files if needed.
|
|
3853
|
+
`),
|
|
3854
|
+
// <- TODO: !!!! Generate the `instructions` from passed `agentSource` (generate outside of this class)
|
|
3855
|
+
tools: [{ type: 'code_interpreter' }, { type: 'file_search' }],
|
|
3856
|
+
// !!!! file_ids: uploadedFiles,
|
|
3857
|
+
});
|
|
3858
|
+
// TODO: !!!! Change Czech to English
|
|
3859
|
+
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
3860
|
+
return new OpenAiAssistantExecutionTools({
|
|
3861
|
+
...this.options,
|
|
3862
|
+
isCreatingNewAssistantsAllowed: false,
|
|
3863
|
+
assistantId: assistant.id,
|
|
3864
|
+
});
|
|
3865
|
+
}
|
|
3866
|
+
/**
|
|
3867
|
+
* Discriminant for type guards
|
|
3868
|
+
*/
|
|
3869
|
+
get discriminant() {
|
|
3870
|
+
return DISCRIMINANT;
|
|
3871
|
+
}
|
|
3872
|
+
/**
|
|
3873
|
+
* Type guard to check if given `LlmExecutionTools` are instanceof `OpenAiAssistantExecutionTools`
|
|
3874
|
+
*
|
|
3875
|
+
* Note: This is useful when you can possibly have multiple versions of `@promptbook/openai` installed
|
|
3876
|
+
*/
|
|
3877
|
+
static isOpenAiAssistantExecutionTools(llmExecutionTools) {
|
|
3878
|
+
return llmExecutionTools.discriminant === DISCRIMINANT;
|
|
3879
|
+
}
|
|
3774
3880
|
}
|
|
3881
|
+
/**
|
|
3882
|
+
* Discriminant for type guards
|
|
3883
|
+
*
|
|
3884
|
+
* @private const of `OpenAiAssistantExecutionTools`
|
|
3885
|
+
*/
|
|
3886
|
+
const DISCRIMINANT = 'OPEN_AI_ASSISTANT_V1';
|
|
3775
3887
|
/**
|
|
3776
3888
|
* TODO: [🧠][🧙♂️] Maybe there can be some wizard for those who want to use just OpenAI
|
|
3777
3889
|
* TODO: Maybe make custom OpenAiError
|
|
@@ -4007,6 +4119,7 @@ const PROMPTBOOK_ERRORS = {
|
|
|
4007
4119
|
PromptbookFetchError,
|
|
4008
4120
|
UnexpectedError,
|
|
4009
4121
|
WrappedError,
|
|
4122
|
+
NotAllowed,
|
|
4010
4123
|
// TODO: [🪑]> VersionMismatchError,
|
|
4011
4124
|
};
|
|
4012
4125
|
/**
|