Skip to content

Commit bcae852

Browse files
committed
zen: remove hardcoded safety identifier
1 parent 16ddf5f commit bcae852

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,34 @@ export async function handler(
141141
)
142142
validateModelSettings(billingSource, authInfo)
143143
updateProviderKey(authInfo, providerInfo)
144-
logger.metric({ provider: providerInfo.id })
144+
logger.metric({
145+
provider: providerInfo.id,
146+
"provider.model": providerInfo.model,
147+
})
145148

146149
const startTimestamp = Date.now()
147150
const reqUrl = providerInfo.modifyUrl(providerInfo.api, isStream)
148151
const reqBody = JSON.stringify(
149152
providerInfo.modifyBody({
150153
...createBodyConverter(opts.format, providerInfo.format)(body),
151154
model: providerInfo.model,
152-
...providerInfo.payloadModifier,
153-
...Object.fromEntries(
154-
Object.entries(providerInfo.payloadMappings ?? {})
155-
.map(([k, v]) => [k, input.request.headers.get(v)])
156-
.filter(([_k, v]) => !!v),
157-
),
155+
...(() => {
156+
const replacer = (obj: Record<string, any>): Record<string, any> =>
157+
Object.fromEntries(
158+
Object.entries(obj).flatMap(([k, v]) => {
159+
if (Array.isArray(v)) return [[k, v]]
160+
if (typeof v === "object") return [[k, replacer(v)]]
161+
if (v === "$ip") return [[k, ip]]
162+
if (v === "$workspace") return authInfo?.workspaceID ? [[k, authInfo?.workspaceID]] : []
163+
if (v.startsWith("$header.")) {
164+
const headerValue = input.request.headers.get(v.slice(8))
165+
return headerValue ? [[k, headerValue]] : []
166+
}
167+
return [[k, v]]
168+
}),
169+
)
170+
return replacer(providerInfo.payloadModifier ?? {})
171+
})(),
158172
}),
159173
)
160174
logger.debug("REQUEST URL: " + reqUrl)
@@ -514,7 +528,6 @@ export async function handler(
514528
reqModel,
515529
providerModel: modelProvider.model,
516530
adjustCacheUsage: providerProps.adjustCacheUsage,
517-
safetyIdentifier: modelProvider.safetyIdentifier ? ip : undefined,
518531
workspaceID: authInfo?.workspaceID,
519532
}
520533
if (format === "anthropic") return anthropicHelper(opts)

packages/console/app/src/routes/zen/util/provider/openai-compatible.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Usage = {
2323
}
2424
}
2525

26-
export const oaCompatHelper: ProviderHelper = ({ adjustCacheUsage, safetyIdentifier }) => ({
26+
export const oaCompatHelper: ProviderHelper = ({ adjustCacheUsage }) => ({
2727
format: "oa-compat",
2828
modifyUrl: (providerApi: string) => providerApi + "/chat/completions",
2929
modifyHeaders: (headers: Headers, body: Record<string, any>, apiKey: string) => {
@@ -34,7 +34,6 @@ export const oaCompatHelper: ProviderHelper = ({ adjustCacheUsage, safetyIdentif
3434
return {
3535
...body,
3636
...(body.stream ? { stream_options: { include_usage: true } } : {}),
37-
...(safetyIdentifier ? { safety_identifier: safetyIdentifier } : {}),
3837
}
3938
},
4039
createBinaryStreamDecoder: () => undefined,

packages/console/app/src/routes/zen/util/provider/openai.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ export const openaiHelper: ProviderHelper = ({ workspaceID }) => ({
1818
modifyHeaders: (headers: Headers, body: Record<string, any>, apiKey: string) => {
1919
headers.set("authorization", `Bearer ${apiKey}`)
2020
},
21-
modifyBody: (body: Record<string, any>) => ({
22-
...body,
23-
...(workspaceID ? { safety_identifier: workspaceID } : {}),
24-
}),
21+
modifyBody: (body: Record<string, any>) => body,
2522
createBinaryStreamDecoder: () => undefined,
2623
streamSeparator: "\n\n",
2724
createUsageParser: () => {

packages/console/app/src/routes/zen/util/provider/provider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export type ProviderHelper = (input: {
3737
reqModel: string
3838
providerModel: string
3939
adjustCacheUsage?: boolean
40-
safetyIdentifier?: string
4140
workspaceID?: string
4241
}) => {
4342
format: ZenData.Format

packages/console/core/src/model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export namespace ZenData {
4040
disabled: z.boolean().optional(),
4141
storeModel: z.string().optional(),
4242
payloadModifier: z.record(z.string(), z.any()).optional(),
43-
safetyIdentifier: z.boolean().optional(),
4443
}),
4544
),
4645
})

0 commit comments

Comments
 (0)