summaryrefslogtreecommitdiffhomepage
path: root/js/example
diff options
context:
space:
mode:
Diffstat (limited to 'js/example')
-rw-r--r--js/example/cli.ts27
-rw-r--r--js/example/ink.tsx (renamed from js/example/client.tsx)18
2 files changed, 39 insertions, 6 deletions
diff --git a/js/example/cli.ts b/js/example/cli.ts
new file mode 100644
index 000000000..bb7522cbb
--- /dev/null
+++ b/js/example/cli.ts
@@ -0,0 +1,27 @@
+import { hc } from "hono/client";
+import type { Server } from "../src/server/server";
+
+const message = process.argv.slice(2).join(" ");
+console.log(message);
+
+const client = hc<Server.App>(`http://localhost:16713`);
+const session = await client.session_create.$post().then((res) => res.json());
+const result = await client.session_chat
+ .$post({
+ json: {
+ sessionID: session.id,
+ parts: [
+ {
+ type: "text",
+ text: message,
+ },
+ ],
+ },
+ })
+ .then((res) => res.json());
+
+for (const part of result.parts) {
+ if (part.type === "text") {
+ console.log(part.text);
+ }
+}
diff --git a/js/example/client.tsx b/js/example/ink.tsx
index 65f0ebe15..5eaab4d3b 100644
--- a/js/example/client.tsx
+++ b/js/example/ink.tsx
@@ -78,13 +78,19 @@ function App() {
<>
<Text>{session.title}</Text>
{
- Object.values(state.session.message[session.id]).map(message => {
- return Object.values(message.parts).map((part, index) => {
- if (part.type === "text") {
- return <Text key={`${message.id}-${index}`}>{message.role}: {part.text}</Text>
- }
+ Object.values(state.session.message[session.id])
+ .filter(message => message.role !== "system")
+ .map(message => {
+ return Object.values(message.parts)
+ .map((part, index) => {
+ if (part.type === "text") {
+ return <Text key={`${message.id}-${index}`}>{message.role}: {part.text}</Text>
+ }
+ if (part.type === "tool-invocation") {
+ return <Text key={`${message.id}-${index}`}>{message.role}: {part.toolInvocation.toolName} {JSON.stringify(part.toolInvocation.args)}</Text>
+ }
+ })
})
- })
}
<Box gap={1} >
<Text>Input:</Text>