Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐Get rid of eval - use propper virtualization #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ Cleanup and renaming
- Change command `PTBK_NAME` to `PROMPTBOOK_NAME` _(but keep backward compatibility and preserve alias `PTBK`)_
- Rename `runRemoteServer` -> `startRemoteServer` and return `Destroyable` object

## !!! This branch !!!

- Implement `JavascriptExecutionTools`
- Deprecate `JavascriptEvalExecutionTools`
- Do not allow to use `JavascriptEvalExecutionTools` in node.js environment

---

## Upcomming

- Rename "natural" -> "llm"
Expand Down
2 changes: 1 addition & 1 deletion samples/usage/logging/logging.ts.todo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function main() {
openAiApiKey: process.env.OPENAI_API_KEY,
}),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,
}),
],
Expand Down
2 changes: 1 addition & 1 deletion samples/usage/remote/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1>esting remote server of PromptBook</h1>
clientId,
}),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,
}),
],
Expand Down
4 changes: 2 additions & 2 deletions samples/usage/simple-script/simple-script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { PromptbookLibrary } from '@promptbook/core';
import { JavascriptEvalExecutionTools } from '@promptbook/execute-javascript';
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
import { OpenAiExecutionTools } from '@promptbook/openai';
import { assertsExecutionSuccessful, executionReportJsonToString } from '@promptbook/utils';
import chalk from 'chalk';
Expand Down Expand Up @@ -38,7 +38,7 @@ async function main() {
openAiApiKey: process.env.OPENAI_API_KEY,
}),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('createPromptbookExecutor + custom async function ', () => {
tools: {
natural: new MockedEchoNaturalExecutionTools({ isVerbose: true }),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,

// Note: [🕎]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { assertsExecutionSuccessful } from '../../assertsExecutionSuccessful';
import { createPromptbookExecutor } from '../../createPromptbookExecutor';
import { MockedEchoNaturalExecutionTools } from '../natural-execution-tools/mocked/MockedEchoNaturalExecutionTools';
import { CallbackInterfaceTools } from '../user-interface-execution-tools/callback/CallbackInterfaceTools';
import { JavascriptEvalExecutionTools } from './javascript/JavascriptEvalExecutionTools';
import { JavascriptExecutionTools } from './javascript/JavascriptExecutionTools';

describe('createPromptbookExecutor + missing custom function', () => {
const promptbook = promptbookStringToJson(
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('createPromptbookExecutor + missing custom function', () => {
tools: {
natural: new MockedEchoNaturalExecutionTools({ isVerbose: true }),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,

// Note: [🕎]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PromptbookString } from '../../../types/PromptbookString';
import { createPromptbookExecutor } from '../../createPromptbookExecutor';
import { MockedEchoNaturalExecutionTools } from '../natural-execution-tools/mocked/MockedEchoNaturalExecutionTools';
import { CallbackInterfaceTools } from '../user-interface-execution-tools/callback/CallbackInterfaceTools';
import { JavascriptEvalExecutionTools } from './javascript/JavascriptEvalExecutionTools';
import { JavascriptExecutionTools } from './javascript/JavascriptExecutionTools';

describe('createPromptbookExecutor + custom function with dependencies', () => {
const promptbook = promptbookStringToJson(
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('createPromptbookExecutor + custom function with dependencies', () => {
tools: {
natural: new MockedEchoNaturalExecutionTools({ isVerbose: true }),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,

// Note: [🕎]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PromptbookString } from '../../../types/PromptbookString';
import { createPromptbookExecutor } from '../../createPromptbookExecutor';
import { MockedEchoNaturalExecutionTools } from '../natural-execution-tools/mocked/MockedEchoNaturalExecutionTools';
import { CallbackInterfaceTools } from '../user-interface-execution-tools/callback/CallbackInterfaceTools';
import { JavascriptEvalExecutionTools } from './javascript/JavascriptEvalExecutionTools';
import { JavascriptExecutionTools } from './javascript/JavascriptExecutionTools';

describe('createPromptbookExecutor + custom function without dependencies', () => {
const promptbook = promptbookStringToJson(
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('createPromptbookExecutor + custom function without dependencies', () =
tools: {
natural: new MockedEchoNaturalExecutionTools({ isVerbose: true }),
script: [
new JavascriptEvalExecutionTools({
new JavascriptExecutionTools({
isVerbose: true,

// Note: [🕎]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@ import {
parseKeywordsFromString,
} from 'n12';
import { spaceTrim as _spaceTrim } from 'spacetrim';
import { isRunningInNode } from '../../../../utils/isRunningInWhatever';
import { prettifyMarkdown as _prettifyMarkdown } from '../../../../utils/markdown/prettifyMarkdown';
import { removeEmojis as _removeEmojis } from '../../../../utils/removeEmojis';
import { removeQuotes as _removeQuotes } from '../../../../utils/removeQuotes';
import { trimCodeBlock as _trimCodeBlock } from '../../../../utils/trimCodeBlock';
import { trimEndOfCodeBlock as _trimEndOfCodeBlock } from '../../../../utils/trimEndOfCodeBlock';
import { unwrapResult as _unwrapResult } from '../../../../utils/unwrapResult';
import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptions';
import type { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptions';
import { preserve } from './utils/preserve';

/**
* ScriptExecutionTools for JavaScript implemented via eval
*
* @deprecated Use `JavascriptExecutionTools` instead
* Warning: It is used for testing and mocking
* **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
*/
export class JavascriptEvalExecutionTools implements ScriptExecutionTools {
public constructor(private readonly options: JavascriptExecutionToolsOptions) {}

public constructor(private readonly options: JavascriptExecutionToolsOptions) {
if (isRunningInNode()) {
throw new Error(`JavascriptEvalExecutionTools is not intended to be used in Node.js environment`);
}
}


/**
* Executes a JavaScript
Expand Down
Loading