feat: include UID in requests per OpenAI guidance#48
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a user identifier to the OpenAI API requests to meet updated requirements as discussed in issue #46.
- The API route now extracts and passes a user ID from the result data.
- The chat request schema has been updated to require a userId field.
- The user context and Chat component are updated to incorporate the user identifier in client-side logic.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/routes/api/chat.ts | Destructure userId from result data and pass it to the stream call. |
| src/lib/schemas.ts | Add a required userId string to the chat request schema. |
| src/contexts/UserContext.tsx | Update the user information mapping to include an id field. |
| src/components/Chat.tsx | Include user?.id as userId in the Chat component’s payload and dependency list. |
Comments suppressed due to low confidence (4)
src/lib/schemas.ts:68
- Including userId as a required string in the schema is appropriate; confirm that all clients sending requests conform to this updated schema.
userId: z.string(),
src/contexts/UserContext.tsx:26
- [nitpick] Mapping userInfo.user to id is acceptable, but consider adding a comment clarifying this choice to ensure consistency for future developers.
id: userInfo.user,
src/routes/api/chat.ts:38
- The addition of userId looks correct; please ensure that the downstream API consumer properly validates and handles the new 'user' field in the streamText call.
const { messages, servers, model, userId } = result.data
src/components/Chat.tsx:55
- Including user?.id in the payload and dependency list is correct; ensure that the component gracefully handles scenarios where user?.id might be undefined.
userId: user?.id,
Member
Author
|
@wasaga, in the end, I didn't need to make changes to the |
0a88d6e to
1afe10d
Compare
Member
Author
|
Just wondering if anything is blocking this @wasaga from being merged. |
1afe10d to
2963d39
Compare
09c2880 to
017e899
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for including a unique end-user ID (uid) in outbound requests to OpenAI, in line with their abuse monitoring recommendations. OpenAI recommends sending a unique end-user ID with each request to help them detect and prevent abuse more effectively. This allows them to provide more actionable feedback if any policy violations are identified in our application.
Closes #46