MCPcopy Create free account
hub / github.com/GrantCuster/gemini-spatial-example / predictImage

Function predictImage

src/modelUtils.tsx:1–46  ·  view source on GitHub ↗
(
  mimeType: string,
  imageData: string,
  prompt: string,
  activeModel: "flash" | "pro",
)

Source from the content-addressed store, hash-verified

1export const predictImage = async (
2 mimeType: string,
3 imageData: string,
4 prompt: string,
5 activeModel: "flash" | "pro",
6) => {
7 const url =
8 activeModel === "flash"
9 ? "/api/flashGenerateResponseToTextAndImage"
10 : "/api/proGenerateResponseToTextAndImage";
11 try {
12 const response = await fetch(url, {
13 headers: {
14 "Content-Type": "application/json",
15 },
16 method: "POST",
17 body: JSON.stringify({
18 prompt: prompt,
19 imageData: imageData,
20 mimeType: mimeType,
21 }),
22 });
23 const result = await response.json();
24 if (response.ok) {
25 return result;
26 } else {
27 const fetchError = new Error(result.error.message);
28 fetchError.fetchResult = result;
29 throw fetchError;
30 }
31 } catch (error) {
32 console.log(error)
33 if (error.fetchResult) {
34 console.error(
35 `HTTP request failed with status code ${error.fetchResult.error.code}`,
36 error.fetchResult,
37 );
38 return error.fetchResult;
39 }
40 return {
41 error: {
42 message: error.message,
43 },
44 };
45 }
46};

Callers 1

AppFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected