
ファイルの摂取、迅速な開発、および構造化されたデータ抽出のための便利なツールを備えたJavaScriptの環境。
JavaScriptを使用して、LLMSのプロンプトをプログラム的に組み立てます。単一のスクリプトに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出力からファイルとdiffを抽出します。 Refactoring UIのプレビュー変更。
$ `Save the result in poem.txt.` FILE ./poem.txt
The quick brown fox jumps over the lazy dog.グレップまたはファズ検索ファイル。
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 Copilotを介してモデルを実行します。
script ( { ... , model : "github:gpt-4o" } )PHI-3などのオープンソースモデルを使用して、Ollama、Localaiを使用してスクリプトを実行します。
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" )LLMSを実行して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 poemCLIを使用して自動化し、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-reviewsPromptFooを搭載したテストと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-known/llms.txtをドキュメントマップ用にフェッチするか、ドキュメンテーションURLに.mdサフィックスを追加して生のマークダウンコンテンツを取得します。
たとえば、https://microsoft.github.io/genaiscript/guides/prompt-as-code.md(.md拡張子に注意)
貢献を受け入れます!詳細と開発者のセットアップについては、貢献ページをチェックアウトします。
このプロジェクトには、プロジェクト、製品、またはサービスの商標またはロゴが含まれる場合があります。 Microsoftの商標またはロゴの承認された使用は、Microsoftの商標およびブランドガイドラインに従うものであり、従わなければなりません。このプロジェクトの変更されたバージョンでのMicrosoft商標またはロゴの使用は、混乱を引き起こしたり、Microsoftのスポンサーシップを暗示したりしてはなりません。サードパーティの商標またはロゴの使用は、これらのサードパーティのポリシーの対象となります。