From cfffb8be9860d5179a9104efcd466cce82643550 Mon Sep 17 00:00:00 2001 From: reng Date: Wed, 4 Jun 2025 15:23:25 +0800 Subject: [PATCH] udpate v1 --- index.js | 32 ++++++++++++++++++++++---- package-lock.json | 49 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + vite/index.html | 2 +- vite/public/favicon.ico | Bin 0 -> 15406 bytes vite/public/vite.svg | 1 - vite/src/App.jsx | 47 ++++++++++++++++++++++---------------- 7 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 vite/public/favicon.ico delete mode 100644 vite/public/vite.svg diff --git a/index.js b/index.js index 66d653c..1f50f88 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,7 @@ import OpenAI from "openai"; import express from "express"; import cors from "cors"; import { system_prompt } from "./system_prompt.js"; - -import { z } from "zod"; -import { zodResponseFormat } from "openai/helpers/zod"; +import { Client } from 'node-osc'; import { config } from "dotenv"; config(); // Load environment variables from .env file @@ -33,6 +31,15 @@ const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, }); +const osc_client = new Client('127.0.0.1', 8787); +osc_client.send('/test', 55555, (error) => { + if (error) { + console.error('Error sending OSC message:', error); + } else { + console.log('OSC message sent successfully'); + } +}); + // const response = await client.responses.create({ // model: "gpt-4.1", // input: "Write a one-sentence bedtime story about a unicorn." @@ -48,6 +55,11 @@ app.use(cors()); app.post("/generate", async (req, res) => { const { input } = req.body; + // console.log(input[input.length-1], 'input received'); + // osc_client.send('/prompt', input[input.length-1]?.content[0]?.text, (err) => { + // console.log('OSC', err ? `Error: ${err}` : 'Success'); + // }); + // return; try { const response = await client.responses.create({ @@ -74,8 +86,20 @@ app.post("/generate", async (req, res) => { }); console.log("Generated response:", response); + const json=JSON.parse(response.output_text); + + // send prompt to TD + osc_client.send('/prompt', json.prompt, (error) => { + if (error) { + console.error('Error sending OSC message:', error); + } else { + console.log('OSC message sent successfully'); + } + }); + + res.json(json); + - res.json(JSON.parse(response.output_text)); } catch (error) { console.error("Error generating response:", error); res.status(500).json({ error: "Failed to generate response" }); diff --git a/package-lock.json b/package-lock.json index 69f3fe9..4d384f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "cors": "^2.8.5", "dotenv": "^16.5.0", "express": "^5.1.0", + "node-osc": "^9.1.5", "openai": "^5.1.0", "zod": "^3.25.50" } @@ -28,6 +29,11 @@ "node": ">= 0.6" } }, + "node_modules/binpack": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/binpack/-/binpack-0.1.0.tgz", + "integrity": "sha512-KcSrsGiIKgklTWweVb9XnZPWO1/rGSsK3fwR7VnbDPbLKPlkvSKd/ZrJ1W712r6HzH5u0fa/AZCftATO09x8Aw==" + }, "node_modules/body-parser": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", @@ -482,6 +488,17 @@ "node": ">= 0.6" } }, + "node_modules/node-osc": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/node-osc/-/node-osc-9.1.5.tgz", + "integrity": "sha512-m8f+VMhgrFmxORP6HAH2ISM4zA4yCoYlT9RFaESmX/2433LNHTv5fx3/StyCYXHlYV9aR9lDgXXdu9rMnnjXtg==", + "dependencies": { + "osc-min": "^1.1.1" + }, + "engines": { + "node": "^18.17.0 || ^20.5.0 || >=22.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -540,6 +557,17 @@ } } }, + "node_modules/osc-min": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/osc-min/-/osc-min-1.1.2.tgz", + "integrity": "sha512-8DbiO8ME85R75stgNVCZtHxB9MNBBNcyy+isNBXrsFeinXGjwNAauvKVmGlfRas5VJWC/mhzIx7spR2gFvWxvg==", + "dependencies": { + "binpack": "~0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -820,6 +848,11 @@ "negotiator": "^1.0.0" } }, + "binpack": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/binpack/-/binpack-0.1.0.tgz", + "integrity": "sha512-KcSrsGiIKgklTWweVb9XnZPWO1/rGSsK3fwR7VnbDPbLKPlkvSKd/ZrJ1W712r6HzH5u0fa/AZCftATO09x8Aw==" + }, "body-parser": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", @@ -1136,6 +1169,14 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==" }, + "node-osc": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/node-osc/-/node-osc-9.1.5.tgz", + "integrity": "sha512-m8f+VMhgrFmxORP6HAH2ISM4zA4yCoYlT9RFaESmX/2433LNHTv5fx3/StyCYXHlYV9aR9lDgXXdu9rMnnjXtg==", + "requires": { + "osc-min": "^1.1.1" + } + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -1168,6 +1209,14 @@ "integrity": "sha512-YQBgPJykHrDOlngB/8QpOsFNg36yofBatpeDWg1zejl9R59/ELuN7AMPSU95ZIdChbKc/o5vg1UnBJ1OEB0IJA==", "requires": {} }, + "osc-min": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/osc-min/-/osc-min-1.1.2.tgz", + "integrity": "sha512-8DbiO8ME85R75stgNVCZtHxB9MNBBNcyy+isNBXrsFeinXGjwNAauvKVmGlfRas5VJWC/mhzIx7spR2gFvWxvg==", + "requires": { + "binpack": "~0" + } + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", diff --git a/package.json b/package.json index 83844b3..d1982f3 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "cors": "^2.8.5", "dotenv": "^16.5.0", "express": "^5.1.0", + "node-osc": "^9.1.5", "openai": "^5.1.0", "zod": "^3.25.50" } diff --git a/vite/index.html b/vite/index.html index 59316f2..f156110 100644 --- a/vite/index.html +++ b/vite/index.html @@ -2,7 +2,7 @@ - + 24070-Conversation diff --git a/vite/public/favicon.ico b/vite/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..45dc02efe3008a8425c6dbf56d35551c6de79268 GIT binary patch literal 15406 zcmeHOd32Li77rsT3M$TsJ6bjYMW%v?AP9<}P8G!wQO7d_GmbjS{GracFwW2ev{?!T z3vKeHbZ-_Si%u0$)MABV+oVg{ByE!Jr9#01r5kj)^SfV~(n1PJnmXf|e&@XNzP!Bm z?(g1r-~Rg~k|B~yBqK*k5C=(K8!D09Cy_{kf?U5RT`Q5qBP}?%>;F3>lFU&O$t2`K z5tMMHBl7Ces^klGYWaSRAUm!VWbFveT9wR>c%wHJ7-A#F=me<&`8yDZgGP|n>eSNZ z-jsLe(Wt|MQT7BvN^(TRaCf>du~v{)LH3)zl+4;klKnp7gY|9mC#z}9umqZVeH^WPA&QW0)(WB5^;M43Q-rW-8$;KhnJ_$o zZX24|E4=h*G{LXZE>s?PKVK9q^eWf09>uB+>`!w%)sd`>xE{K8+&?CrW{)$`gA)sB z{$wl7n`EK6cNEb5L0Po&#Z>sBY>TJzDS|9ySITBG?a!s1$pw@URY=16LWWc$^7Bn2*5YQ-2;qeE6tTLH34LE!ze=!{1~_ zG4`|~K7-JVa7ZV}vNbAcf>xz?Ax#LqvOn^AmQC0gI#R2Wo`ei>%=Fyba?{ZJt~ft%u&*Yf3A09X~A6ZT%a&$)rxtL-5j@3P8V8( z23?v+FFh7bsY)4PK57Hjr}~RQ7bm|NvX3T2$!XS@*gn_4J=eld+@~T9FreH?y`UJ^ z9}HOc>_k1Z8uvfVhAKe@%#7HZj-{>s;?!e?Q<(aCFjcfH=mL6;>^`h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J9rE*L)0nBCY1<3S6YYk~g&929Y~ literal 0 HcmV?d00001 diff --git a/vite/public/vite.svg b/vite/public/vite.svg deleted file mode 100644 index e7b8dfb..0000000 --- a/vite/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/vite/src/App.jsx b/vite/src/App.jsx index e8894f2..daf8ea9 100644 --- a/vite/src/App.jsx +++ b/vite/src/App.jsx @@ -1,4 +1,4 @@ -import { useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import './App.css' @@ -10,13 +10,15 @@ function App() { const [processing, setProcessing] = useState(false); const [prompt, setPrompt] = useState([]); + const refHistoryContainer= useRef(null); + const refPrompContainer= useRef(null); function onSubmit(event) { event.preventDefault(); const input = event.target.elements.input.value; console.log("Submitted:", input); - setProcessing(true); + // setProcessing(true); fetch(`${BASE_URL}/generate`, { @@ -65,7 +67,7 @@ function App() { // clear input event.target.elements.input.value = ''; - setProcessing(false); + setProcessing(false); }); @@ -73,33 +75,40 @@ function App() { } + useEffect(()=>{ + refHistoryContainer.current.scrollTop = refHistoryContainer.current.scrollHeight; + },[history]); + useEffect(()=>{ + refPrompContainer.current.scrollTop = refPrompContainer.current.scrollHeight; + },[prompt]); return ( -
-
+
+
{prompt?.length==0 ? (
Promp will appear here...
):( prompt?.map((item, index) => ( -
+

{item}

)) )}
-
- {/* History will be rendered here */} - {history?.length==0? ( -
History will appear here...
- ):( - history.map((item, index) => ( -
- {item.content.map((content, idx) => ( -

{content.text}

- ))} -
- )) - )} +
+
+ {history?.length==0? ( +
History will appear here...
+ ):( + history.map((item, index) => ( +
+ {item.content.map((content, idx) => ( +

{content.text}

+ ))} +
+ )) + )} +