Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

Photo search reads labels again

Youssef6f19c74ad836
diff --git a/src/app/api/help/route.ts b/src/app/api/help/route.ts
index 11182aa..c677d05 100644
--- a/src/app/api/help/route.ts
+++ b/src/app/api/help/route.ts
@@ -36,7 +36,7 @@ export async function POST(req: Request) {
key,
models: image ? MODELS.vision : MODELS.text,
stream: true,
- maxTokens: 500,
+ maxTokens: image ? 1200 : 500,
temperature: 0.4,
messages: [{ role: "system", content: SYSTEM + "\n\nWhere they are:\n" + context }, ...history, user],
});
diff --git a/src/app/api/identify/route.ts b/src/app/api/identify/route.ts
index 86b82e1..7e9b680 100644
--- a/src/app/api/identify/route.ts
+++ b/src/app/api/identify/route.ts
@@ -15,7 +15,8 @@ export async function POST(req: Request) {
const { text } = await chatText({
key,
models: MODELS.vision,
- maxTokens: 200,
+ // vision models think before they answer: a short budget comes back empty
+ maxTokens: 1500,
temperature: 0,
messages: [{ role: "user", content: [{ type: "text", text: PROMPT }, { type: "image_url", image_url: { url: image } }] }],
});
diff --git a/src/lib/together.ts b/src/lib/together.ts
index 285dec5..a6fbbf9 100644
--- a/src/lib/together.ts
+++ b/src/lib/together.ts
@@ -106,10 +106,15 @@ async function chatWith(o: ChatOpts, key: string): Promise<{ res: Response; mode
}
export async function chatText(o: Omit<ChatOpts, "stream">) {
- const { res, model } = await chat(o);
- const j = await res.json();
- const text: string = j?.choices?.[0]?.message?.content ?? "";
- return { text, model };
+ // a model can spend its whole budget thinking and answer nothing: the next one in the list gets a go
+ for (let models = o.models; ; ) {
+ const { res, model } = await chat({ ...o, models });
+ const j = await res.json();
+ const text: string = j?.choices?.[0]?.message?.content ?? "";
+ const rest = models.slice(models.indexOf(model) + 1);
+ if (text.trim() || !rest.length) return { text, model };
+ models = rest;
+ }
}
export function extractJson(text: string): unknown {