Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce server stats endpoint and caching #238

Merged
merged 3 commits into from
Dec 7, 2024
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
98 changes: 57 additions & 41 deletions app/client/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const VersionedTextsSchema = z.object({
z.object({
version: z.string(),
content: z.string(),
}),
})
),
});

Expand Down Expand Up @@ -88,7 +88,7 @@ export const learningSchema = z.object({
summary: z
.string()
.describe(
"The new information that was learned. Be generic, do not refer to the entities.",
"The new information that was learned. Be generic, do not refer to the entities."
),
entities: z
.array(
Expand All @@ -97,7 +97,7 @@ export const learningSchema = z.object({
.string()
.describe("The name of the entity this learning relates to."),
type: z.enum(["tool"]),
}),
})
)
.describe("The entities this learning relates to."),
relevance: z.object({
Expand All @@ -121,7 +121,7 @@ export const agentDataSchema = z
toolName: z.string(),
reasoning: z.string().optional(),
input: z.object({}).passthrough(),
}),
})
)
.optional(),
})
Expand Down Expand Up @@ -162,7 +162,7 @@ export const definition = {
description: z.string().optional(),
schema: z.string().optional(),
config: FunctionConfigSchema.optional(),
}),
})
)
.optional(),
}),
Expand Down Expand Up @@ -231,7 +231,7 @@ export const definition = {
.and(
z.object({
data: z.string(),
}),
})
),
},
getContract: {
Expand All @@ -256,7 +256,7 @@ export const definition = {
name: z.string(),
createdAt: z.date(),
description: z.string().nullable(),
}),
})
),
401: z.undefined(),
},
Expand Down Expand Up @@ -332,13 +332,13 @@ export const definition = {
name: z.string().optional(),
description: z.string().optional(),
additionalContext: VersionedTextsSchema.optional().describe(
"Additional cluster context which is included in all runs",
"Additional cluster context which is included in all runs"
),
debug: z
.boolean()
.optional()
.describe(
"Enable additional logging (Including prompts and results) for use by Inferable support",
"Enable additional logging (Including prompts and results) for use by Inferable support"
),
enableRunConfigs: z.boolean().optional(),
enableKnowledgebase: z.boolean().optional(),
Expand Down Expand Up @@ -389,7 +389,7 @@ export const definition = {
workflowId: z.string().nullable(),
meta: z.any().nullable(),
id: z.string(),
}),
})
),
401: z.undefined(),
404: z.undefined(),
Expand Down Expand Up @@ -418,13 +418,13 @@ export const definition = {
totalInputTokens: z.number(),
totalOutputTokens: z.number(),
totalModelInvocations: z.number(),
}),
})
),
agentRuns: z.array(
z.object({
date: z.string(),
totalAgentRuns: z.number(),
}),
})
),
}),
},
Expand Down Expand Up @@ -481,23 +481,23 @@ export const definition = {
resultSchema: anyObject
.optional()
.describe(
"A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema",
"A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema"
),
attachedFunctions: z
.array(functionReference)
.optional()
.describe(
"An array of functions to make available to the run. By default all functions in the cluster will be available",
"An array of functions to make available to the run. By default all functions in the cluster will be available"
),
onStatusChange: z
.object({
function: functionReference.describe(
"A function to call when the run status changes",
"A function to call when the run status changes"
),
})
.optional()
.describe(
"Mechanism for receiving notifications when the run status changes",
"Mechanism for receiving notifications when the run status changes"
),
metadata: z
.record(z.string())
Expand All @@ -513,16 +513,16 @@ export const definition = {
.object({})
.passthrough()
.describe("The mock output of the function"),
}),
})
)
.optional()
.describe(
"Function mocks to be used in the run. (Keys should be function in the format <SERVICE>_<FUNCTION>)",
"Function mocks to be used in the run. (Keys should be function in the format <SERVICE>_<FUNCTION>)"
),
})
.optional()
.describe(
"When provided, the run will be marked as as a test / evaluation",
"When provided, the run will be marked as as a test / evaluation"
),
config: z
.object({
Expand All @@ -531,7 +531,7 @@ export const definition = {
.object({})
.passthrough()
.describe(
"The run configuration input arguments, the schema must match the run configuration input schema",
"The run configuration input arguments, the schema must match the run configuration input schema"
)
.optional(),
})
Expand Down Expand Up @@ -560,7 +560,7 @@ export const definition = {
.boolean()
.default(true)
.describe(
"Allow the run to be continued with follow-up messages / message edits",
"Allow the run to be continued with follow-up messages / message edits"
),
}),
responses: {
Expand Down Expand Up @@ -638,7 +638,7 @@ export const definition = {
createdAt: z.date(),
pending: z.boolean().default(false),
displayableContext: z.record(z.string()).nullable(),
}),
})
),
401: z.undefined(),
},
Expand Down Expand Up @@ -676,7 +676,7 @@ export const definition = {
configId: z.string().nullable(),
configVersion: z.number().nullable(),
feedbackScore: z.number().nullable(),
}),
})
),
401: z.undefined(),
},
Expand Down Expand Up @@ -840,7 +840,7 @@ export const definition = {
targetFn: z.string(),
service: z.string(),
executingMachineId: z.string().nullable(),
}),
})
),
},
},
Expand Down Expand Up @@ -876,7 +876,7 @@ export const definition = {
createdAt: z.date(),
createdBy: z.string(),
revokedAt: z.date().nullable(),
}),
})
),
},
},
Expand Down Expand Up @@ -906,7 +906,7 @@ export const definition = {
id: z.string(),
lastPingAt: z.date(),
ip: z.string(),
}),
})
),
},
pathParams: z.object({
Expand All @@ -932,10 +932,10 @@ export const definition = {
description: z.string().optional(),
schema: z.string().optional(),
config: FunctionConfigSchema.optional(),
}),
})
)
.optional(),
}),
})
),
},
pathParams: z.object({
Expand Down Expand Up @@ -974,7 +974,7 @@ export const definition = {
createdAt: z.date(),
pending: z.boolean().default(false),
displayableContext: z.record(z.string()).nullable(),
}),
})
),
activity: z.array(
z.object({
Expand All @@ -985,7 +985,7 @@ export const definition = {
createdAt: z.date(),
jobId: z.string().nullable(),
targetFn: z.string().nullable(),
}),
})
),
jobs: z.array(
z.object({
Expand All @@ -997,7 +997,7 @@ export const definition = {
createdAt: z.date(),
approved: z.boolean().nullable(),
approvalRequested: z.boolean().nullable(),
}),
})
),
run: z.object({
id: z.string(),
Expand Down Expand Up @@ -1111,7 +1111,7 @@ export const definition = {
resultSchema: anyObject.nullable(),
inputSchema: anyObject.nullable(),
public: z.boolean(),
}),
})
),
}),
401: z.undefined(),
Expand Down Expand Up @@ -1216,7 +1216,7 @@ export const definition = {
resultSchema: z.unknown().nullable(),
createdAt: z.date(),
updatedAt: z.date(),
}),
})
),
401: z.undefined(),
},
Expand All @@ -1243,7 +1243,7 @@ export const definition = {
createdAt: z.date(),
updatedAt: z.date(),
similarity: z.number(),
}),
})
),
401: z.undefined(),
},
Expand All @@ -1263,7 +1263,7 @@ export const definition = {
jobFailureCount: z.number(),
timeToCompletion: z.number(),
jobCount: z.number(),
}),
})
),
},
pathParams: z.object({
Expand All @@ -1284,7 +1284,7 @@ export const definition = {
.array(z.string())
.transform((tags) => tags.map((tag) => tag.toLowerCase().trim())),
title: z.string(),
}),
})
),
}),
responses: {
Expand Down Expand Up @@ -1312,7 +1312,7 @@ export const definition = {
tags: z.array(z.string()),
title: z.string(),
similarity: z.number(),
}),
})
),
401: z.undefined(),
},
Expand Down Expand Up @@ -1363,7 +1363,7 @@ export const definition = {
data: z.string(),
tags: z.array(z.string()),
title: z.string(),
}),
})
),
401: z.undefined(),
},
Expand Down Expand Up @@ -1393,7 +1393,7 @@ export const definition = {
.max(20)
.default(0)
.describe(
"Time in seconds to keep the request open waiting for a response",
"Time in seconds to keep the request open waiting for a response"
),
}),
headers: z.object({
Expand Down Expand Up @@ -1471,7 +1471,7 @@ export const definition = {
authContext: z.any().nullable(),
runContext: z.any().nullable(),
approved: z.boolean(),
}),
})
),
},
},
Expand Down Expand Up @@ -1503,7 +1503,7 @@ export const definition = {
resultSchema: anyObject
.optional()
.describe(
"A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema",
"A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema"
),
modelId: z.enum(["claude-3-5-sonnet", "claude-3-haiku"]),
temperature: z
Expand All @@ -1520,6 +1520,22 @@ export const definition = {
clusterId: z.string(),
}),
},
getServerStats: {
method: "GET",
path: "/stats",
responses: {
200: z.object({
functionCalls: z.object({
count: z.number(),
}),
tokenUsage: z.object({
input: z.number(),
output: z.number(),
}),
refreshedAt: z.number(),
}),
},
},
} as const;

export const contract = c.router(definition);
Loading
Loading