
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贊助。任何使用第三方商標或徽標都遵守這些第三方政策。