docs: align AI examples with the actual SDK API and return shapes#89
Conversation
Replace nonexistent ai.completion/ai.vision with ai.chat.completions.create, ai.images.generate, and ai.embeddings.create, and fix the documented return shapes (choices[0].message.content, chunk.choices[0].delta.content, data[0].b64_json, data[0].embedding). Correct the parameter lists to match the @insforge/shared-schemas request schemas, and fix the images.generate JSDoc example. Verified with typecheck and tests. Closes InsForge#76
WalkthroughThis PR aligns README and SDK reference documentation with the actual AI module API. Chat completions, images, and embeddings examples now correctly demonstrate thrown-on-failure OpenAI-like response objects and proper accessor patterns for streaming deltas and image base64 output. ChangesAI API Shape Documentation Updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review — PR #89 docs: align AI examples with the actual SDK API and return shapes
Scope: 3 files changed (README.md +37, SDK-REFERENCE.md +122, src/modules/ai.ts +2). The only runtime-visible change is a one-line JSDoc fix in ai.ts; everything else is documentation.
Summary
The direction of this PR is unambiguously correct. The old examples referenced methods that don't exist (ai.completion, ai.vision), used a { data, error } envelope the AI module never returns, and read non-existent fields (chat.response, images.images[0].url). The replacements are consistent with the OpenAI-like response objects the SDK actually returns and with how for await async iterables work. The single code change (response.images[0].url → response.data[0].b64_json in the JSDoc) is correct.
Findings
Important — worth a follow-up
-
Model name
google/gemini-3-pro-image-previewis unverified (README.mdline 270,SDK-REFERENCE.mdlines 749, 824)The PR replaces
google/gemini-2.5-flash-image-preview(a plausible, real-sounding identifier) withgoogle/gemini-3-pro-image-previewin every image example, but the PR description does not cite evidence that this string is a live model in InsForge's platform. If the identifier isn't registered, every copy-pasted image example throws at runtime. The PR claims cross-checking against integration tests — if an integration test actually calls this model, the concern is resolved; a pointer to that test would be reassuring.
Low — inconsistency / cosmetic
-
Streaming null-delta pattern differs between README and SDK-REFERENCE (
README.mdline 261 vsSDK-REFERENCE.mdlines 717, 818)README writes:
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
SDK-REFERENCE writes:
const delta = chunk.choices[0]?.delta?.content; if (delta) process.stdout.write(delta);
Both are functionally correct (OpenAI final chunks have
nullcontent, andnull ?? ""=""which is harmless;if (null)is also skipped). But they teach two different idioms in the same PR. Theif (delta)form is arguably cleaner and avoids a no-op write. Aligning them removes reader confusion. -
encoding_formatis snake_case; TypeScript callers may need camelCase (SDK-REFERENCE.mdline 789)- `encoding_format` ('float' | 'base64'): Encoding of the returned vectors
OpenAI's own TypeScript SDK exposes this property as
encoding_format(snake_case) on the request type, so if InsForge mirrors that convention this is correct. But if the InsForge TypeScript interface usesencodingFormat(camelCase, the typical TS convention), copy-pasting would produce a TS type error or a silently-ignored unknown key. Worth double-checking against the actual schema type. -
README omits the
data:URI caveat that SDK-REFERENCE includes (README.mdline 275)SDK-REFERENCE helpfully notes
// base64-encoded image (no data: URI prefix), but README just says:const base64Png = image.data[0].b64_json;
A web developer reading only README may paste the value directly into
<img src=...>expecting a data URI and get a broken image silently. A brief parenthetical// raw base64, no data: prefixwould close the gap.
Verdict
No Critical or blocking Important issues — the one Important item (model name) is flagged for follow-up, not blocking. The overall change is a clear net improvement to the developer experience.
Ahead Four.
|
hey @jwfing, both |
|
@AbdulWasih05 yes, I know that gemini-3-pro-image-preview is valid and also agree with you to use the latest model. |
What
Aligns the AI examples in
README.mdandSDK-REFERENCE.md(and oneai.tsJSDoc example) with the AI module's actual API and return shapes.Why
The docs referenced methods that don't exist (
ai.completion,ai.vision) and destructured responses incorrectly ({ data, error },chat.response,images.images[0].url).Copy-pasting these examples fails at runtime or teaches the wrong return shape.
How
README
ai.completion/ai.visionexamples with:ai.chat.completions.createai.images.generateai.embeddings.createSDK-REFERENCE
@insforge/shared-schemasrequest schemas.message,systemPrompt).ai.ts
images.generateJSDoc example to usedata[0].b64_json.images[0].urlreference.How to Test
npm run typecheck npm testExpected results:
npm run typecheck-- passesnpm test-- 131/131 tests pass@insforge/shared-schemas@1.1.53integration-tests/ai.test.tsRelated
Closes #76
Summary by cubic
Aligns AI examples in README and SDK reference to the actual SDK API and return shapes so copy‑paste works and matches OpenAI‑like responses. Also fixes the
images.generateJSDoc example and updates params to match@insforge/shared-schemas. Closes #76.ai.completion/ai.visionwithai.chat.completions.create,ai.images.generate,ai.embeddings.create.choices[0].message.content, streamingchoices[0].delta.content, imagesdata[0].b64_json, embeddingsdata[0].embedding; methods throw on failure.@insforge/shared-schemas(removed nonexistent chat/image params; added embeddings and documented supported options).ai.tsJSDoc to useresponse.data[0].b64_json.Written for commit 06854de. Summary will update on new commits.
Note
Align AI SDK docs and JSDoc examples with OpenAI-like return shapes
{ data, error }envelope pattern and replace it with direct return values that throw on failure, matching the actual SDK API.insforge.ai.chat.completions.createand read fromchoices[0].message.content(non-streaming) andchoices[0]?.delta?.content(streaming).image.data[0].b64_jsonand adds an image-to-image example; adds a new embeddings section usingai.embeddings.createreturning vectors viaembeddings.data[i].embedding.Images.generateJSDoc in src/modules/ai.ts to referenceresponse.data[0].b64_jsoninstead ofresponse.images[0].url.Macroscope summarized 06854de.
Summary by CodeRabbit