sync
This commit is contained in:
parent
7618267bdb
commit
f4e6e29372
2 changed files with 19 additions and 20 deletions
|
|
@ -46,9 +46,13 @@ export namespace LLM {
|
||||||
const [language, cfg] = await Promise.all([Provider.getLanguage(input.model), Config.get()])
|
const [language, cfg] = await Promise.all([Provider.getLanguage(input.model), Config.get()])
|
||||||
|
|
||||||
const [first, ...rest] = [
|
const [first, ...rest] = [
|
||||||
|
// header prompt for providers with auth checks
|
||||||
...SystemPrompt.header(input.model.providerID),
|
...SystemPrompt.header(input.model.providerID),
|
||||||
|
// use agent prompt otherwise provider prompt
|
||||||
...(input.agent.prompt ? [input.agent.prompt] : SystemPrompt.provider(input.model)),
|
...(input.agent.prompt ? [input.agent.prompt] : SystemPrompt.provider(input.model)),
|
||||||
|
// any custom prompt passed into this call
|
||||||
...input.system,
|
...input.system,
|
||||||
|
// any custom prompt from last user message
|
||||||
...(input.user.system ? [input.user.system] : []),
|
...(input.user.system ? [input.user.system] : []),
|
||||||
]
|
]
|
||||||
const system = [first, rest.join("\n")].filter((x) => x)
|
const system = [first, rest.join("\n")].filter((x) => x)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ import { Instance } from "@/project/instance"
|
||||||
import { Storage } from "@/storage/storage"
|
import { Storage } from "@/storage/storage"
|
||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { mergeDeep, pipe } from "remeda"
|
import { mergeDeep, pipe } from "remeda"
|
||||||
|
import { LLM } from "./llm"
|
||||||
|
import { Agent } from "@/agent/agent"
|
||||||
|
|
||||||
export namespace SessionSummary {
|
export namespace SessionSummary {
|
||||||
const log = Log.create({ service: "session.summary" })
|
const log = Log.create({ service: "session.summary" })
|
||||||
|
|
@ -89,16 +91,12 @@ export namespace SessionSummary {
|
||||||
|
|
||||||
const textPart = msgWithParts.parts.find((p) => p.type === "text" && !p.synthetic) as MessageV2.TextPart
|
const textPart = msgWithParts.parts.find((p) => p.type === "text" && !p.synthetic) as MessageV2.TextPart
|
||||||
if (textPart && !userMsg.summary?.title) {
|
if (textPart && !userMsg.summary?.title) {
|
||||||
const result = await generateText({
|
const stream = await LLM.stream({
|
||||||
maxOutputTokens: small.capabilities.reasoning ? 1500 : 20,
|
agent: await Agent.get("summary"),
|
||||||
providerOptions: ProviderTransform.providerOptions(small, options),
|
user: userMsg,
|
||||||
|
tools: {},
|
||||||
|
model: small,
|
||||||
messages: [
|
messages: [
|
||||||
...SystemPrompt.title(small.providerID).map(
|
|
||||||
(x): ModelMessage => ({
|
|
||||||
role: "system",
|
|
||||||
content: x,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
role: "user" as const,
|
role: "user" as const,
|
||||||
content: `
|
content: `
|
||||||
|
|
@ -109,18 +107,15 @@ export namespace SessionSummary {
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
headers: small.headers,
|
small: true,
|
||||||
model: language,
|
abort: new AbortController().signal,
|
||||||
experimental_telemetry: {
|
sessionID: userMsg.sessionID,
|
||||||
isEnabled: cfg.experimental?.openTelemetry,
|
system: [],
|
||||||
metadata: {
|
retries: 3,
|
||||||
userId: cfg.username ?? "unknown",
|
|
||||||
sessionId: assistantMsg.sessionID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
log.info("title", { title: result.text })
|
const result = await stream.text
|
||||||
userMsg.summary.title = result.text
|
log.info("title", { title: result })
|
||||||
|
userMsg.summary.title = result
|
||||||
await Session.updateMessage(userMsg)
|
await Session.updateMessage(userMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue