Escape braces in outputs of prompt nodes by default

This commit is contained in:
Ian Arawjo 2023-07-14 09:13:24 -04:00
parent 3657609c32
commit 973970b8ab
8 changed files with 21 additions and 11 deletions

View File

@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.d97bf957.css",
"main.js": "/static/js/main.44a6025f.js",
"main.js": "/static/js/main.b9a02cd0.js",
"static/js/787.4c72bb55.chunk.js": "/static/js/787.4c72bb55.chunk.js",
"index.html": "/index.html",
"main.d97bf957.css.map": "/static/css/main.d97bf957.css.map",
"main.44a6025f.js.map": "/static/js/main.44a6025f.js.map",
"main.b9a02cd0.js.map": "/static/js/main.b9a02cd0.js.map",
"787.4c72bb55.chunk.js.map": "/static/js/787.4c72bb55.chunk.js.map"
},
"entrypoints": [
"static/css/main.d97bf957.css",
"static/js/main.44a6025f.js"
"static/js/main.b9a02cd0.js"
]
}

View File

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><script async src="https://www.googletagmanager.com/gtag/js?id=G-RN3FDBLMCR"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-RN3FDBLMCR")</script><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="A visual programming environment for prompt engineering"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>ChainForge</title><script defer="defer" src="/static/js/main.44a6025f.js"></script><link href="/static/css/main.d97bf957.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><script async src="https://www.googletagmanager.com/gtag/js?id=G-RN3FDBLMCR"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-RN3FDBLMCR")</script><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="A visual programming environment for prompt engineering"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>ChainForge</title><script defer="defer" src="/static/js/main.b9a02cd0.js"></script><link href="/static/css/main.d97bf957.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

View File

@ -11,6 +11,7 @@ import LLMList from './LLMListComponent'
import LLMResponseInspectorModal from './LLMResponseInspectorModal';
import { getDefaultModelSettings, AvailableLLMs } from './ModelSettingSchemas'
import fetch_from_backend from './fetch_from_backend';
import { escapeBraces } from './backend/template';
// The LLM(s) to include by default on a PromptNode whenever one is created.
// Defaults to ChatGPT (GPT3.5).
@ -530,7 +531,7 @@ const PromptNode = ({ data, id }) => {
resp_obj => resp_obj['responses'].map(
r => {
// Carry over the response text and prompt fill history (vars):
let o = {text: r, fill_history: resp_obj['vars']};
let o = {text: escapeBraces(r), fill_history: resp_obj['vars']};
// Carry over any metavars
o.metavars = resp_obj['metavars'] || {};

View File

@ -24,6 +24,15 @@ export function escapeBraces(str: string): string {
return str.replace(/[{}]/g, '\\$&');
}
/**
* Given a string, returns the same string with the \ before any braces \{ and \} removed. Does nothing else.
* @param str The string to transform
*/
export function cleanEscapedBraces(str: string): string {
return str.replaceAll('\\{', '{').replaceAll('\\}', '}');
}
export class StringTemplate {
val: string;
/**
@ -153,7 +162,7 @@ export class PromptTemplate {
/** Returns the value of this.template, with any escaped braces \{ and \} with the escape \ char removed. */
toString(): string {
return this.template.replaceAll('\\{', '{').replaceAll('\\}', '}');
return cleanEscapedBraces(this.template);
}
toValue(): string {

View File

@ -6,7 +6,7 @@ def readme():
setup(
name='chainforge',
version='0.2.1',
version='0.2.1.1',
packages=find_packages(),
author="Ian Arawjo",
description="A Visual Programming Environment for Prompt Engineering",