Dax Raad 9 месяцев назад
Родитель
Сommit
e524209352
3 измененных файлов с 712 добавлено и 22 удалено
  1. 677 19
      app/bun.lock
  2. 7 0
      js/src/session/prompt/title.txt
  3. 28 3
      js/src/session/session.ts

Разница между файлами не показана из-за своего большого размера
+ 677 - 19
app/bun.lock


+ 7 - 0
js/src/session/prompt/title.txt

@@ -0,0 +1,7 @@
+you will generate a short title based on the first message a user begins a conversation with
+- ensure it is not more than 50 characters long
+- the title should be a summary of the user's message
+- it should be one line long
+- do not use quotes or colons
+- the entire text you return will be used as the title
+- never return anything that is more than one sentence (one line) long

+ 28 - 3
js/src/session/session.ts

@@ -6,6 +6,7 @@ import { Storage } from "../storage/storage";
 import { Log } from "../util/log";
 import { Log } from "../util/log";
 import {
 import {
   convertToModelMessages,
   convertToModelMessages,
+  generateText,
   stepCountIs,
   stepCountIs,
   streamText,
   streamText,
   type TextUIPart,
   type TextUIPart,
@@ -17,7 +18,9 @@ import {
 import { z } from "zod";
 import { z } from "zod";
 import * as tools from "../tool";
 import * as tools from "../tool";
 
 
-import ANTHROPIC_PROMPT from "./prompt/anthropic.txt";
+import PROMPT_ANTHROPIC from "./prompt/anthropic.txt";
+import PROMPT_TITLE from "./prompt/title.txt";
+
 import type { Tool } from "../tool/tool";
 import type { Tool } from "../tool/tool";
 import { Share } from "../share/share";
 import { Share } from "../share/share";
 
 
@@ -120,6 +123,7 @@ export namespace Session {
     sessionID: string,
     sessionID: string,
     ...parts: UIMessagePart<UIDataTypes>[]
     ...parts: UIMessagePart<UIDataTypes>[]
   ) {
   ) {
+    const model = await LLM.findModel("claude-sonnet-4-20250514");
     const session = await get(sessionID);
     const session = await get(sessionID);
     const l = log.clone().tag("session", sessionID);
     const l = log.clone().tag("session", sessionID);
     l.info("chatting");
     l.info("chatting");
@@ -138,7 +142,7 @@ export namespace Session {
         parts: [
         parts: [
           {
           {
             type: "text",
             type: "text",
-            text: ANTHROPIC_PROMPT,
+            text: PROMPT_ANTHROPIC,
           },
           },
         ],
         ],
         metadata: {
         metadata: {
@@ -151,6 +155,28 @@ export namespace Session {
       };
       };
       msgs.push(system);
       msgs.push(system);
       state().messages.set(sessionID, msgs);
       state().messages.set(sessionID, msgs);
+      generateText({
+        messages: convertToModelMessages([
+          {
+            role: "system",
+            parts: [
+              {
+                type: "text",
+                text: PROMPT_TITLE,
+              },
+            ],
+          },
+          {
+            role: "user",
+            parts,
+          },
+        ]),
+        model,
+      }).then(async (result) => {
+        const session = await Session.get(sessionID);
+        session.title = result.text;
+        return Session.update(session);
+      });
       await write(system);
       await write(system);
     }
     }
     const msg: Message = {
     const msg: Message = {
@@ -168,7 +194,6 @@ export namespace Session {
     msgs.push(msg);
     msgs.push(msg);
     await write(msg);
     await write(msg);
 
 
-    const model = await LLM.findModel("claude-sonnet-4-20250514");
     const result = streamText({
     const result = streamText({
       stopWhen: stepCountIs(1000),
       stopWhen: stepCountIs(1000),
       messages: convertToModelMessages(msgs),
       messages: convertToModelMessages(msgs),

Некоторые файлы не были показаны из-за большого количества измененных файлов