GenAIScript

Official

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Enables execution of code in Docker containers, allowing LLMs to run isolated code environments for data processing or computation tasks.

  • Provides video processing capabilities including transcription and frame extraction to prepare video content for LLM analysis.

  • Allows querying and analyzing repository data using Git tools, enabling statistical analysis of commits and other Git operations.

GenAIスクリプト

プロンプトはコーディングです

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 Code 拡張機能をインストールするか、コマンド ラインを使用してすぐに開始できます。


✨ 特徴

🎨 スタイル化された JavaScript と TypeScript

JavaScriptまたはTypeScriptを使用してプログラムでプロンプトを構築します。

def("FILE", env.files, { endsWith: ".pdf" }) $`Summarize FILE. Today is ${new Date()}.`

🚀 高速開発ループ

Visual Studio Codeまたはコマンド ラインを使用してスクリプトを編集、デバッグ実行テストします


🔗 スクリプトの再利用と共有

スクリプトはファイルです。バージョン管理、共有、フォークが可能です。

// 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.`

📋 データスキーマ

スキーマを使用してデータを定義、検証、修復します。Zod サポートが組み込まれています。

const data = defSchema("MY_DATA", { type: "array", items: { ... } }) $`Extract data from files using ${data} schema.`

📄 PDF、DOCX などからテキストを取り込みます...

PDFDOCX などを操作します。

def("PDF", env.files, { endsWith: ".pdf" }) const { pages } = await parsers.PDF(env.files[0])

📊 CSV、XLSX などからテーブルを取り込みます...

CSVXLSX 、... からの表形式データを操作します。

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" })

分類する

テキスト、画像、またはそれらの組み合わせを分類します。

const joke = await classify( "Why did the chicken cross the road? To fry in the sun.", { yes: "funny", no: "not funny", } )

LLMツール

JavaScript関数をツールとして登録します(ツールをサポートしていないモデルの場合はフォールバック機能を使用します)。モデルコンテキストプロトコル(MCP)ツールもサポートされています。

defTool( "weather", "query a weather web api", { location: "string" }, async (args) => await fetch(`https://weather.api.api/?location=${args.location}`) )

LLMエージェント

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_git" }) $`Do a statistical analysis of the last commits`

Git エージェントのソースを参照してください。


🔍 RAG内蔵

ベクトル検索

const { files } = await retrieval.vectorSearch("cats", "**/*.md")

🐙 GitHub モデルと GitHub Copilot

GitHub ModelsまたはGitHub Copilotを通じてモデルを実行します。

script({ ..., model: "github:gpt-4o" })

💻 ローカルモデル

OllamaLocalAIを使用して、 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 リクエストに効率的にフィードできるように、ビデオを書き起こしてスクリーンショットを作成します。

// transcribe const transcript = await transcript("path/to/audio.mp3") // screenshots at segments const frames = await ffmpeg.extractFrames("path_url_to_video", { transcript }) def("TRANSCRIPT", transcript) def("FRAMES", frames)

🧩 LLM 構成

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.`

🅿️ 迅速なサポート

Promptyファイルも実行してください。

--- name: poem --- Write me a poem

プラグ可能な秘密スキャン

秘密スキャンを使用して、チャットの秘密をスキャンします。

{ "secretPatterns": { ..., "OpenAI API Key": "sk-[A-Za-z0-9]{32,48}" } }

⚙ CLI または API で自動化

CLIまたはAPIを使用して自動化します。

npx genaiscript run tlaplus-linter "*.tla"
import { run } from "genaiscript/api" const res = await 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 Actions と Azure DevOps パイプラインをサポートします。

npx genaiscript ... --pull-request-reviews

⭐ テストと評価

promptfooを利用したテストと評価を使用して、信頼性の高いプロンプトを構築します。

script({ ..., tests: { files: "penguins.csv", rubric: "is a data analysis report", facts: "The data refers about penguin population in Antarctica.", }})

LLMフレンドリーなドキュメント

ドキュメントの全コンテンツは、 https://microsoft.github.io/genaiscript/llms-full.txtにマークダウン形式で保存されています。お気に入りの RAG システムに直接入力してください。

LLMクローラーの場合は、ドキュメントURLに.mdサフィックスを追加して、生のMarkdownコンテンツを取得してください。例: https ://microsoft.github.io/genaiscript/guides/prompt-as-code.md(.md拡張子にご注意ください)

貢献

貢献を歓迎します!詳細と開発者向け設定については、 「貢献」ページをご覧ください。


商標

このプロジェクトには、プロジェクト、製品、またはサービスの商標またはロゴが含まれている場合があります。Microsoftの商標またはロゴの使用は、 Microsoftの商標およびブランドガイドラインの対象となり、これに従う必要があります。このプロジェクトの改変版におけるMicrosoftの商標またはロゴの使用は、混乱を招いたり、Microsoftのスポンサーシップを暗示したりしてはなりません。第三者の商標またはロゴの使用は、当該第三者のポリシーに従うものとします。

ID: 4pijmyi7gc