[英语| 简体中文]]
promptc-go是promptc的实现。它使用promptc规范生成,分析,构建,编译和运行promptc文件,并旨在推广及时工程的方法。
promptc是及时工程的OpenAPI样规范。
以上提示文件从Zinccat/Zkit进行了调整,该文件已获得GPLV3的许可
# As simple as it should be
$ promptc $prompt $input
聊天功能
$ promptc chat有关ProffCC-CLI的更多信息,请参阅DOCS/CLI.MD。
结构化提示文件:
// [Optional] meta info
project: test
author: KevinZonda
license: MIT
version: 0.0 .1
// [Optional] define configs
conf: {
provider: openai
model: gpt - 3.5 - turbo
temperature: 0.5
stop: [ 'Hello' , '4.0' ]
}
// [Optional] define variable constraint
vars: {
x: int
// var x with int type
y: int { min : 0 , max : 10 }
z: int { min : 0 , max : 10 , default : '5' }
}
// [Optional] Birmingham-style define var
a: int { min : 0 , max : 10 }
// [Required] define prompts
prompts: [
// role: 'user' is meta info for ChatGPT
// to make it empty, use {}
'' 'role: ' user '
You Entered : { x }
Prompt Compiled : { %
if ( x == "1" ) {
result = "Hello" ;
} else {
result = "Word!" ;
}
% }
{ % Q % }
'' '
]单线提示文件实验:
You Entered : { x }笔记
单线提示文件当前是一个实验功能。
不建议在生产环境中使用它。
您可以在没有结构化的情况下编写单线提示文件。
当前的promptc-go支持string , int , float类型。
// declare a variable
myName : string { minLen : 3 , maxLen : 10 , default : "John" }
// a var named `myName` of type `string`
// with default value "John"
// min length 3, max length 10
myAge : int { min : 18 , max : 100 , default : '18' }
// a var named `myAge` of type `int`
// with default value 18
// min value 18, max value 100
thisPrice : float { min : 0.01 , default : '0.01' }
// a var named `thisPrice` of type `float`
// with default value 0.01
// min value 0.01, and unlimited max value stringminLen :intmaxLen :intintmin :INT64max :INT64floatmin :float64max :float64default :字符串{ role : 'user' }
xx { x } {{ x }} { %
if ( x > 12 ) {
result = "good" ;
} else {
result = "bad" ;
}
% } {}中的任何内容都是可变的,例如{x}上一个示例中的任何内容{%%}中的任何内容都是JS脚本
如果要显示{或} ,请使用{{或}}
提示的第一行是特殊的,它为此提示提供了一些额外的信息。
即Chatgpt的角色信息。例如
role: 'user'
Show me more about {x}
如果要提供空的额外信息,请使用{} ,因为非常建议您使用{}。尽管不是必需的,因为一旦HJSON解析失败, promptc将在您的提示下将第一行预先置于第一行,但可能会导致很多不确定的行为。
我们为'''保留{%Q%}这在HJSON的多行文本语法中不容易完成。
例如
This is reserved { % Q % } {{ % Q % }}将被编译为
This is reserved ''' { % Q % }笔记
在提示中使用JavaScript是一个实验功能。
promptc-go使用OTTO作为JavaScript运行时
警告
在提示中使用JavaScript可能会引起脆弱性并导致潜在的安全性漏洞。
promptc-go对此不会承担任何责任。
promptc支持使用{%%}语法嵌入JavaScript脚本。它支持2种模式:
在标准模式下,运行JS脚本后,Pysterc将从result变量中获得结果。
You Entered : { x }
Prompt Compiled : { %
if ( x == "1" ) {
result = "Hello" ;
} else {
result = "Word!" ;
}
% }如果输入x = 1 ,结果将为:
You Entered: 1
Prompt Compiled: Hello
在简单的模式下,下调将从JS脚本的返回值中获取结果。它将在提示开始时添加E ( {%E /*script here*/ %} )
You Entered : { x }
Prompt Compiled : { % E
if ( x == "1" ) {
return "Hello" ;
} else {
return "Word!" ;
}
% }如果输入x = 1 ,结果将为:
You Entered: 1
Prompt Compiled: Hello
在简单的模式下,脚本将包裹在功能中以启用return语句。
例如,将在上一个示例中运行的实际脚本:
result = ( function ( ) {
if ( x == "1" ) {
return "Hello"
} else {
return "Word!" ;
}
} ( )元信息将被用作特殊的野外定义变量(但不会将其视为变量)。
当前支持的元信息:
project: test
author: KevinZonda
license: MIT
version: 0.0 .1如果需要,您可以在vars部分中定义相同名称。
// prompt1.promptc
project: test
author: KevinZonda
license: MIT
version: 0.0 .1
vars: {
x : int
}
// VarList:
// - x: string // prompt2.promptc
project: test
author: KevinZonda
license: MIT
version: 0.0 .1
vars: {
x: int
project: string
license: string { minLen : 12 }
}
// VarList:
// - x: string
// - project: string
// - license: string // prompt3.promptc
project: test
author: KevinZonda
license: MIT
version: 0.0 .1
prompts: [
'' '{}
{ %
console . log ( project ) ; // will print nothing
% }
'' '
]
// VarList:
// - project: string