Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook support #540

Merged
merged 26 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/azure-cli:1.2.5": {}
"ghcr.io/devcontainers/features/azure-cli:1.2.5": {},
"ghcr.io/devcontainers/features/python:1.6.1": {}
}
}
23 changes: 23 additions & 0 deletions demo/genaisrc/poem.genaibook
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"cells": [
{
"type": "code",
"source": "$`Write a 1 sentence poem`",
"outputs": [
{
"items": [
{
"mime": "text/markdown",
"data": "496e20746865207175696574206d6561646f772c207768697370657273206f66207468652077696e642064616e636520776974682074686520646169736965732e"
}
]
}
]
},
{
"type": "code",
"source": "def(\"FILE\", env.vars.output.text)\n$`Summarize FILE`\n",
"outputs": []
}
]
}
4 changes: 0 additions & 4 deletions packages/core/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ export class Fragment {
Object.assign(this, init)
if (!this.fullId) this.fullId = this.id
}
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

get project() {
return this.file.project
}
}
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project getter method has been removed from the Fragment class but there is no replacement provided. If other parts of the codebase are using this method, this will cause a breakage.

generated by pr-review-commit unused_code


export function templateGroup(template: PromptScript) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export const XLSX_MIME_TYPE =
export const JSON_MIME_TYPE = "application/json"
export const JSON_SCHEMA_MIME_TYPE = "application/schema+json"
export const JAVASCRIPT_MIME_TYPE = "application/javascript"
export const MARKDOWN_MIME_TYPE = "text/markdown"
export const YAML_MIME_TYPE = "application/yaml"

export const JSON_META_SCHEMA_URI =
"https://json-schema.org/draft/2020-12/schema"
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export function fenceMD(t: string, contentType?: string) {
export function link(text: string, href: string) {
return href ? `[${text}](${href})` : text
}

export function details(summary: string, body: string) {
return `\n<details><summary>${summary}</summary>

${body}

</summary></details>\n`
}
38 changes: 38 additions & 0 deletions packages/sample/src/jupytest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.11.2' requires the ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/bin/python3 -m pip install ipykernel -U --user --force-reinstall'"
]
}
],
"source": [
"x = 1\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
41 changes: 41 additions & 0 deletions packages/sample/src/node.nnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"cells": [
{
"language": "typescript",
"source": [
"var x = 2\ny =1"
],
"outputs": [
{
"items": [
{
"mime": "text/plain",
"value": [
"\u001b[33m1\u001b[39m"
]
}
]
}
]
},
{
"language": "typescript",
"source": [
"// <reference path=\"../genaisrc/genaiscript.d.ts\" />\nconsole.log({ x,y})\n"
],
"outputs": [
{
"items": [
{
"mime": "application/vnd.code.notebook.stdout",
"value": [
"{ x: 2, y: 1 }",
""
]
}
]
}
]
}
]
}
48 changes: 48 additions & 0 deletions packages/sample/src/poem.genaibook

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
"activationEvents": [
"workspaceContains:**/*.gpspec.md",
"workspaceContains:**/*.genai.js"
"workspaceContains:**/*.genai.js",
"onNotebook:genaiscript"
],
"main": "./built/extension.js",
"bugs": {
Expand All @@ -56,6 +57,17 @@
"./icon-dark.svg"
],
"contributes": {
"notebooks": [
{
"type": "genaiscript",
"displayName": "GenAIScript",
"selector": [
{
"filenamePattern": "*.genaibook"
}
]
}
],
"markdown.previewStyles": [
"./markdown.css"
],
Expand Down Expand Up @@ -213,6 +225,11 @@
}
],
"commands": [
{
"command": "genaiscript.notebook.new",
"title": "New Notebook",
"category": "GenAIScript"
},
{
"command": "genaiscript.request.abort",
"title": "Abort OpenAI request",
Expand Down Expand Up @@ -347,4 +364,4 @@
"enabledApiProposals": [
"languageModels"
]
}
}
2 changes: 2 additions & 0 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { activateOpenAIRequestTreeDataProvider } from "./openairequesttree"
import { activateAIRequestTreeDataProvider } from "./airequesttree"
import { activateTestController } from "./testcontroller"
import { activateModelCompletionProvider } from "./modelcompletionprovider"
import { activateNotebook } from "./notebook"

export async function activate(context: ExtensionContext) {
const state = new ExtensionState(context)
Expand All @@ -22,6 +23,7 @@ export async function activate(context: ExtensionContext) {
activateOpenAIRequestTreeDataProvider(state)
activateStatusBar(state)
activateModelCompletionProvider(state)
activateNotebook(state)
// activateChatParticipant(state)

context.subscriptions.push(
Expand Down
Loading
Loading