Closed MarcSkovMadsen closed 11 months ago
All modified lines are covered by tests :white_check_mark:
:exclamation: No coverage uploaded for pull request base (
main@5b56b23
). Click here to learn what that means.
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
The purpose of these experiments it to "prove" that
panel convert
we can patch/ mock the javascript/ python/ pyodide code such that it can still run as expected. But now in the browser onlyimport 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"])
Insert your own OpenAI apiKey
below.
<!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/openai@4.11.1/+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