MCPcopy Create free account
hub / github.com/CopilotKit/aimock / handleSpeech

Function handleSpeech

src/speech.ts:32–276  ·  view source on GitHub ↗
(
  req: http.IncomingMessage,
  res: http.ServerResponse,
  raw: string,
  fixtures: Fixture[],
  journal: Journal,
  defaults: HandlerDefaults,
  setCorsHeaders: (res: http.ServerResponse) => void,
)

Source from the content-addressed store, hash-verified

30}
31
32export async function handleSpeech(
33 req: http.IncomingMessage,
34 res: http.ServerResponse,
35 raw: string,
36 fixtures: Fixture[],
37 journal: Journal,
38 defaults: HandlerDefaults,
39 setCorsHeaders: (res: http.ServerResponse) => void,
40): Promise<void> {
41 setCorsHeaders(res);
42 const path = req.url ?? "/v1/audio/speech";
43 const method = req.method ?? "POST";
44
45 let speechReq: SpeechRequest;
46 try {
47 speechReq = JSON.parse(raw) as SpeechRequest;
48 } catch (parseErr) {
49 const detail = parseErr instanceof Error ? parseErr.message : "unknown";
50 journal.add({
51 method,
52 path,
53 headers: flattenHeaders(req.headers),
54 body: null,
55 response: { status: 400, fixture: null },
56 });
57 writeErrorResponse(
58 res,
59 400,
60 JSON.stringify({
61 error: {
62 message: `Malformed JSON: ${detail}`,
63 type: "invalid_request_error",
64 code: "invalid_json",
65 },
66 }),
67 );
68 return;
69 }
70
71 if (!speechReq.input) {
72 journal.add({
73 method,
74 path,
75 headers: flattenHeaders(req.headers),
76 body: null,
77 response: { status: 400, fixture: null },
78 });
79 writeErrorResponse(
80 res,
81 400,
82 JSON.stringify({
83 error: { message: "Missing required parameter: 'input'", type: "invalid_request_error" },
84 }),
85 );
86 return;
87 }
88
89 const syntheticReq: ChatCompletionRequest = {

Callers 1

handleHttpRequestFunction · 0.85

Calls 15

setCorsHeadersFunction · 0.85
flattenHeadersFunction · 0.85
writeErrorResponseFunction · 0.85
getContextFunction · 0.85
getTestIdFunction · 0.85
matchFixtureDiagnosticFunction · 0.85
applyChaosFunction · 0.85
resolveStrictModeFunction · 0.85
strictNoMatchMessageFunction · 0.85
strictNoMatchLogLineFunction · 0.85
strictOverrideFieldFunction · 0.85
proxyAndRecordFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…