
JavaScript-ish环境具有方便的工具,用于摄入文件,及时开发和结构化数据提取。
使用JavaScript编程组装LLM的提示。在单个脚本中编排LLM,工具和数据。
对您说要创建一个生成“ Hello World”诗的LLM脚本。您可以编写以下脚本:
$ `Write a 'hello world' poem.` $函数是创建提示的模板标签。然后将提示发送到生成诗的LLM(您配置)。
让我们通过添加文件,数据和结构化输出来使其更有趣。假设您要在提示符中包含一个文件,然后将输出保存在文件中。您可以编写以下脚本:
// read files
const file = await workspace . readText ( "data.txt" )
// include the file content in the prompt in a context-friendly way
def ( "DATA" , file )
// the task
$ `Analyze DATA and extract data in JSON in data.json.` def函数包括文件的内容,并在必要时对目标LLM进行优化。 Genaiscript脚本还解析了LLM输出并将自动提取data.json 。
通过安装Visual Studio代码扩展名或使用命令行快速开始。
使用JavaScript或Typescript编程构建提示。
def ( "FILE" , env . files , { endsWith : ".pdf" } )
$ `Summarize FILE. Today is ${ new Date ( ) } .`在Visual Studio代码或命令行中编辑,调试,运行和测试您的脚本。
脚本是文件!它们可以版本化,共享和分叉。
// define the context
def ( "FILE" , env . files , { endsWith : ".pdf" } )
// structure the data
const schema = defSchema ( "DATA" , { type : "array" , items : { type : "string" } } )
// assign the task
$ `Analyze FILE and extract data to JSON using the ${ schema } schema.`使用模式定义,验证和维修数据。
const data = defSchema ( "MY_DATA" , { type : "array" , items : { ... } } )
$ `Extract data from files using ${ data } schema.`操纵PDF,Docx,...
def ( "PDF" , env . files , { endsWith : ".pdf" } )
const { pages } = await parsers . PDF ( env . files [ 0 ] )从CSV,XLSX,...操纵表格数据,...
def ( "DATA" , env . files , { endsWith : ".csv" , sliceHead : 100 } )
const rows = await parsers . CSV ( env . files [ 0 ] )
defData ( "ROWS" , rows , { sliceHead : 100 } )从LLM输出中提取文件和差异。预览UI重构的变化。
$ `Save the result in poem.txt.` FILE ./poem.txt
The quick brown fox jumps over the lazy dog.GREP或FUZZ搜索文件。
const { files } = await workspace . grep ( / [a-z][a-z0-9]+ / , { globs : "*.md" } )注册JavaScript用作工具(对于不支持工具的模型的后备)。
defTool (
"weather" ,
"query a weather web api" ,
{ location : "string" } ,
async ( args ) =>
await fetch ( `https://weather.api.api/?location= ${ args . location } ` )
)注册JavaScript用作工具,并将工具 +提示组合到代理中。
defAgent (
"git" ,
"Query a repository using Git to accomplish tasks." ,
`Your are a helpful LLM agent that can use the git tools to query the current repository.
Answer the question in QUERY.
- The current repository is the same as github repository.` ,
{ model , system : [ "system.github_info" ] , tools : [ "git" ] }
)然后将其用作工具
script ( { tools : "agent" } )
$ `Do a statistical analysis of the last commits`向量搜索。
const { files } = await retrieval . vectorSearch ( "cats" , "**/*.md" )通过GitHub模型或GitHub副副词运行模型。
script ( { ... , model : "github:gpt-4o" } )使用Ollama,Localai,使用开源模型(例如Phi-3)运行脚本。
script ( { ... , model : "ollama:phi3" } )让LLM在沙盒执行环境中运行代码。
script ( { tools : [ "python_code_interpreter" ] } )在Docker容器中运行代码。
const c = await host . container ( { image : "python:alpine" } )
const res = await c . exec ( "python --version" )运行LLM来构建您的LLM提示。
for ( const file of env . files ) {
const { text } = await runPrompt ( ( _ ) => {
_ . def ( "FILE" , file )
_ . $ `Summarize the FILE.`
} )
def ( "SUMMARY" , text )
}
$ `Summarize all the summaries.` 还运行您的及时文件!
---
name : poem
---
Write me a poem使用CLI自动化,将报告集成在您的CI/CD管道中。
npx genaiscript run tlaplus-linter " *.tla "Genaiscript提供内置负责的AI系统提示和Azure内容安全支持以验证内容安全性。
script ( { ... ,
system : [ "system.safety_harmful_content" , ... ] ,
contentSafety : "azure" // use azure content safety
} )
const safety = await host . contentSafety ( )
const res = await safety . detectPromptInjection ( env . vars . input )通过注释,评论或说明更新整合到您的拉请求中检查。支持GitHub动作和Azure DevOps管道。
npx genaiscript ... --pull-request-reviews使用PressFoo供电的测试和EVALS构建可靠的提示。
script ( { ... , tests : {
files : "penguins.csv" ,
rubric : "is a data analysis report" ,
facts : "The data refers about penguin population in Antarctica." ,
} } )如果您是llm crawler,请获取https://microsoft.github.io/genaiscript/.well-nown/lonknoy/llms.txt作为文档映射或将.md后缀添加到任何文档URL中以获取原始的Markdown内容。
例如,https://microsoft.github.io/genaiscript/guides/prompt-as-code.md(注意.MD扩展)
我们接受贡献!查看贡献页面的详细信息和开发人员设置。
该项目可能包含用于项目,产品或服务的商标或徽标。 Microsoft商标或徽标的授权使用受到了Microsoft的商标和品牌准则的约束。在此项目的修改版本中使用Microsoft商标或徽标不得引起混乱或暗示Microsoft赞助。任何使用第三方商标或徽标都遵守这些第三方政策。