Skip to content

feat: include UID in requests per OpenAI guidance #48

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export function Chat() {
.filter(([_, server]) => server),
),
model: selectedModel,
userId: user?.id,
}),
[selectedServers, servers, selectedModel],
[selectedServers, servers, selectedModel, user?.id],
)

const { messages, input, handleInputChange, handleSubmit, isLoading } =
Expand Down
11 changes: 8 additions & 3 deletions src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createContext, useContext } from 'react'
import type { ReactNode } from 'react'
import { getBrowserUser } from '@pomerium/js-sdk'
import { useQuery } from '@tanstack/react-query'
import type { UserInfo } from 'node_modules/@pomerium/js-sdk/lib/esm/types/utils'
import type { UserInfo as PomeriumUserInfo } from 'node_modules/@pomerium/js-sdk/lib/esm/types/utils'

type UserInfo = PomeriumUserInfo & {
id: string | undefined
}

type UserContextType = {
user: UserInfo | undefined
Expand All @@ -16,9 +20,10 @@ async function fetchUserInfo(): Promise<UserInfo> {
const userInfo = await getBrowserUser()

return {
email: userInfo.email ?? '',
name: userInfo.name ?? '',
email: userInfo.email,
name: userInfo.name,
picture: userInfo.picture as string,
id: userInfo.user,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const chatRequestSchema = z.object({
messages: z.array(messageSchema),
servers: serversSchema,
model: z.string(),
userId: z.string(),
})

// Types
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const APIRoute = createAPIFileRoute('/api/chat')({
})
}

const { messages, servers, model } = result.data
const { messages, servers, model, userId } = result.data

if (messages.length === 0) {
return new Response(JSON.stringify({ error: 'No messages provided' }), {
Expand Down Expand Up @@ -87,6 +87,7 @@ export const APIRoute = createAPIFileRoute('/api/chat')({
tools,
input,
stream: true,
user: userId,
})

return streamText(answer)
Expand Down
Loading