MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / runInference

Function runInference

app/src/server/modal-rpc/clients.ts:54–99  ·  view source on GitHub ↗
(args: ModalInput)

Source from the content-addressed store, hash-verified

52}.modal.run`;
53
54export const runInference = async (args: ModalInput) => {
55 const resp = await fetch(inferenceBase, {
56 method: "POST",
57 body: JSON.stringify(args),
58 headers: {
59 "Content-Type": "application/json",
60 },
61 });
62
63 const respText = await resp.text();
64 if (!resp.ok) {
65 captureException("Failed to run inference.", {
66 extra: {
67 response: respText,
68 ...pick(args, ["model", "n", "max_tokens", "temperature"]),
69 },
70 });
71 throw new Error("Failed to run inference");
72 }
73
74 let json;
75 try {
76 json = JSON.parse(respText);
77 } catch (e) {
78 // captureException
79 captureException("Failed to parse response from modal.", {
80 extra: {
81 response: respText,
82 ...pick(args, ["model", "n", "max_tokens", "temperature"]),
83 },
84 });
85 throw new Error("Failed to parse LLM response");
86 }
87 const output = outputSchema.safeParse(json);
88 if (output.success) {
89 return output.data;
90 } else {
91 captureException("Failed to validate output from modal.", {
92 extra: {
93 response: respText,
94 ...pick(args, ["model", "n", "max_tokens", "temperature"]),
95 },
96 });
97 throw new Error("Failed to validate LLM response");
98 }
99};

Callers 1

getModalCompletionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected