-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
116 lines (100 loc) · 3.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
}
#header {
background-color: #f8f8f8;
padding: 20px;
border-bottom: 1px solid #ddd;
}
#content {
flex-grow: 1;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
#editor {
overflow-x: hidden;
}
#editor,
#results {
flex-basis: 50%;
border: 1px solid #ddd;
box-sizing: border-box;
padding: 20px;
}
#result {
width: 100%;
height: 100%;
border: none;
}
@media(max-width:600px) {
#editor,
#results {
flex-basis: 100%;
}
}
</style>
<title>Python to OpenAI function specification converter</title>
<meta charset="utf-8">
<link rel="stylesheet" href="pyscript.css" />
<script>
function setup() {
import("./codemirror.js").then((module) => {
basicSetup = window.CM["codemirror"].basicSetup
EditorView = window.CM["@codemirror/view"].EditorView
keymap = window.CM["@codemirror/view"].keymap
indentWithTab = window.CM["@codemirror/commands"].indentWithTab
python = window.CM["@codemirror/lang-python"].python
const doc = '"Type in your function declaration here..."'
editor = new EditorView({
doc,
extensions: [
basicSetup,
keymap.of([indentWithTab]),
python()
],
parent: document.getElementById("editor")
})
const intervalTime = 1000;
let lastVal = "";
let isLoaded = false;
function loadPyodideIfNeeded() {
if (!isLoaded) {
globalThis.loadPyodide();
isLoaded = true;
}
}
function validate() {
loadPyodideIfNeeded()
const val = editor.state.doc.toString();
if (val !== lastVal) {
lastVal = val;
pyscript.interpreter.run("validate(" + JSON.stringify(val) + ")");
}
}
setInterval(validate, intervalTime);
});
}
</script>
<script defer onload="setup()" src="pyscript.js"></script>
</head>
<body>
<div id="header">py2gpt - Convert Python Function Declarations into OpenAI Functions API</div>
<div id="content">
<div id="editor"></div>
<div id="results"><iframe id="result" srcdoc=""></iframe></div>
</div>
<py-script src="main.py"></py-script>
<py-config>
packages = ["docstring_parser", "rich"]
</py-config>
</body>
</html>