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

Launch Anvil From the Client #105

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
66cf000
squashing commits
kaganrua Sep 23, 2024
cb72b8d
save changes
kaganrua Sep 23, 2024
12f1d61
save changes
kaganrua Sep 23, 2024
8047972
save changes
kaganrua Sep 23, 2024
3960437
fixed blockSerialization
kaganrua Sep 23, 2024
cc5a470
push this commit to compare with main
kaganrua Sep 23, 2024
35369af
save
kaganrua Sep 23, 2024
caba445
save changes
kaganrua Sep 23, 2024
9f51c48
saving my changes
kaganrua Sep 23, 2024
e6b269a
test succesful
kaganrua Sep 23, 2024
2a376c7
fix io
kaganrua Sep 23, 2024
a59b7f2
fix tests
kaganrua Sep 23, 2024
b627786
minor fix before test
kaganrua Sep 24, 2024
a9af5f2
remove unnecessary code from previos commits
kaganrua Sep 24, 2024
bfa804e
save changes
kaganrua Sep 24, 2024
f319816
fix container testing
kaganrua Sep 24, 2024
713357d
lint format
kaganrua Sep 24, 2024
e4e6a02
0.4.0
kaganrua Sep 24, 2024
c518729
fix zoom to pointer (#214)
jmagoon Sep 24, 2024
540cc15
squashing commits
kaganrua Sep 23, 2024
b229dca
save changes
kaganrua Sep 23, 2024
cd0704b
save changes
kaganrua Sep 23, 2024
454eb61
save changes
kaganrua Sep 23, 2024
e64b7f3
fixed blockSerialization
kaganrua Sep 23, 2024
95fc4ba
push this commit to compare with main
kaganrua Sep 23, 2024
5e06f06
save
kaganrua Sep 23, 2024
eb2d339
save changes
kaganrua Sep 23, 2024
4a8c4d9
saving my changes
kaganrua Sep 23, 2024
1842101
test succesful
kaganrua Sep 23, 2024
5f5f650
fix io
kaganrua Sep 23, 2024
2b19f13
fix tests
kaganrua Sep 23, 2024
18d2365
minor fix before test
kaganrua Sep 24, 2024
00160d7
remove unnecessary code from previos commits
kaganrua Sep 24, 2024
e175421
save changes
kaganrua Sep 24, 2024
444a18f
fix container testing
kaganrua Sep 24, 2024
805cbec
lint format
kaganrua Sep 24, 2024
afc5af8
0.4.0
kaganrua Sep 24, 2024
863abd0
Merge branch 'f/client-launch-anvil' of https://github.com/zetane/zet…
kaganrua Sep 26, 2024
d37ebd4
fix minor overflow issue
kaganrua Sep 26, 2024
d6635cc
remove unnecessary logs
kaganrua Sep 26, 2024
f21150c
saving changes
kaganrua Sep 26, 2024
cbbf341
optimization done
kaganrua Sep 27, 2024
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
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"BucketName":"zetaforge",
"Database":"./zetaforge.db",
"SetupVersion":"1",

"KubeContext": "docker-desktop",
"Local": {
"BucketPort": 8333,
"Driver": "docker-desktop"
Expand Down
12 changes: 2 additions & 10 deletions deploy_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ def get_download_file(client_version, system, arch):
bucket_key += ".tar.gz"
return bucket_key

def upload_to_s3(file_path, object_key):
s3_client = boto3.client('s3')
bucket_name = 'forge-executables-test'

try:
with open(file_path, 'rb') as file:
s3_client.upload_fileobj(file, bucket_name, object_key)
print(f"File {file_path} uploaded to S3 bucket {bucket_name} as {object_key}")
except Exception as e:
print(f"Error uploading file to S3: {str(e)}")

def get_package_version():
# Specify the path to the package.json file
Expand Down Expand Up @@ -82,7 +73,8 @@ def main():
frontend = os.path.join("frontend", "server2")
os.makedirs(frontend, exist_ok=True)
res = subprocess.run('npm install', cwd="frontend", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)



for os_ in os_list:
print(f"Compiling {version} for {os_}..")
for goarch in args.arch:
Expand Down
4 changes: 2 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func terminateArgo(ctx context.Context, cfg Config, db *sql.DB, name string, id

func buildImage(ctx context.Context, source string, tag string, logger *log.Logger, cfg Config) error {
if cfg.Local.Driver == "minikube" {
minikubeBuild := cmd.NewCmd("minikube", "-p", "zetaforge", "image", "build", "-t", tag, source)
minikubeBuild := cmd.NewCmd("minikube", "-p", cfg.KubeContext, "image", "build", "-t", tag, source)
minikubeChan := minikubeBuild.Start()
lineCount := 0
done := false
Expand Down Expand Up @@ -542,7 +542,7 @@ func buildImage(ctx context.Context, source string, tag string, logger *log.Logg
}
}

minikubeImage := cmd.NewCmd("minikube", "-p", "zetaforge", "image", "ls")
minikubeImage := cmd.NewCmd("minikube", "-p", cfg.KubeContext, "image", "ls")
<-minikubeImage.Start()
for _, line := range minikubeImage.Status().Stdout {
if "docker.io/"+tag == line {
Expand Down
74 changes: 74 additions & 0 deletions frontend/agents/gpt-4_python_compute/generate/computations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Configuration, OpenAIApi } from "openai";
const openaiSystemContent = `You are an assistant that generates python code and returns it in a way that must follow the template below.
You absolutely need to give a python code section without abbreviation that follows the template. Do not put code lines at the root, but give only the functions and imports.

By default, when requested to do change or add to the code, modify the latest code section. But when the user ask to do it on another section, do so.

In the template, the function compute contains the code and the function test contains a series of call to compute that runs and prints multiple tests.

Don't insert a __main__ section.

Template:
import ...

def compute(in1, in2, in3,...):
'''A textual description of the compute function.'''

#some code
return {{'out1': out1, 'out2': out2, ...}}

def test():
# Call compute multiple times based on a series of inputs. The outputs are then compare with the expected outputs. Print the results and indicate if the tests passed.
`;

function extractPythonCode(response) {
const patternBackticks = /```python\n(.*?)```/gs;
const matchesBackticks = [...response.matchAll(patternBackticks)];
if (matchesBackticks.length === 0) {
return response;
}
const processedCodeBlocks = matchesBackticks.map((match) => {
let codeBlock = match[1];
codeBlock = codeBlock.replace(/^\s*compute\(.*?\)\s*$/gm, "");
codeBlock = codeBlock.replace(/^\s*test\(.*?\)\s*$/gm, "");
return codeBlock.trim();
});
return processedCodeBlocks.join("\n\n");
}

export async function computeAgent(
userPrompt,
modelVersion,
conversationHistory,
apiKey,
) {
if (conversationHistory.length > 0) {
conversationHistory = [conversationHistory[conversationHistory.length - 1]];
}

const escapedHistory = [];
for (const entry of conversationHistory) {
const prompt = entry.prompt.replace(/{/g, "{{").replace(/}/g, "}}");
const response = entry.response.replace(/{/g, "{{").replace(/}/g, "}}");
escapedHistory.push({ role: "user", content: prompt });
escapedHistory.push({ role: "assistant", content: response });
}

const messages = [
{ role: "system", content: openaiSystemContent },
...escapedHistory,
];
messages.push({ role: "user", content: userPrompt });

const configuration = new Configuration({ apiKey: apiKey });
const openai = new OpenAIApi(configuration);

const response = await openai.createChatCompletion({
model: modelVersion,
messages: messages,
});

const code = extractPythonCode(response.data.choices[0].message.content);

return { response: code, model: modelVersion };
}
96 changes: 96 additions & 0 deletions frontend/agents/gpt-4_python_view/generate/computations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Configuration, OpenAIApi } from "openai";
const openaiSystemContent = `You are an assistant that generates python code and returns it in a way that must follow the template below. Your goal is to generate a view.html file that satisfy the user requirement.
Most importantly, you must rely on the prompt to generate the html_template file that satisfy the user request. The html should contain everything to display in a browser and must rely on CDN or skypack when needed.
You absolutely need to give a python code section without abbreviation that follows the template. Do not put code lines at the root, but give only the functions and imports.

By default, when requested to do change or add to the code, modify the latest code section. But when the user asks to do it on another section, do so.

In the template, the function compute contains the code and the function test contains a series of call to compute that runs and prints multiple tests.

Don't insert a __main__ section.

Template:
from string import Template

def compute(in1):
'''Generates an HTML file with a unique name and returns the file name.'''

html_template = Template(\`
<!DOCTYPE html>
<html>
<head>
<title>Hello Block View</title>
</head>
<body>
\${in1}
</body>
</html>
\`)

# Build and save the html file
html_path = f"view.html"
html_code = html_template.substitute(in1=in1)
with open(html_path, "w") as file:
file.write(html_code)

return {{'html': f"view.html"}}

def test():
'''Test the compute function.'''

print('Running test')
result = compute('Hello view block')
print(f"Generated HTML file: {{result['html']}}")
`;

function extractPythonCode(response) {
const patternBackticks = /```python\n(.*?)```/gs;
const matchesBackticks = [...response.matchAll(patternBackticks)];
if (matchesBackticks.length === 0) {
return response;
}
const processedCodeBlocks = matchesBackticks.map((match) => {
let codeBlock = match[1];
codeBlock = codeBlock.replace(/^\s*compute\(.*?\)\s*$/gm, "");
codeBlock = codeBlock.replace(/^\s*test\(.*?\)\s*$/gm, "");
return codeBlock.trim();
});
return processedCodeBlocks.join("\n\n");
}

export async function computeViewAgent(
userPrompt,
modelVersion,
conversationHistory,
apiKey,
) {
if (conversationHistory.length > 0) {
conversationHistory = [conversationHistory[conversationHistory.length - 1]];
}

const escapedHistory = [];
for (const entry of conversationHistory) {
const prompt = entry.prompt.replace(/{/g, "{{").replace(/}/g, "}}");
const response = entry.response.replace(/{/g, "{{").replace(/}/g, "}}");
escapedHistory.push({ role: "user", content: prompt });
escapedHistory.push({ role: "assistant", content: response });
}

const messages = [
{ role: "system", content: openaiSystemContent },
...escapedHistory,
];
messages.push({ role: "user", content: userPrompt });

const configuration = new Configuration({ apiKey: apiKey });
const openai = new OpenAIApi(configuration);

const response = await openai.createChatCompletion({
model: modelVersion,
messages: messages,
});

const code = extractPythonCode(response.data.choices[0].message.content);

return { response: code, model: modelVersion };
}
2 changes: 0 additions & 2 deletions frontend/core/blocks/canny-edge/computations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os

import cv2
from PIL import Image


def compute(image_path, range_min, range_max, step):
"""
Computes the Canny edge detection on an image at various thresholds and saves the results.
Expand Down
11 changes: 9 additions & 2 deletions frontend/electron-builder.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
* @see https://www.electron.build/configuration/configuration
*/
{
afterPack: "./macPacker.cjs",
appId: "com.zetane.zetaforge",
productName: "ZetaForge",
asar: true,
directories: {
output: "release/${version}",
},
files: ["dist-electron", "dist"],
files: ["dist-electron", "dist", "server"],
mac: {
artifactName: "${productName}-${version}-darwin-${arch}.${ext}",
target: ["tar.gz"],
binaries: ["launch.command"],
},
win: {
target: ["tar.gz"],
target: ["tar.gz", "zip"],
artifactName: "${productName}-${version}-windows-${arch}.${ext}",
},
linux: {
Expand Down Expand Up @@ -47,6 +49,11 @@
to: "resources",
filter: ["**/*"],
},
{
from: "./logs",
to: "logs",
filter: ["**/*"],
},
],
nsis: {
oneClick: false,
Expand Down
3 changes: 2 additions & 1 deletion frontend/electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ declare namespace NodeJS {
/** /dist/ or /public/ */
VITE_PUBLIC: string
}
}
}

Loading
Loading