Closed bzorn closed 5 months ago
The right-click menu option doesn't appear for any file after I parse the pdf:
Looks like it attaches the debugger. The terminal log:
PS C:\Users\zorn\OneDrive - Microsoft\AI CoArch\open-source-release\review> node "c:\Users\zorn.vscode\extensions\genaiscript.genaiscript-vscode-1.19.2\genaiscript.cjs" serve
Debugger listening on ws://127.0.0.1:62411/ecb576ab-bfdc-4c9a-ba16-b0e7b1a60110
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
GenAIScript server started on port 8003
(node:37368) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ...
to show where the warning was created)
clients: connected (1 clients)
parse: pdf ex2.pdf
This was due to the Javascript Debugger attach setting being on "always". Needs to be on something else like "smart".
Type: Bug
Describe the issue
I have script that parses a pdf file. I ran it on a pdf file and it ran successfully but when I try to invoke a script on another pdf file, no option appears in the right-click context menu
It looks like I'm in the debugger when the script ends.
To Reproduce
See above
Expected behavior
I expected to see the option
Environment
vscode: 1.88.1 extension: 1.19.2
Request
batch
command:.env
file.npx genaiscript help run
for the full list of options.đź“„ spec
```markdown # Specification - [GenAIScript-Introduction-March2024.pdf](./GenAIScript-Introduction-March2024.pdf) ```đź’ľ script
🧬 prompt
đź““ script source
```js script({ title: "gen-tweet" }) def("FILE", env.files) $`Given the paper in FILE, write a 140 character summary of the paper that makes the paper sound exciting and encourages readers to look at it. ` ```đź‘ľ system
- tokens: 8 ```markdown You are concise. Answer in markdown. ```js
```js system({ title: "Markdown system prompt" }) $`You are concise. Answer in markdown.` ```đź‘ľ system.explanations
- tokens: 9 ```markdown When explaining answers, take a deep breath. ```js
```js system({ title: "Explain your answers" }) $`When explaining answers, take a deep breath.` ```đź‘ľ system.files
- tokens: 146 ``````markdown ## Files When generating or updating files you will use the following syntax: File ./file1.ts: ```typescript What goes in ./file1.ts. ``` File ./file1.py: ```python What goes in ./file1.py. ``` File /path_to_file/file2.md: `````markdown What goes in /path_to_file/file2.md. ````` Make sure to use precisely ``` to guard file code sections. Make sure to use precisely ````` to guard file markdown sections. Use full path of filename in code section header. If a file does not have changes, do not regenerate. Do NOT emit line numbers in file. CSV files are inlined as markdown tables. ``````js
```js system({ title: "File generation", description: "Teaches the file format supported by GenAIScripts", }) const folder = env.vars["outputFolder"] || "." $`## Files When generating or updating files you will use the following syntax:` def( `File ${folder}/file1.ts`, `What goes in\n${folder}/file1.ts.`, { language: "typescript" } ) def( `File ${folder}/file1.py`, `What goes in\n${folder}/file1.py.`, { language: "python" } ) def( `File /path_to_file/file2.md`, `What goes in\n/path_to_file/file2.md.`, { language: "markdown" } ) $`Make sure to use precisely ${env.fence} to guard file code sections.` $`Make sure to use precisely ${env.markdownFence} to guard file markdown sections.` $`Use full path of filename in code section header.` if (folder !== ".") $`When generating new files, place files in folder "${folder}".` $`If a file does not have changes, do not regenerate.` $`Do NOT emit line numbers in file.` $`CSV files are inlined as markdown tables.` ```🧠llm request (2 messages)
- tokens: 4306 - temperature: 0.2 - api type: azure - model: gpt-4 - url: [https://tnrllmproxy.azurewebsites.net/openai/deployments/gpt-4/chat/completions?api-version=2023-09-01-preview](https://tnrllmproxy.azurewebsites.net/openai/deployments/gpt-4/chat/completions?api-version=2023-09-01-preview)✉️ messages
``````json { "temperature": 0.2, "messages": [ { "role": "system", "content": "---\nYou are concise. Answer in markdown.\n\n---\nWhen explaining answers, take a deep breath.\n\n---\n## Files\n\nWhen generating or updating files you will use the following syntax:\nFile ./file1.ts:\n```typescript\nWhat goes in\n./file1.ts.\n```\n\nFile ./file1.py:\n```python\nWhat goes in\n./file1.py.\n```\n\nFile /path_to_file/file2.md:\n`````markdown\nWhat goes in\n/path_to_file/file2.md.\n`````\n\nMake sure to use precisely ``` to guard file code sections.\nMake sure to use precisely ````` to guard file markdown sections.\nUse full path of filename in code section header.\nIf a file does not have changes, do not regenerate.\nDo NOT emit line numbers in file.\nCSV files are inlined as markdown tables.\n\n" }, { "role": "user", "content": [ { "type": "text", "text": "FILE:\n```pdf file=\"GenAIScript-Introduction-March2024.pdf\"\nGenAIScript: Robust Scripting for Generative AI\n\nPeli de Halleux, Markus Kuppe, Michał Moskal, Madan Musuvathi, Benjamin Zorn\n\nMarch 2024\n\nAbstract our existing computing infrastructure, AISW, with its\nenhanced capabilities, will dominate the development\nScripting languages, like Python and JavaScript, have\nof future software systems. Our goal is to make\nenabled major advances in computing but were created\nGenAIScript the language for scripting AISW.\nprior to the advent of Large Language Models\n(LLMs). This paper introduces GenAIScript, a script- Historically, scripting languages like Perl, JavaScript,\ning language that makes LLMs a first-class part of the and Python, have become widely successful because\nscripting process, allowing users to author, debug, and they provide two key elements: (1) they allow diverse\ndeploy LLM-based scripts that can perform tasks be- users to write small but useful programs, and (2) they\nyond the reach of conventional code. By extending the give users access to new computing capabilities not\npopular Visual Studio Code environment, GenAIS- previously available to programs (e.g., JavaScript gave\ncript simplifies the creation of robust and reusable its users access to the Web).\nscripts that can intelligently process and generate con-\nGiven that context, the goal of GenAIScript is to em-\ntent, including code, documentation, and structured\npower a wide class of potential users to easily leverage\ndata. We explain what GenAIScript is, how it is im-\nthe power of AISW. GenAIScript enables users, in-\nplemented, and illustrate its use in several production\ncluding those without extensive programming exper-\ndeployments.\ntise, to author, debug, and deploy scripts that seam-\nlessly incorporate calls to LLMs. GenAIScript is a Ja-\n1. Introduction\nvaScript-compatible language with a dedicated VS\nCode extension to simplify the scripting process, mak-\n1\nGenAIScript is a JavaScript-compatiblescripting lan-\ning it accessible to a broader audience.\nguage that allows users to write scripts to automate\ncomplex tasks by leveraging LLMs as a first-class\nWith the goal of making GenAIScript the go-to lan-\nscript element.\nguage for writing AISW, we have the following key\nobjectives:\nCommented [BZ1]: @Madan Musuvathi - I added a list\nThe dramatic rise in the capabilities of artificial intel-\nof key objectives and how we address them related to your\nligence has revolutionized the way we interact with\n1. Integration with LLMs: GenAIScript is de-\nquestion. Let me know what you think.\ntechnology, offering unprecedented opportunities to\nsigned to make LLMs a first-class part of the\nautomate and enhance many tasks. Incorporating calls\nscripting process, allowing users to author,\nto LLMs (or more generally any foundation model) at\ndebug, and deploy LLM-based scripts.\nruntime into a software system greatly enhances what\nthat software can do. The disruptive nature of this\n2. Simple Abstractions: GenAIScript provides\ntransition forces us to categorize software into Plain\nabstractions to define the prompt context, re-\nOrdinary Software (POSW), which does not use the\nfer to the context in the prompt itself, and\npower of LLMs at runtime, and the more capable AI\nsupports specification and checking of multi-\nSoftware (AISW) that does leverage LLMs.\nple output formats.\nPOSW represents all software written before the crea-\n3. Ease of Use: GenAIScript targets a wide\ntion of LLMs and includes operating systems, applica-\nclass of potential users, including non-devel-\ntions, scripts, etc. While POSW is a key element of\nopers. The VS Code extension and\n\n1\nCurrently GenAIScripts are JavaScript-compatible\nbut in the future we anticipate bindings for other lan-\nguages including Python.\n\n1\n\n-------- Page Break --------\n\nintegration with existing IDE features con- Because every GenAIScript calls an LLM, metadata is\ntribute to this quality. needed to define the parameters that will be used to\ninvoke the LLM. Those parameters can include the\n4. Robustness: GenAIScript aims to be robust\nmodel, the temperature, the number of tokens to re-\nby leveraging the capabilities of VS Code for\nturn, etc. By default, GenAIScripts use the “gpt-4”\nwriting, executing, debugging, and refining\nmodel and other reasonable defaults, so many of the\nscripts. Additional features like input and out-\nmetadata fields can be omitted.\nput specifications and static orchestration\ngraphs also contribute to robustness. A GenAIScript executes in three parts: 1) set up the\nLLM prompt, 2) execute the LLM, and 3) parse the\n5. Seamless Integration with Plain Old Soft-\nLLM output.\nware (POSW): GenAIScript is designed to\nbe embedded into existing POSW work- Setting up the prompt is done with the “def” command,\nflows, allowing users to integrate AI capabil- which in this case associates the name FILES with the\nities into traditional software systems. contents of env.files. env.files is a variable that refers\nto the parameters (typically one or more files) that the\nIn the remainder of this paper, we describe the user ex-\nscript is invoked on. After this def command, when the\nperience of creating a GenAIScript, define key\nuser refers to FILES in the prompt, the LLM will know\nGenAIScript abstractions, highlight the capabilities of\nthey are referring to the contents of the files in\nthe framework, and describe several case studies based\nenv.files.\non our experiences building and deploying GenAIS-\ncripts in production setting. We discuss related work The text between $`…` in the figure is the prompt that\nand also our thoughts about future additions and fea- the LLM will process. The $`…` instructs the LLM\nwhat to do and refers to the names defined using def\ntures.\nsuch as FILE. This prompt is typically the final part\nof every GenAIScript. The prompt, augmented by any\n2. Introducing GenAIScript\ncontent defined by defs, will be passed to the LLM.\nWhen the LLM returns a result, it will be either be pro-\nGenAIScript was designed to provide a low barrier to\ncessed by GenAIScript, or returned directly.\nentry so that many users, including non-developers,\ncan quickly start using and writing scripts. However,\nThis example, when executed, will shorten the con-\nwe also want to enable power-users to leverage their\ntents of the input file as directed by the prompt. While\nprograming skills to create and deploy more sophisti-\nthe LLM generates a string as output, the GenAIScript\ncated scripts for more challenging scenarios. As a re-\nruntime understands standard output file formats, such\nsult, GeneAIScript is JavaScript compatible where the\nas code files (Python, etc.), markdown files, etc., so\nscripts can contain JavaScript code but less sophisti-\nthat if the prompt instructs the model to produce a file\ncated users can still define powerful and effective\nof a given type, the runtime will parse the resulting\nscripts using the simple abstractions we provide.\ngeneration and create and populate the file.\nIn this example, because the prompt says “shorten the\nfollowing FILE”, the LLM will generate another file\nTo understand GenAIScript, we present a simple com-\nwith the same name. The GenAIScript runtime will\nplete script in Figure 1.\ncreate the new version of the file and then, using the\nexisting refactoring feature that is part of VS Code,\npresent the differences between the original file and\nthe new file in the UI and ask the user to confirm the\n\nFigure 1: A simple GenAIScript\n\nThis example illustrates the key elements of every\nCommented [BZ2]: @Peli de Halleux , @Markus Kuppe ,\nGenAIScript: the metadata, the context, and the\n@Madan Musuvathi I added this description to the white\nprompt. We describe each element in turn.\npaper. Let me know what you think.\n\n2\n\n-------- Page Break --------\n\nedits (shown in Figure 2). research but due to the uncertain nature of the quality\nand robustness of multi-agent interactions, in GenAIS-\ncript we have chosen a different approach toward the\ngoal of creating more robust AISW.\nSpecifically, in GenAIScript, when a script executes\n4\nthere is a single call to the LLM. This approach al-\nlows the user to apply traditional techniques to im-\nprove their script’s software robustness (testing, etc.)\nleveraging many existing tools (debugging, refactor-\ning, etc.) that are part of IDEs like VS Code.\nEvery GenAIScript can be called from the command\nline. As a result, we encourage the integration of our\nFigure 2: Refactoring view of LLM output in GenAIScript\nscripts into existing POSW automation processes. We\nfrom script in Figure 1.\nbelieve that focusing the AISW on the specific hard\ntasks that POSW can’t do, and leveraging the enor-\n3. GenAIScript Abstractions\nmous robust POSW infrastructure, is the best way to\navoid known robustness challenges in building AISW.\nThe design of GenAIScript follows several principles:\nAs an aside, if a user writes a GenAIScript to generate\n- LLM at the bottom. By this we mean that\na program as output, say in Python, it is not automati-\nevery GenAIScript will use an LLM to\ncally executed. If the user wants to use GenAIScript\nachieve its goal. We firmly believe that if the\nto help write software by generating it automatically,\nuser wants to accomplish something that is\nthey still have to edit/execute/debug that software in a\neasily accomplished with POSW, they should\ntraditional manner.\n2\nuse that instead. Use GenAIScript for prob-\nlems that POSW cannot solve.\nParameterization\n- Control AI Behavior with a Static Orches-\ntration Graph. We do not permit the LLM\nFor scripts written in POSW, the parameters provide a\nin GenAIScripts to determine other AI\nway to generalize and customize the application of the\nscripts/agents to call and/or call them. In-\nscript. For example, they might specify the name of\nstead, a user can determine statically exactly\nan input file so that the script can be applied to many\nwhat LLM will be called and with prompt\ndifferent files. In general, for POSW, the input file\ncontext.\ndoes not affect how well the script itself executes or\n- Parameterizing context. We provide mech-\nwhat it does.\nanisms to bring external context into\nIn GenAIScript, the input provided can have enormous\nGenAIScripts as well as provide mechanisms\nimpact on what the script does and how well it does it.\nto structure that input to make it more com-\nThis happens because inputs to the script are:\nprehensible to the LLM.\n- Specifying and verifying outputs. GenAIS-\n- Typically text files provided for Retrieval\ncript supports numerous ways to specify and\nAugmented Generation (RAG)\ncheck output requirements for the AI-gener-\n- Almost always passed to the underlying LLM\nated content to ensure it conforms to the user\nto help it be more effective.\nspecifications.\nFor example, the prompt in a script might say:\nWith these principles in mind, we discuss the key\nGenAIScript abstractions.\nStatic Orchestration Graph\nApproaches to allowing a collection of AI agents to be\ndefined and integrated have been proposed (for exam-\n3\nple, autogen). This is an exciting area of current\n\n2 4\nNote that AI, such as GitHub Copilot, might still be GenAIScripts do support inner prompts, but in these\nused to help write that software. cases the LLM invocation is still statically defined.\n3\nhttps://github.com/microsoft/autogen\n\n3\n\n-------- Page Break --------\n\n$`You are an expert Lua programmer and Because LLMs are so flexible, we are just starting to\nyou will write a function that implements a understand the best way to factor the parameterization\n5\nand specification of tasks in tools like GenAIScript. As\nTimsortsorting algorithm.`\na result, we provide a second, more flexible interface\nThe underlying model may not know much about Lua\nto provide context to the GenAIScript called a GPSpec\nprogramming and/or not be aware of the Timsort algo-\n(Generative Programming Spec) defined with the ex-\nrithm. By augmenting the GenAIScript with refer-\ntension .gpspec.md. This file is a simple markdown\nences to context that describes both Lua and Timsort,\nfile that provides more input to the GenAIScript in two\nthe quality of the resulting generation can be greatly\nways. Any links present in the gpspec file are accessi-\nimproved.\nble in the script via env.links. The textual contents of\nthe gpspec file can also be accessed via env.gpspec.\nA key abstraction in GenAIScript is the ability to de-\nfine input sources (that are included in the prompt con-\nAs an example, a GenAIScript can be written to act as\ntext) and allow them to be referred to in the LLM\na generic expert code generating program in a specific\nprompt.\nlanguage, such as our example of Lua above. In this\nuse case, a GPSpec file could be written that directs\nContext (env + def)\nthe GenAIScript on the specific code generating task\nat hand (such as writing an implementation of Tim-\nIn GenAIScript, the env variable forms the root of con-\nsort).\ntent from which the LLM prompt context can be gen-\nCommented [BZ4]: Need a better example/explanation of\nerated. Using env to define the context allows the\nusing a GPSpec here.\nSpecifying and Verifying Outputs\nscripts to be portable and easily parameterized. For\nCommented [BZ5]: We special case output to files by tell-\nexample, env often refers to the directory in which the\nA key element of robust software is the ability to spec-\ning the LLM how to express that kind of output. Should we\nscript is run and env.files refers to all the files in that\nify and check the output of a function. Because LLMs\nmention this in the paper?\ndirectory. The command: def(“FILES”, env.files) eas-\nby their design generate sequences of tokens, layers of\nily provides the content of all the files in the directory\nsoftware are needed to enforce more structure on the\nto the LLM.\ngenerated output. For example, it is often desirable\nthat the LLM output be syntactically well-formed\nIn the example above, we could place two files in the\nJSON.\ncurrent directory: 1) an overview of the Lua program-\nming language in language.pdf, and 2) a description of\nNumerous efforts have been made to constrain LLM\nthe Timsort algorithm in sort.pdf. We can then greatly 6\noutput. GenAIScript supports several mechanisms to\nimprove the LLM performance on the above prompt\nenforce output specifications on the LLM generations.\nwith the code:\nFirst, it provides a mechanism, defSchema, to define a\nJSON/YAML format for the generated output. Fol-\ndef(“LANG”, env.files, {matches: “language”})\nCommented [BZ3]: I need to find the best way to embed\nlowing the “All You Need Is Types” approach from\ncode into a Word doc.\nTypeChat, the schema is converted to TypeScript types\ndef(“SORT”, env.files, {matches: “sort”})\nbefore being injected in the LLM prompt. When def-\nWe can now rewrite the prompt above to make the re-\nSchema is used, GenAIScript will automatically vali-\nsulting script much more general and more likely to\ndate the resulting generation against the specification\ngenerate a correct result:\nand either attempt repair or fail, depending on what the\nscript specifies.\n$`You are an expert in the language described in\nLANG and you will write a function that imple-\nGenAIScript also supports a more sophisticated con-\nments the sorting algorithm described in SORT.`\ntrol over LLM generation via the AI Controller Inter-\n7\nface system (AICI).Using AICI, the script can define\nUsing the def and env mechanisms in GenAIScript, the\nmuch richer constraints on the LLM generations. Ex-\nabove script is entirely parameterize by both program-\namples of the kinds of constraints expressible can be\nming language and sorting algorithm.\nGPSpec\n\n5 6\nTimsort is a real sorting algorithm, described here: Pydantic validators (Minimize LLM Hallucinations\nTimsort — the fastest sorting algorithm you’ve never with Pydantic Validators - Pydantic Blog), TypeChat\nheard of | by Brandon Skerritt | HackerNoon.com | Me- (https://microsoft.github.io/TypeChat/blog/introduc-\ndium ing-typechat/), etc.\n7\nAICI | GenAIScript (microsoft.github.io)\n\n4\n\n-------- Page Break --------\n\n8\nfound in the Guidance prompt language. For example,\n7. Next Steps\nthe user can specify that the LLM output must match\nan arbitrary regular expression or be an exact substring\n8. Conclusion\nof the input prompt.\nUltimately, we believe that the ability to express and\nenforce rich constraints on LLM generations will be\ncritical in the widespread adoption of AISW. Our goal\nwith GenAIScript is to support the latest developments\nin such specifications and incorporate the related im-\nplementation mechanisms (such as AICI) into our lan-\nguage runtime.\n\n4. GenAIScript Implementation\nBased on the principles and mechanisms defined\nabove, we provide an overview of how GenAIScript is\nimplemented.\nIn its current form, a GenAIScript is a JavaScript pro-\ngram that incorporates several enhancements:\n- Syntax modifications to easily define con-\ntext, prompts, etc.\n- Targeted LLM system prompts to support\ncommunicating information about both ex-\npected inputs and outputs to the LLM\n- Runtime libraries that support LLM interac-\ntions and parsing LLM outputs.\nWe consider each of these elements in turn.\nGenAIScript Syntax\n\n5. Case Studies\n\n6. Related Work\nExamples:\n- Langchain\n- Semantic kernel\n- Autogen\n\n8\nguidance-ai/guidance: A guidance language for con-\ntrolling large language models. (github.com)\n\n5\n```\n\nGiven the paper in FILE, write a 140 character summary of the paper \nthat makes the paper sound exciting and encourages readers to look at it.\n\n" } ] } ], "stream": true } ``````📩 llm response
output
````markdown ```markdown Discover GenAIScript: a new scripting language integrating AI models to automate complex tasks, revolutionizing code generation and software dev! ``` ````vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 a9j8j154:30646983 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 ccp2r3:30993541 dsvsc020:30976470 pythonait:31006305 gee8j676:31009558 dsvsc021:30996838 gd77d436:30999572 jg8ic977:31013176