Conversation
|
Greptile OverviewGreptile SummaryThis PR adds Vercel AI Gateway support to enable routing model calls through the gateway, along with model-specific fixes for Kimi and DeepSeek. Key changes:
Concerns:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant LLMProvider
participant AISdkClient
participant AIGateway
participant Model
User->>LLMProvider: getClient(modelName)
alt modelName contains "/"
LLMProvider->>LLMProvider: Parse provider/model (substring)
LLMProvider->>LLMProvider: Check if provider is "gateway"
alt provider is "gateway"
LLMProvider->>AIGateway: createGateway(clientOptions)
AIGateway-->>LLMProvider: gateway provider instance
end
LLMProvider->>AISdkClient: new AISdkClient(model)
AISdkClient-->>LLMProvider: client instance
end
User->>AISdkClient: createChatCompletion(options)
alt model is Kimi
AISdkClient->>AISdkClient: Force temperature=1
end
alt response_model exists AND (DeepSeek OR Kimi)
AISdkClient->>AISdkClient: Append JSON schema instruction
end
AISdkClient->>Model: generateObject/generateText()
Model-->>AISdkClient: response
AISdkClient-->>User: formatted response
|
|
@Kylejeong2 would users have to define |
Yeah that is the current flow, but I can update it to make more ergonomic |
There was a problem hiding this comment.
1 issue found across 6 files
Confidence score: 5/5
- Only minor wording clarity issue in
packages/evals/lib/AISdkClientWrapped.ts; it doesn’t affect runtime behavior and is low severity. - Score reflects low risk since the concern is documentation/terminology rather than functional change.
- Pay close attention to
packages/evals/lib/AISdkClientWrapped.ts- update the prompt wording to say JSON schema format for clarity.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/evals/lib/AISdkClientWrapped.ts">
<violation number="1" location="packages/evals/lib/AISdkClientWrapped.ts:153">
P2: Misleading terminology: the prompt says 'zod schema format' but `toJsonSchema()` produces a JSON Schema, not a Zod schema. Consider changing the wording to 'JSON schema format' for clarity.</violation>
</file>
Architecture diagram
sequenceDiagram
participant App as App / Eval Engine
participant LLMP as LLMProvider.ts
participant Client as AISdkClient
participant AISDK as Vercel AI SDK
participant GW as NEW: AI Gateway
participant Provider as Model Provider (Kimi/DeepSeek)
Note over App,Provider: Runtime Request Flow with AI Gateway & Model Optimization
App->>LLMP: getAISDKLanguageModel(provider, model)
alt NEW: Provider is "gateway"
LLMP->>AISDK: createGateway(config)
else Standard Provider
LLMP->>AISDK: createProvider(config)
end
LLMP-->>App: languageModel instance
App->>Client: createChatCompletion(options)
rect rgb(23, 37, 84)
Note right of Client: CHANGED: Model-specific Logic
opt modelId contains "kimi"
Client->>Client: NEW: Force temperature = 1
end
opt modelId contains "deepseek" OR "kimi"
Client->>Client: NEW: Inject Zod Schema & JSON instructions into prompt
end
end
alt generateObject (Structured Data)
Client->>AISDK: generateObject(model, schema, messages)
AISDK->>GW: Request with Gateway Headers
GW->>Provider: Route to Inference API
Provider-->>GW: JSON Response
GW-->>AISDK: Relay Response
AISDK-->>Client: Typed Object
else generateText
Client->>AISDK: generateText(model, messages)
AISDK->>GW: Request with Gateway Headers
GW->>Provider: Route to Inference API
Provider-->>GW: Text Response
GW-->>AISDK: Relay Response
AISDK-->>Client: Text
end
Client-->>App: LLMResponse
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| formattedMessages.push({ | ||
| role: "user", | ||
| content: `Respond in this zod schema format:\n${parsedSchema}\n |
There was a problem hiding this comment.
P2: Misleading terminology: the prompt says 'zod schema format' but toJsonSchema() produces a JSON Schema, not a Zod schema. Consider changing the wording to 'JSON schema format' for clarity.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/evals/lib/AISdkClientWrapped.ts, line 153:
<comment>Misleading terminology: the prompt says 'zod schema format' but `toJsonSchema()` produces a JSON Schema, not a Zod schema. Consider changing the wording to 'JSON schema format' for clarity.</comment>
<file context>
@@ -136,13 +137,30 @@ export class AISdkClientWrapped extends LLMClient {
+
+ formattedMessages.push({
+ role: "user",
+ content: `Respond in this zod schema format:\n${parsedSchema}\n
+You must respond in JSON format. respond WITH JSON. Do not include any other text, formatting or markdown in your output. Do not include \`\`\` or \`\`\`json in your response. Only the JSON object itself.`,
+ });
</file context>
| content: `Respond in this zod schema format:\n${parsedSchema}\n | |
| content: `Respond in this JSON schema format:\n${parsedSchema}\n |
That's fine let's just cover it in the docs! |
Yeah I can add into docs in separate PR, can you approve? |
| "@ai-sdk/gateway": "^3.0.25", | ||
| "@ai-sdk/google": "^2.0.23", |
There was a problem hiding this comment.
is this the right version? usually v3 ai sdk packages = only works with v6
There was a problem hiding this comment.
im thinking about removing, since the actual package that we're pulling from is "ai" not the /gateway i added this per cubic's recommendation
There was a problem hiding this comment.
docs for reference: https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway
| "@ai-sdk/cerebras": "^1.0.25", | ||
| "@ai-sdk/deepseek": "^1.0.23", | ||
| "@ai-sdk/gateway": "^3.0.25", |
There was a problem hiding this comment.
believe we can also just directly import gateway from ai without needing to add a new dependency
42a1c50 to
e5cf56d
Compare
# why
Users need to know how to use the AI gateway provider in stagehand
# what changed
added docs to the models section to show users how to use the ai gateway
# test plan
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Added first-class support for the Vercel AI Gateway and updated docs so
you can use models across providers with a single key and simple model
strings. Also improved structured outputs for Kimi/DeepSeek and fixed
eval parsing for provider/model names.
- **New Features**
- Added gateway provider to LLMProvider (use model:
"gateway/{provider}/{model}").
- Updated docs with AI Gateway usage, examples, and env var guidance.
- For DeepSeek/Kimi, added schema prompt to ensure JSON structured
outputs; Kimi uses temperature=1.
- Consistent temperature handling in object/text generation.
- Improved evals to parse model strings using the first slash.
- **Migration**
- Set AI_GATEWAY_API_KEY in your environment.
- Use model names prefixed with gateway/{provider}/{model}; optional
baseURL supported.
<sup>Written for commit 560366a.
Summary will update on new commits. <a
href="https://cubic.dev/pr/browserbase/stagehand/pull/1670">Review in
cubic</a></sup>
<!-- End of auto-generated description by cubic. -->
Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com>
Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com>
why
New open source models are released, and don't necessarily have a great inference provider at all times. Seeing as we're already using the AI-SDK, it makes sense to add support for the AI Gateway.
what changed
Added Vercel AI Gateway as a provider to the llm providers list.
test plan
Testing with Evals
Summary by cubic
Adds Vercel AI Gateway as a provider to route model calls across vendors with a single API key; docs now cover gateway/{provider}/{model} usage, AI_GATEWAY_API_KEY setup, examples for Anthropic/Google, and optional baseURL config.
Also enforces JSON outputs for Kimi and DeepSeek, sets Kimi temperature=1, and fixes eval parsing by using the first slash in provider/model strings.
Written for commit 514142f. Summary will update on new commits. Review in cubic