-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add Pyodide Apps (EXPERIMENTAL) #33
Add Pyodide Apps (EXPERIMENTAL) #33
Conversation
Codecov ReportAll modified lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
=======================================
Coverage ? 98.41%
=======================================
Files ? 2
Lines ? 63
Branches ? 0
=======================================
Hits ? 62
Misses ? 1
Partials ? 0 ☔ View full report in Codecov by Sentry. |
OpenAI Mock Experiments.The purpose of these experiments it to "prove" that
Server Side Python Codeimport openai
question="Tell me what HoloViz Panel is in one sentence."
print("Question: ", question)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": question}],
stream=False,
)
print("Answer: ", response["choices"][0]["message"]["content"]) Client Side Javascript+Pyodide codeInsert your own OpenAI <!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>
</head>
<body>
Open your browser console to see Pyodide openai output
<script type="text/javascript">
async function main(){
let OpenAI = await import("https://cdn.jsdelivr.net/npm/[email protected]/+esm")
let openai = {
ChatCompletion: {
acreate: async function(config){
openAI = new OpenAI.OpenAI({ apiKey: "INSERT KEY HERE", dangerouslyAllowBrowser: true });
response = await openAI.chat.completions.create(config, { timeout: 60000 })
return response
}
}
}
let pyodide = await loadPyodide();
pyodide.registerJsModule("openai", openai);
pyodide.setDebug(true);
await pyodide.runPythonAsync(`
from js import Object
from pyodide.ffi import to_js
import openai
question="Tell me what HoloViz Panel is in one sentence."
print("Question: ", question)
response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo",
messages=to_js([{"role": "user", "content": question}], dict_converter=Object.fromEntries),
stream=False,
)
print("Answer: ", response.to_py()["choices"][0]["message"]["content"])
`);
}
main();
</script>
</body>
</html> It works except that
|
Superseeded by #73 |
THIS IS CURRENTLY AN EXPERIMENT.
BUILDS ON #12. Review that one first.
I wanted to figure out whether we can deploy the apps to Pyodide as discussed on Discord.
Todo
index.md
file to include link to apps (See below)hatch
shortcut commandsImportError
. See belowopenai
python lib withopenai
js lib (and similar for other api libs)Docs
ImportError