-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core…
… into gh-pages
- Loading branch information
Showing
560 changed files
with
35,205 additions
and
34,915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# ShowFocus Layer | ||
|
||
And I wrote it again.... Because I did not look for <edit://demos/contextjs/showfocuslayer.js> first | ||
|
||
```js | ||
import * as cop from "src/client/ContextJS/src/contextjs.js"; | ||
|
||
cop.layer(window, "ShowFocus").refineClass(HTMLElement, { | ||
|
||
focus(...args) { | ||
lively.showElement(this) | ||
console.log("focus " + this, lively.stack()) | ||
return cop.proceed(...args) | ||
} | ||
|
||
}) | ||
|
||
ShowFocus.beGlobal() | ||
|
||
ShowFocus.beNotGlobal() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,3 @@ function count(list) { | |
} | ||
|
||
var result = count([1,2,3,2345,234,234,23,4,23,4]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
// a.js | ||
"disable deepeval" | ||
export const value = 44; | ||
export const value = 44; | ||
|
||
|
||
function hello2() { | ||
var a = 3 + 4 | ||
} | ||
|
||
hello2() | ||
|
||
|
||
|
||
class Foo { | ||
|
||
|
||
hello2() { | ||
var a = 3 + 4 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import {value} from "./a.js" | ||
import {value} from "./a.js" | ||
|
||
|
||
var foo =3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<script> | ||
|
||
|
||
class Foo { | ||
|
||
async init() { | ||
|
||
} | ||
|
||
setupListeners() { | ||
this.s | ||
} | ||
|
||
setupFoo() { | ||
|
||
} | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<html> | ||
<body> | ||
<h1 aasdf="">Hello</h1> | ||
|
||
<script> | ||
|
||
let b = <button>xx</button> | ||
let c = "foo" | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
<script> | ||
|
||
import {AudioRecorder} from "src/client/audio.js" | ||
|
||
</script> | ||
|
||
|
||
|
||
<script> | ||
|
||
var foo = <span>x</span>, b = 3; | ||
|
||
const x | ||
|
||
|
||
class Foo { | ||
|
||
async bla() { | ||
|
||
} | ||
|
||
bar() { | ||
|
||
} | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
let a = <span>x</span>, b = 3; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
let a = <span>x</span>, b = 3; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# AI Function Calling | ||
|
||
<script> | ||
import OpenAI from "demos/openai/openai.js" | ||
|
||
let maxCalls = 3 | ||
let calls = 0 | ||
|
||
function getCurrentDateTime() { | ||
return new Date().toLocaleString(); | ||
} | ||
|
||
const functions = { | ||
getCurrentDateTime: getCurrentDateTime, | ||
}; | ||
|
||
|
||
async function handleFunctionCall(functionName, args) { | ||
if (functions[functionName]) { | ||
return functions[functionName](...args); | ||
} else { | ||
throw new Error(`Function ${functionName} not found`); | ||
} | ||
} | ||
|
||
let messages = [ | ||
{ "role": "system", "content": "You are an AI chat bot!" }, | ||
{ "role": "user", "content": [ | ||
{ | ||
"type": "text", | ||
"text": "What is the current time?" | ||
} | ||
]} | ||
] | ||
|
||
|
||
async function chat() { | ||
calls++ | ||
if (calls > maxCalls) { | ||
lively.warn("max calls reached") | ||
return | ||
} | ||
|
||
let prompt = { | ||
"model": "gpt-4o", | ||
"max_tokens": 2000, | ||
"temperature": 0.1, | ||
"top_p": 1, | ||
"n": 1, | ||
"stream": false, | ||
"stop": "VANILLA", | ||
"messages": messages, | ||
"functions": [ | ||
{ | ||
"name": "getCurrentDateTime", | ||
"description": "Fetches the current date and time", | ||
|
||
}, | ||
{ | ||
name: "addNumbers", | ||
description: "Adds two numbers", | ||
parameters: { | ||
type: "object", | ||
properties: { | ||
a: { type: "number" }, | ||
b: { type: "number" } | ||
}, | ||
required: ["a", "b"] | ||
} | ||
} | ||
] | ||
} | ||
|
||
let json = await OpenAI.openAIRequest(prompt).then(r => r.json()) | ||
if (!json.choices) { | ||
result.textContent += JSON.stringify(json, undefined, 2) | ||
return | ||
} | ||
|
||
|
||
let message = json.choices[0].message | ||
messages.push(message) | ||
|
||
result.textContent = JSON.stringify(messages, undefined, 2) | ||
|
||
if (message.function_call) { | ||
const functionName = message.function_call.name; | ||
const args = message.function_call.arguments || []; | ||
const result = await handleFunctionCall(functionName, args); | ||
|
||
|
||
messages.push({ | ||
role: 'function', | ||
name: functionName, | ||
content: JSON.stringify(result) | ||
}) | ||
chat() | ||
} | ||
} | ||
|
||
let result = <div style="white-space: pre-wrap"></div> | ||
|
||
let pane = <div> | ||
<button click={() => chat()}>chat</button> | ||
{result} | ||
</div> | ||
pane | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,55 @@ | ||
# Image Generation | ||
|
||
```javascript | ||
import OpenAI from "demos/openai/openai.js" | ||
|
||
|
||
let prompt = { | ||
"model": "dall-e-3", | ||
"prompt": "a white siamese cat", | ||
"n": 1, | ||
"size": "1024x1024" | ||
} | ||
|
||
|
||
async function imageGeneration(prompt) { | ||
const apiKey = await OpenAI.ensureSubscriptionKey(); | ||
const url = "https://api.openai.com/v1/images/generations"; | ||
|
||
const requestOptions = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${apiKey}` | ||
}, | ||
body: JSON.stringify(prompt) | ||
}; | ||
return fetch(url, requestOptions); | ||
} | ||
|
||
|
||
let response = await imageGeneration(prompt) | ||
|
||
|
||
reso | ||
|
||
let json = await response.json() | ||
|
||
|
||
json.data[0].url | ||
|
||
``` | ||
|
||
<script> | ||
|
||
let img = <img src="https://oaidalleapiprodscus.blob.core.windows.net/private/org-MPQoSTR6cnoOYKKoexRQqilJ/user-jSdR6BwdMFDIgdYmJiwmPPyY/img-5tGP5Ewc7Ro54jL8nqRNwhHC.png?st=2024-05-14T15%3A39%3A06Z&se=2024-05-14T17%3A39%3A06Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-05-14T15%3A40%3A46Z&ske=2024-05-15T15%3A40%3A46Z&sks=b&skv=2021-08-06&sig=VyLOR1dYBJBs0z7KzG/n/XXIk2lXWQ%2BJ4B29xSB5HZQ%3D"></img> | ||
import OpenAI from "demos/openai/openai.js" | ||
|
||
|
||
img | ||
async function generate() { | ||
let prompt = { | ||
"model": "dall-e-3", | ||
"prompt": input.value, | ||
"n": 1, | ||
"size": "1024x1024" | ||
} | ||
|
||
|
||
async function imageGeneration(prompt) { | ||
const apiKey = await OpenAI.ensureSubscriptionKey(); | ||
const url = "https://api.openai.com/v1/images/generations"; | ||
|
||
const requestOptions = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${apiKey}` | ||
}, | ||
body: JSON.stringify(prompt) | ||
}; | ||
return fetch(url, requestOptions); | ||
} | ||
|
||
let start = performance.now() | ||
let response = await imageGeneration(prompt) | ||
|
||
let json = await response.json() | ||
result.innerHTML = "" | ||
result.appendChild(<div>time {performance.now() - start}ms</div>) | ||
result.appendChild(<div>{json.data[0].revised_prompt}</div>) | ||
img.src = json.data[0].url | ||
|
||
} | ||
|
||
let img = <img></img> | ||
let input = <input value="a white siamese cat"></input> | ||
let result = <div></div> | ||
|
||
let pane = <div> | ||
{input} | ||
<button click={() => generate()}>generate</button> | ||
{result} | ||
{img} | ||
</div> | ||
|
||
pane | ||
</script> | ||
|
Oops, something went wrong.