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 스크립트를 만들고 싶다고 가정해 보겠습니다. 다음과 같은 스크립트를 작성할 수 있습니다.

지엑스피1

$ 함수는 프롬프트를 생성하는 템플릿 태그입니다. 프롬프트는 사용자가 설정한 LLM으로 전송되고, 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

JavaScriptTypeScript를 사용하여 프로그래밍 방식으로 프롬프트를 작성합니다.

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 등에서 텍스트를 수집합니다.

PDF , DOCX 등을 조작합니다.

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

📊 CSV, XLSX, ...에서 테이블을 수집합니다.

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

나누다

텍스트, 이미지 또는 이들을 혼합하여 분류합니다.

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

LLM 도구

JavaScript 함수를 도구 로 등록합니다(도구를 지원하지 않는 모델에 대한 대체 기능 포함). MCP(Model Context Protocol) 도구 도 지원됩니다.

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

💻 지역 모델

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 요청 시 효율적으로 제출할 수 있도록 비디오를 필사하고 스크린샷을 찍으세요.

// 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로 자동화

CLIAPI를 사용하여 자동화합니다.

npx genaiscript run tlaplus-linter "*.tla"
import { run } from "genaiscript/api" const res = await run("tlaplus-linter", "*.tla")

안전이 최우선!

GenAIScript는 콘텐츠 안전성을 검증하기 위한 기본 제공 Responsible AI 시스템 프롬프트와 Azure Content Safety 지원을 제공합니다.

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 접미사를 추가하여 원시 마크다운 콘텐츠를 얻을 수 있습니다. 예: https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (.md 확장자 참고)

기여하다

기여를 받습니다! 자세한 내용과 개발자 설정은 CONTRIBUTING 페이지를 확인하세요.


상표

이 프로젝트에는 프로젝트, 제품 또는 서비스에 대한 상표 또는 로고가 포함될 수 있습니다. Microsoft 상표 또는 로고의 허가된 사용은 Microsoft의 상표 및 브랜드 지침을 준수해야 합니다. 이 프로젝트의 수정된 버전에서 Microsoft 상표 또는 로고를 사용하는 것은 혼동을 야기하거나 Microsoft의 후원을 암시해서는 안 됩니다. 타사 상표 또는 로고를 사용하는 경우 해당 타사의 정책이 적용됩니다.

ID: 4pijmyi7gc