Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions convex/_ai/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,33 @@ export type UserKeyModel = {
defaultEffort: ModelEffort;
};

const EFFORTS: readonly ModelEffort[] = ["low", "medium", "high"];

/**
* Models an owner can choose for their own provider key, the default first.
* The provider bills that usage, so it never counts against Gitdog tokens.
* Requests are not streamed and stop after two minutes, so settings that can
* Requests are not streamed and must finish within minutes (two for most
* work, up to four or five in a pull request review), so settings that can
* think for longer, such as Fable 5.1 or xhigh and max effort, are left out.
*/
export const USER_KEY_MODELS: Record<"anthropic" | "openai", UserKeyModel[]> = {
anthropic: [
{
modelId: "claude-opus-5-5",
name: "Claude Opus 5.5",
efforts: ["low", "medium", "high"],
efforts: EFFORTS,
defaultEffort: "medium",
},
{
modelId: "claude-sonnet-5-5",
name: "Claude Sonnet 5.5",
efforts: ["low", "medium", "high"],
efforts: EFFORTS,
defaultEffort: "high",
},
{
modelId: "claude-haiku-5-5",
name: "Claude Haiku 5.5",
efforts: ["low", "medium", "high"],
efforts: EFFORTS,
defaultEffort: "medium",
},
],
Expand All @@ -208,13 +211,13 @@ export const USER_KEY_MODELS: Record<"anthropic" | "openai", UserKeyModel[]> = {
{
modelId: "gpt-6.1-sol",
name: "GPT-6.1 Sol",
efforts: ["low", "medium", "high"],
efforts: EFFORTS,
defaultEffort: "high",
},
{
modelId: "gpt-6.2-sol",
name: "GPT-6.2 Sol",
efforts: ["low", "medium", "high"],
efforts: EFFORTS,
defaultEffort: "high",
},
],
Expand Down
25 changes: 14 additions & 11 deletions convex/_ai/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class ClaudeProvider implements AiProvider {
throw unavailable("Claude API access has ended");
if (!this.authorize && !this.apiKey.trim())
throw unavailable("Anthropic API key is not configured");
const system = systemPrompt(messages);
const { data, requestId } = await request(
"https://api.anthropic.com/v1/messages",
{
Expand All @@ -246,12 +247,12 @@ export class ClaudeProvider implements AiProvider {
fallbacks: "default",
// The system prompt and tools are shared by every turn of a
// conversation, and the caller marks longer prefixes it resends.
...(systemPrompt(messages)
...(system
? {
system: [
{
type: "text",
text: systemPrompt(messages),
text: system,
cache_control: { type: "ephemeral" },
},
],
Expand Down Expand Up @@ -315,21 +316,23 @@ export class ClaudeProvider implements AiProvider {
// answered.
const cacheWrite = counts.cache_creation_input_tokens ?? 0;
const cacheRead = counts.cache_read_input_tokens ?? 0;
if (!tokens(cacheWrite) || !tokens(cacheRead))
if (
!tokens(counts.input_tokens) ||
!tokens(cacheWrite) ||
!tokens(cacheRead)
)
throw new ChatProviderRequestError(
"AI provider returned invalid usage metadata",
"ambiguous",
{ providerRequestId: requestId },
);
const billed = usage(
tokens(counts.input_tokens)
? cacheAdjustedInputTokens(
typeof data.model === "string" ? data.model : this.modelId,
counts.input_tokens,
cacheWrite,
cacheRead,
)
: counts.input_tokens,
cacheAdjustedInputTokens(
typeof data.model === "string" ? data.model : this.modelId,
counts.input_tokens,
cacheWrite,
cacheRead,
),
counts.output_tokens,
requestId,
);
Expand Down
4 changes: 3 additions & 1 deletion convex/pullRequests/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ export function summarizeReviewTrace(events: ReviewTraceEvent[]): {
candidates: number;
discarded: number;
} {
let steps = 0;
let candidates = 0;
let discarded = 0;
const trace: ReviewTraceStep[] = [];
for (const event of events) {
if (event.stage === "proposed") {
steps++;
candidates += event.candidates.length;
trace.push({
step: text(event.step, MAX_PATH_LENGTH),
Expand Down Expand Up @@ -77,7 +79,7 @@ export function summarizeReviewTrace(events: ReviewTraceEvent[]): {
trace.length > MAX_TRACE_STEPS
? [...trace.slice(0, half), ...trace.slice(-half)]
: trace,
steps: events.filter((e) => e.stage === "proposed").length,
steps,
candidates,
discarded,
};
Expand Down
Loading