chat: remember last model
This commit is contained in:
@@ -10,11 +10,12 @@ function asProviderEnum(p: Provider) {
|
||||
|
||||
export async function runMultiplex(req: MultiplexRequest): Promise<MultiplexResponse> {
|
||||
const t0 = performance.now();
|
||||
const chatId = req.chatId ?? (await prisma.chat.create({ data: {}, select: { id: true } })).id;
|
||||
|
||||
// Persist call record early so we can attach errors.
|
||||
const call = await prisma.llmCall.create({
|
||||
data: {
|
||||
chatId: req.chatId ?? (await prisma.chat.create({ data: {} })).id,
|
||||
chatId,
|
||||
provider: asProviderEnum(req.provider) as any,
|
||||
model: req.model,
|
||||
request: req as any,
|
||||
@@ -22,6 +23,23 @@ export async function runMultiplex(req: MultiplexRequest): Promise<MultiplexResp
|
||||
select: { id: true, chatId: true },
|
||||
});
|
||||
|
||||
await prisma.$transaction([
|
||||
prisma.chat.update({
|
||||
where: { id: chatId },
|
||||
data: {
|
||||
lastUsedProvider: asProviderEnum(req.provider) as any,
|
||||
lastUsedModel: req.model,
|
||||
},
|
||||
}),
|
||||
prisma.chat.updateMany({
|
||||
where: { id: chatId, initiatedProvider: null },
|
||||
data: {
|
||||
initiatedProvider: asProviderEnum(req.provider) as any,
|
||||
initiatedModel: req.model,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
try {
|
||||
let outText = "";
|
||||
let usage: MultiplexResponse["usage"] | undefined;
|
||||
|
||||
@@ -29,6 +29,23 @@ export async function* runMultiplexStream(req: MultiplexRequest): AsyncGenerator
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
await prisma.$transaction([
|
||||
prisma.chat.update({
|
||||
where: { id: chatId },
|
||||
data: {
|
||||
lastUsedProvider: req.provider as any,
|
||||
lastUsedModel: req.model,
|
||||
},
|
||||
}),
|
||||
prisma.chat.updateMany({
|
||||
where: { id: chatId, initiatedProvider: null },
|
||||
data: {
|
||||
initiatedProvider: req.provider as any,
|
||||
initiatedModel: req.model,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
yield { type: "meta", chatId, callId: call.id, provider: req.provider, model: req.model };
|
||||
|
||||
let text = "";
|
||||
|
||||
Reference in New Issue
Block a user