Wire mic through Whisper-compatible transcriptions on LLM_BASE_URL. Photos upload to MinIO and reach the vision model as base64 image_url parts.
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import type { ChatCompletionRequest, ChatCompletionResult, LlmClient } from "./types";
|
|
import { textFromMessageContent } from "./content";
|
|
|
|
function hadToolResults(messages: ChatCompletionRequest["messages"]): boolean {
|
|
return messages.some((message) => message.role === "tool");
|
|
}
|
|
|
|
export function createMockLlmClient(): LlmClient {
|
|
return {
|
|
async chatCompletion(request: ChatCompletionRequest): Promise<ChatCompletionResult> {
|
|
const userText = textFromMessageContent(
|
|
[...request.messages].reverse().find((message) => message.role === "user")?.content ?? "",
|
|
).toLowerCase();
|
|
|
|
if (hadToolResults(request.messages)) {
|
|
return {
|
|
message: {
|
|
role: "assistant",
|
|
content: "Done — I updated your household data using the API.",
|
|
},
|
|
finishReason: "stop",
|
|
};
|
|
}
|
|
|
|
if (userText.includes("milk") && request.tools?.length) {
|
|
return {
|
|
message: {
|
|
role: "assistant",
|
|
content: null,
|
|
tool_calls: [
|
|
{
|
|
id: "mock_call_add_item",
|
|
type: "function",
|
|
function: {
|
|
name: "add_list_item",
|
|
arguments: JSON.stringify({
|
|
listType: "shopping",
|
|
text: "milk",
|
|
}),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
finishReason: "tool_calls",
|
|
};
|
|
}
|
|
|
|
if (userText.includes("calendar") && request.tools?.length) {
|
|
const now = new Date();
|
|
const from = new Date(now);
|
|
from.setDate(from.getDate() - 1);
|
|
const to = new Date(now);
|
|
to.setDate(to.getDate() + 7);
|
|
|
|
return {
|
|
message: {
|
|
role: "assistant",
|
|
content: null,
|
|
tool_calls: [
|
|
{
|
|
id: "mock_call_list_events",
|
|
type: "function",
|
|
function: {
|
|
name: "list_events",
|
|
arguments: JSON.stringify({
|
|
from: from.toISOString(),
|
|
to: to.toISOString(),
|
|
}),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
finishReason: "tool_calls",
|
|
};
|
|
}
|
|
|
|
return {
|
|
message: {
|
|
role: "assistant",
|
|
content:
|
|
"I'm the famapp assistant (mock provider). Ask me to add items or check the calendar.",
|
|
},
|
|
finishReason: "stop",
|
|
};
|
|
},
|
|
};
|
|
}
|