Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jezekra1 committed Dec 9, 2024
1 parent 3eda431 commit 0cba6ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
22 changes: 6 additions & 16 deletions src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import runPy from './python/run.py?raw'
import runPy from './python/run.py?raw';

declare global {
const stlite: any;
Expand Down Expand Up @@ -43,24 +43,23 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl
const { classList } = document.body;

switch (data.type) {
case 'setFullscreen':
case 'bee:setFullscreen':
classList.toggle('fullscreen', data.value);

return;
case 'updateTheme':
case 'bee:updateTheme':
classList.remove(data.theme === 'light' ? 'cds--g90' : 'cds--white');
classList.add(data.theme === 'light' ? 'cds--white' : 'cds--g90');

return;
case 'updateCode':
case 'bee:updateCode':
await app.writeFile('app.py', data.code);
await app.writeFile('config.json', JSON.stringify(data.config ?? {}));
await app.writeFile('trigger.py', 'import run; await run.run(); # ' + Math.random());

return;
case 'bee:response':
app.kernel._worker.postMessage(data);

return;
default:
return;
Expand All @@ -72,20 +71,11 @@ const ALLOWED_ORIGINS = (import.meta.env.VITE_ALLOWED_FRAME_ANCESTORS ?? '').spl
switch (data.type) {
case 'bee:reportError':
ALLOWED_ORIGINS.forEach((origin: string) =>
parent.postMessage({ type: 'reportError', errorText: data?.errorText }, origin),
parent.postMessage({ type: data.type, errorText: data?.errorText }, origin),
);
return;
case 'bee:request':
const response = {
type: 'bee:response',
request_id: data.request_id,
payload: {
message: 'THIS IS GOOD!'
}
}
console.log('bee:request %o, sending response %o', data, response)
app.kernel._worker.postMessage(response);
// ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage(data, origin));
ALLOWED_ORIGINS.forEach((origin: string) => parent.postMessage(data, origin));
return;
default:
return;
Expand Down
5 changes: 2 additions & 3 deletions src/python/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
import asyncio
import runpy
import functools
import importlib
import inspect
Expand Down Expand Up @@ -111,7 +112,6 @@ async def wrapper(*args, **kwargs):
response = await request(
"/v1/chat/completions",
{
"model": "runtime",
"messages": messages,
"temperature": 0.8 if creative else 0.0,
"max_tokens": 4096,
Expand All @@ -127,7 +127,6 @@ async def wrapper(*args, **kwargs):
return return_type_adapter.validate_json(response.message)

return wrapper

return _llm_function


Expand Down Expand Up @@ -198,7 +197,7 @@ async def translate_modules_to_packages(modules):
"/modules-to-packages",
{"modules": unknown_modules},
)
if not getattr(response, 'error'):
if not getattr(response, 'error', None):
packages += response.packages
return packages

Expand Down

0 comments on commit 0cba6ad

Please sign in to comment.