Anthropic Helicone String -> Object#5102
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Claude finished @colegottdank's task —— View job Code Review CompleteReviewing PR: Anthropic Helicone String -> Object Todo List:
Code Review SummaryScore: 8/10 - Good implementation with correct API format handling AnalysisThe change adds proper handling for Anthropic's system message format in the HeliconeProvider when What Changed// Before
return JSON.stringify({
...context.parsedBody,
model: endpoint.providerModelId,
});
// After
const body = { ...context.parsedBody };
// Ensure system message is in object format if it's a string
if (typeof body.system === "string") {
body.system = [{ type: "text", text: body.system }];
}
return JSON.stringify({
...body,
model: endpoint.providerModelId,
});Positive Aspects
Minor Improvements Suggested
if (typeof body.system === "string") {
body.system = [{ type: "text", text: body.system }] as const;
}
// Anthropic API requires system messages as object array format
// when using structured content blocks
if (typeof body.system === "string") {
body.system = [{ type: "text", text: body.system }];
}Technical Correctness✅ API Compliance: Correctly implements Anthropic's Messages API format No Critical Issues Found
|
There was a problem hiding this comment.
Greptile Overview
Summary
Converts string-formatted Anthropic system messages to object format when using NO_MAPPING body mapping in the HeliconeProvider.
- The change ensures
systemmessages are always in array format[{type: "text", text: string}]instead of plain strings - Only applies when
bodyMapping === "NO_MAPPING"for Anthropic models - The Anthropic API accepts both string and object array formats for the
systemfield according to the types inpackages/llm-mapper/transform/types/anthropic.ts:21
Confidence Score: 4/5
- This PR is safe to merge with low risk
- The change standardizes the system message format to always use the object array format. While both formats are valid according to Anthropic's types, this conversion is safe and maintains API compatibility. The implementation is straightforward with no side effects.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/cost/models/providers/helicone.ts | 4/5 | Converts Anthropic system message from string to object format when using NO_MAPPING body mapping |
Sequence Diagram
sequenceDiagram
participant Client
participant HeliconeProvider
participant AnthropicAPI
Client->>HeliconeProvider: buildRequestBody(endpoint, context)
alt bodyMapping === "NO_MAPPING"
HeliconeProvider->>HeliconeProvider: Copy parsedBody
alt system is string
HeliconeProvider->>HeliconeProvider: Convert system to [{type:"text", text:system}]
end
HeliconeProvider->>HeliconeProvider: Set model to providerModelId
HeliconeProvider->>AnthropicAPI: Send request with object-formatted system
else bodyMapping !== "NO_MAPPING"
HeliconeProvider->>HeliconeProvider: Call toAnthropic(parsedBody)
HeliconeProvider->>AnthropicAPI: Send transformed request
end
AnthropicAPI-->>Client: Response
1 file reviewed, no comments
No description provided.