Skip to content

Commit

Permalink
sanitize names for openai
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Sep 19, 2024
1 parent 78f7a37 commit d26e484
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ai/openai/src/OpenAiCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const formatRole = (role: AiRole.AiRole) => {
case "UserWithName":
return {
role: "user",
name: role.name
name: safeName(role.name)
} as const
case "User":
return {
Expand Down Expand Up @@ -301,3 +301,5 @@ const makeSystemMessage = (content: string): typeof Generated.ChatCompletionRequ
content
}
}

const safeName = (name: string) => name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/, "_")

0 comments on commit d26e484

Please sign in to comment.