Skip to content

Commit

Permalink
Add randomized user IDs to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Yarantsev (Yardanico) committed Nov 29, 2023
1 parent c780dea commit b58f96a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { modelMaxToken } from '@constants/chat';
import countTokens from '@utils/messageUtils';
import { ShareGPTSubmitBodyInterface } from '@type/api';
import { ConfigInterface, MessageInterface } from '@type/chat';
import { isAzureEndpoint } from '@utils/api';
import { isAzureEndpoint, uuidv4 } from '@utils/api';

export const getChatCompletion = async (
endpoint: string,
Expand Down Expand Up @@ -47,6 +47,9 @@ export const getChatCompletion = async (
restConfig.model = 'gpt-3.5-turbo';
}

// todo: option in config
restConfig.user = uuidv4();

const response = await fetch(endpoint, {
method: 'POST',
headers,
Expand Down Expand Up @@ -98,6 +101,9 @@ export const getChatCompletionStream = async (

const { max_context, ...restConfig } = config;

// todo: option in config
restConfig.user = uuidv4();

const response = await fetch(endpoint, {
method: 'POST',
headers,
Expand Down
1 change: 1 addition & 0 deletions src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ConfigInterface {
presence_penalty: number;
top_p: number;
frequency_penalty: number;
user?: string;
}

export interface ChatHistoryInterface {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export const isAzureEndpoint = (endpoint: string) => {
return endpoint.includes('openai.azure.com');
};

export const uuidv4 = (): string =>
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c =>
((c === 'x' ? Math.random() * 16 : (Math.random() * 16 & 0x3 | 0x8)) | 0).toString(16)
);

0 comments on commit b58f96a

Please sign in to comment.