Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jun 14, 2024
1 parent e8125b2 commit afaca8d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 deletions.
105 changes: 54 additions & 51 deletions docs/src/content/docs/getting-started/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
---
title: Getting Started
sidebar:
order: 0
description: Start developing with the GenAIScript VS Code Extension to create AI scripts efficiently.
order: 0
description: Start developing with the GenAIScript VS Code Extension to create
AI scripts efficiently.
keywords:
- AI Scripting Extension
- VS Code AI
- Generative AI Development
- AI Extension Setup
- AI Code Automation
- AI Scripting Extension
- VS Code AI
- Generative AI Development
- AI Extension Setup
- AI Code Automation
genaiscript:
model: openai:gpt-3.5-turbo
files: src/samples/markdown-small.txt

---

GenAIScript is a scripting language that integrates LLMs into the scripting process using a simplified JavaScript syntax.
Expand All @@ -17,68 +22,73 @@ It allows users to create, debug, and automate LLM-based scripts.
GenAIScript brings the flexibility of JavaScript with the convenience of built-in output parsing
to streamline the creation of LLM-based software solutions.

## the script
## script = prompt generator

The following script
takes a file with text content (.txt, .pdf, .docx) as input and
saves a summary of the file in another file.
The following script generates a prompt that
takes files (.txt, .pdf, .docx) as input and
saves the summaries in another files.

```js wrap title="summarize.genai.js"
// metadata and model configuration
script({ title: "Summarize", model: "gpt4" })
// insert the context, define a "FILE" variable
```js wrap title="summarize.genai.js" system=false assistant=true user=true
// context: define a "FILE" variable
const file = def("FILE", env.files)
// appends text to the prompt (file is the variable name)
$`Summarize ${file}. Save output to ${file}.summary`
// task: appends text to the prompt (file is the variable name)
$`Summarize ${file} in one sentence. Save output to ${file}.summary`
```

GenAIScript will execute `summarize.genai.js` and generate the user message that will be sent to the LLM chat.
It also populates the `env.files` variable with the files selected in the context (from a user UI interaction or CLI arguments).
<!-- genaiscript output start -->

````txt title="user prompt" wrap
FILE ./lorem.txt:
```txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
<details style="margin-left: 1rem;" open>
<summary>👤 user</summary>


````markdown wrap
FILE:
```txt file="src/samples/markdown-small.txt"
What is Markdown?

Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages.
```

Shorten the following FILE. Limit changes to minimum.
Summarize FILE in one sentence. Save output to FILE.summary
````

## System scripts

GenAIScript also automatically selects system scripts to support file generation and other features. Since
we're using files in this script, it will run the `system.files` script which teaches the LLM how to format files
in a structured format.
</details>

```js title="system.files.genai.js"
system({ title: "File generation" })
const folder = env.vars["outputFolder"] || "."
$`When generating or updating files you will use this syntax:`
def(`File ${folder}/file1.ts`, `What goes in ${folder}/file1.ts`, {
language: "typescript",
})
```

And the resulting system prompt.
<details style="margin-left: 1rem;" open>
<summary>🤖 assistant</summary>


````txt title="system prompt"
When generating or updating files you will use the following syntax:
File ./file1.ts
```typescript
What goes in ./file1.ts
````markdown wrap
File src/samples/markdown-small.txt.summary:
```txt
Markdown is a lightweight markup language created by John Gruber in 2004, known for adding formatting elements to plaintext text documents.
```
````


</details>

<!-- genaiscript output end -->



GenAIScript will execute `summarize.genai.js` and generate the `👤 user` message that will be sent to the LLM chat. It also populates the `env.files` variable with the files selected in the context (from a user UI interaction or CLI arguments).

The LLM responds with the `🤖 assistant` message and GenAIScript parses the output
to extract structured data.

## LLM invocation

All the generated prompts are formatted and sent to the LLM server, which can be remote like [OpenAI](https://platform.openai.com/docs/api-reference/chat/create) or running locally like [ollama](https://ollama.com/) (there are many other LLM providers).

```json title="llmrequest.json"
```json
{
"model": "gpt4",
"messages": [
{ "role": "system", "content": "When generating... " },
{ "role": "user", "content": "FILE ./lorem.txt:..." }
{ "role": "user", "content": "FILE src/samples/...:" }
]
}
```
Expand All @@ -88,13 +98,6 @@ All the generated prompts are formatted and sent to the LLM server, which can be
The LLM responds with a text which can be parsed for various micro-formats,
like markdown code fences, files or annotations.

````txt title="llmresponse.txt"
File ./lorem.txt.summary
```
Lorem Ipsum.
```
````

GenAIScript automatically makes sense of the output and exposes it through a [Refactoring Preview](https://code.visualstudio.com/docs/editor/refactoring#_refactor-preview) or directly saved to the file system.

Of course, things can get more complex - with functions, schemas, ... -, but this is the basic flow of a GenAIScript script.
Expand Down
3 changes: 3 additions & 0 deletions docs/src/samples/markdown-small.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
What is Markdown?

Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages.

0 comments on commit afaca8d

Please sign in to comment.