Skip to content

Commit

Permalink
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core
Browse files Browse the repository at this point in the history
… into gh-pages
  • Loading branch information
phischdev committed Jun 20, 2024
2 parents c49af8e + 2ca027c commit 4e5556a
Show file tree
Hide file tree
Showing 560 changed files with 35,205 additions and 34,915 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The Lively4 server and GitHub sync tools can check out arbitrary projects, such

## Authors / Contributors

- [Sofware Architecture Group](https://www.hpi.uni-potsdam.de/hirschfeld/), [Hasso Plattner Institute](https://www.hpi.de), 2015-2021 [MIT LICENSE](LICENSE)
- [Sofware Architecture Group](https://www.hpi.uni-potsdam.de/hirschfeld/), [Hasso Plattner Institute](https://www.hpi.de), 2015-2024 [MIT LICENSE](LICENSE)
- Jens Lincke, Stefan Ramson, Tim Felgentreff, Fabio Niephaus, Robert Hirschfeld, Marcel Taeumel
- Seminars
<!--
Expand Down
21 changes: 21 additions & 0 deletions demos/contextjs/showfocuslayer.md
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()
```
1 change: 0 additions & 1 deletion demos/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ function count(list) {
}

var result = count([1,2,3,2345,234,234,23,4,23,4])

20 changes: 19 additions & 1 deletion demos/javascript/a.js
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
}

}
1 change: 1 addition & 0 deletions demos/javascript/double-import.js
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
Expand Down
28 changes: 28 additions & 0 deletions demos/markdown/scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@









<script>


class Foo {

async init() {

}

setupListeners() {
this.s
}

setupFoo() {

}
}

</script>
13 changes: 13 additions & 0 deletions demos/markdown/test.html
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>
29 changes: 29 additions & 0 deletions demos/markdown/test.md
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>
3 changes: 3 additions & 0 deletions demos/markdown/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
let a = <span>x</span>, b = 3;
</script>
3 changes: 3 additions & 0 deletions demos/markdown/test2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
let a = <span>x</span>, b = 3;
</script>
108 changes: 108 additions & 0 deletions demos/openai/functions.md
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>
92 changes: 49 additions & 43 deletions demos/openai/image.md
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>

Loading

0 comments on commit 4e5556a

Please sign in to comment.