
파일 수집, 신속한 개발 및 구조화 된 데이터 추출을위한 편리한 툴링을 갖춘 JavaScript 환경.
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 Extension을 설치하거나 명령 줄을 사용하여 신속하게 시작하십시오.
JavaScript 또는 TypeScript를 사용하여 프로그래밍 방식으로 프롬프트를 작성하십시오.
def ( "FILE" , env . files , { endsWith : ".pdf" } )
$ `Summarize FILE. Today is ${ new Date ( ) } .`비주얼 스튜디오 코드 또는 명령 줄에서 스크립트를 편집, 디버그, 실행 및 테스트하십시오.
스크립트는 파일입니다! 그들은 버전을 만들고 공유하며 포크 될 수 있습니다.
// 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.`PDFS 조작, 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 또는 퍼즈 검색 파일.
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" } )localai, Ollama를 사용하여 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.` Prompty 파일도 실행하십시오!
---
name : poem
---
Write me a poemCLI를 사용하여 자동화하고 CI/CD 파이프 라인에 보고서를 통합하십시오.
npx genaiscript run tlaplus-linter " *.tla "Genaiscript는 내장 책임있는 AI 시스템 프롬프트 및 Azure Content Safety Support를 제공하여 컨텐츠 안전을 검증합니다.
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-reviewsTests 및 Eval을 사용하여 신뢰할 수있는 프롬프트를 구축하십시오.
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/.well-known/llms.txt 문서 맵에 대한 https://microsoft.github.io/genaiscript를 가져 오거나 모든 문서화 URL에 .md 접미사를 추가하여 원시 마크 다운 컨텐츠를 얻으십시오.
예를 들어, https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (.md extension 참고)
우리는 기여를 받아들입니다! 자세한 내용 및 개발자 설정은 기고 페이지를 확인하십시오.
이 프로젝트에는 프로젝트, 제품 또는 서비스에 대한 상표 또는 로고가 포함될 수 있습니다. Microsoft 상표 또는 로고의 승인 된 사용에는 Microsoft의 상표 및 브랜드 지침이 적용되며 따라야합니다. 이 프로젝트의 수정 된 버전에서 Microsoft 상표 또는 로고를 사용한다고해서 혼란을 일으키거나 Microsoft 후원을 암시해서는 안됩니다. 타사 상표 또는 로고를 사용하면 타사 정책이 적용됩니다.