Skip to content

Commit 71a7ad1

Browse files
committed
core: fix model selection in title generation to use user's model instead of assistant's
1 parent 20399bb commit 71a7ad1

1 file changed

Lines changed: 4 additions & 49 deletions

File tree

‎packages/opencode/src/session/summary.ts‎

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,17 @@ export namespace SessionSummary {
7474
}
7575
await Session.updateMessage(userMsg)
7676

77-
const assistantMsg = messages.find((m) => m.info.role === "assistant")!.info as MessageV2.Assistant
78-
const small =
79-
(await Provider.getSmallModel(assistantMsg.providerID)) ??
80-
(await Provider.getModel(assistantMsg.providerID, assistantMsg.modelID))
81-
8277
const textPart = msgWithParts.parts.find((p) => p.type === "text" && !p.synthetic) as MessageV2.TextPart
8378
if (textPart && !userMsg.summary?.title) {
8479
const agent = await Agent.get("title")
8580
const stream = await LLM.stream({
8681
agent,
8782
user: userMsg,
8883
tools: {},
89-
model: agent.model ? await Provider.getModel(agent.model.providerID, agent.model.modelID) : small,
84+
model: agent.model
85+
? await Provider.getModel(agent.model.providerID, agent.model.modelID)
86+
: ((await Provider.getSmallModel(userMsg.model.providerID)) ??
87+
(await Provider.getModel(userMsg.model.providerID, userMsg.model.modelID))),
9088
small: true,
9189
messages: [
9290
{
@@ -109,49 +107,6 @@ export namespace SessionSummary {
109107
userMsg.summary.title = result
110108
await Session.updateMessage(userMsg)
111109
}
112-
113-
if (
114-
messages.some(
115-
(m) =>
116-
m.info.role === "assistant" && m.parts.some((p) => p.type === "step-finish" && p.reason !== "tool-calls"),
117-
)
118-
) {
119-
if (diffs.length > 0) {
120-
for (const msg of messages) {
121-
for (const part of msg.parts) {
122-
if (part.type === "tool" && part.state.status === "completed") {
123-
part.state.output = "[TOOL OUTPUT PRUNED]"
124-
}
125-
}
126-
}
127-
const summaryAgent = await Agent.get("summary")
128-
const stream = await LLM.stream({
129-
agent: summaryAgent,
130-
user: userMsg,
131-
tools: {},
132-
model: summaryAgent.model
133-
? await Provider.getModel(summaryAgent.model.providerID, summaryAgent.model.modelID)
134-
: small,
135-
small: true,
136-
messages: [
137-
...MessageV2.toModelMessage(messages),
138-
{
139-
role: "user" as const,
140-
content: `Summarize the above conversation according to your system prompts.`,
141-
},
142-
],
143-
abort: new AbortController().signal,
144-
sessionID: userMsg.sessionID,
145-
system: [],
146-
retries: 3,
147-
})
148-
const result = await stream.text
149-
if (result) {
150-
userMsg.summary.body = result
151-
}
152-
}
153-
await Session.updateMessage(userMsg)
154-
}
155110
}
156111

157112
export const diff = fn(

0 commit comments

Comments
 (0)