Skip to content

Commit

Permalink
chore!: update env variables to avoid naming misunderstanding (Issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikitabut authored Jan 4, 2024
1 parent ab0b0ae commit e77f268
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 94 deletions.
12 changes: 6 additions & 6 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenAI keys
OPENAI_API_HOST=""
OPENAI_API_KEY=""
OPENAI_API_VERSION="2023-03-15-preview"
# Dial environment variables
DIAL_API_HOST=""
DIAL_API_KEY=""
DIAL_API_VERSION="2023-03-15-preview"

# App Settings
APP_BASE_PATH=""
Expand Down Expand Up @@ -86,10 +86,10 @@ THEMES_CONFIG_HOST=""
FOOTER_HTML_MESSAGE="For API access please fill&nbsp;<a href="#requestApiKey"><u><strong>this form</strong></u></a>.&nbsp;If you have a problem please&nbsp;<a href="#reportAnIssue"><u><strong>report an issue</strong></u></a>. Version %%VERSION%%"
AZURE_FUNCTIONS_API_HOST=""

## Report issue modal
## Report issue modal code
REPORT_ISSUE_CODE=""

## Request API Key code
## Request API Key modal code
REQUEST_API_KEY_CODE=""

## Warning regarding code generation
Expand Down
2 changes: 1 addition & 1 deletion .github/pr-title-checker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"color": "EEEEEE"
},
"CHECKS": {
"prefixes": ["fix: ", "feat: ", "feature: ", "chore: ", "hotfix: ", "e2e: "]
"prefixes": ["fix: ", "feat: ", "feature: ", "chore: ", "hotfix: ", "e2e: ", "fix!: ", "feat!: ", "feature!: ", "chore!: ", "hotfix!: "]
},
"MESSAGES": {
"success": "All OK",
Expand Down
132 changes: 66 additions & 66 deletions README.md

Large diffs are not rendered by default.

68 changes: 65 additions & 3 deletions environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,73 @@ export {};
declare global {
namespace NodeJS {
interface ProcessEnv {
OPENAI_API_KEY: string;
OPENAI_API_HOST: string;
OPENAI_API_VERSION?: string;
DIAL_API_KEY: string;
DIAL_API_HOST: string;

DIAL_API_VERSION?: string;
APP_BASE_PATH?: string;
APP_BASE_ORIGIN?: string;
ALLOWED_IFRAME_ORIGINS?: string;
IS_IFRAME?: string;
ENABLED_FEATURES?: string;
NEXT_PUBLIC_APP_NAME?: string;
NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT?: string;
NEXT_PUBLIC_DEFAULT_TEMPERATURE?: string;
DEFAULT_MODEL?: string;
DEFAULT_ASSISTANT_SUB_MODEL?: string;
RECENT_MODELS_IDS?: string;
RECENT_ADDONS_IDS?: string;
E2E_HOST?: string;
E2E_USERNAME?: string;
E2E_PASSWORD?: string;
TRACES_URL?: string;
TMS_URL?: string;
ISSUE_URL?: string;
THEMES_CONFIG_HOST?: string;
FOOTER_HTML_MESSAGE?: string;
ANNOUNCEMENT_HTML_MESSAGE?: string;
AZURE_FUNCTIONS_API_HOST?: string;
REPORT_ISSUE_CODE?: string;
REQUEST_API_KEY_CODE?: string;
CODE_GENERATION_WARNING?: string;
SHOW_TOKEN_SUB?: string;
STORAGE_TYPE?: string;
TRACES_URL?: string;

AUTH_DISABLED?: string;
NEXTAUTH_URL?: string;
NEXTAUTH_SECRET?: string;
AUTH_TEST_TOKEN?: string;
AUTH_AUTH0_AUDIENCE?: string;
AUTH_AUTH0_CLIENT_ID?: string;
AUTH_AUTH0_HOST?: string;
AUTH_AUTH0_NAME?: string;
AUTH_AUTH0_SECRET?: string;
AUTH_AUTH0_SCOPE?: string;
AUTH_AZURE_AD_CLIENT_ID?: string;
AUTH_AZURE_AD_NAME?: string;
AUTH_AZURE_AD_SECRET?: string;
AUTH_AZURE_AD_TENANT_ID?: string;
AUTH_AZURE_AD_SCOPE?: string;
AUTH_GITLAB_CLIENT_ID?: string;
AUTH_GITLAB_HOST?: string;
AUTH_GITLAB_NAME?: string;
AUTH_GITLAB_SECRET?: string;
AUTH_GITLAB_SCOPE?: string;
AUTH_GOOGLE_CLIENT_ID?: string;
AUTH_GOOGLE_NAME?: string;
AUTH_GOOGLE_SECRET?: string;
AUTH_GOOGLE_SCOPE?: string;
AUTH_KEYCLOAK_CLIENT_ID?: string;
AUTH_KEYCLOAK_HOST?: string;
AUTH_KEYCLOAK_NAME?: string;
AUTH_KEYCLOAK_SECRET?: string;
AUTH_KEYCLOAK_SCOPE?: string;
AUTH_PING_ID_CLIENT_ID?: string;
AUTH_PING_ID_HOST?: string;
AUTH_PING_ID_NAME?: string;
AUTH_PING_ID_SECRET?: string;
AUTH_PING_ID_SCOPE?: string;
}
}
}
7 changes: 3 additions & 4 deletions src/constants/default-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { OpenAIEntityModelID, OpenAIEntityModels } from '@/src/types/openai';
export const DEFAULT_SYSTEM_PROMPT =
process.env.NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT ?? '';

export const OPENAI_API_HOST =
process.env.OPENAI_API_HOST || 'https://api.openai.com';
export const DIAL_API_HOST = process.env.DIAL_API_HOST;

export const DEFAULT_TEMPERATURE = parseFloat(
process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE || '1',
);

export const DEFAULT_CONVERSATION_NAME = 'New conversation';

export const OPENAI_API_VERSION =
process.env.OPENAI_API_VERSION || '2023-03-15-preview';
export const DIAL_API_VERSION =
process.env.DIAL_API_VERSION || '2023-03-15-preview';

export const DEFAULT_ASSISTANT_SUBMODEL =
OpenAIEntityModels[OpenAIEntityModelID.GPT_4];
6 changes: 3 additions & 3 deletions src/pages/api/files/file/[...slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function handlePutRequest(
if (!slugs || slugs.length === 0) {
throw new OpenAIError('No file path provided', '', '', '400');
}
const url = `${process.env.OPENAI_API_HOST}/v1/files/${encodeURI(
const url = `${process.env.DIAL_API_HOST}/v1/files/${encodeURI(
slugs.join('/'),
)}`;
const proxyRes = await fetch(url, {
Expand Down Expand Up @@ -101,7 +101,7 @@ async function handleGetRequest(
if (!slugs || slugs.length === 0) {
throw new OpenAIError('No file path provided', '', '', '400');
}
const url = `${process.env.OPENAI_API_HOST}/v1/files/${encodeURI(
const url = `${process.env.DIAL_API_HOST}/v1/files/${encodeURI(
slugs.join('/'),
)}`;
const proxyRes = await fetch(url, {
Expand Down Expand Up @@ -134,7 +134,7 @@ async function handleDeleteRequest(
if (!slugs || slugs.length === 0) {
throw new OpenAIError('No file path provided', '', '', '400');
}
const url = `${process.env.OPENAI_API_HOST}/v1/files/${encodeURI(
const url = `${process.env.DIAL_API_HOST}/v1/files/${encodeURI(
slugs.join('/'),
)}`;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/files/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {

const token = await getToken({ req });

const url = `${process.env.OPENAI_API_HOST}/v1/files/metadata/${bucket}${
const url = `${process.env.DIAL_API_HOST}/v1/files/metadata/${bucket}${
path && `/${encodeURI(path)}`
}/`;

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { logger } from '@/src/utils/server/logger';

import { RateBody } from '../../types/chat';

import { OPENAI_API_HOST } from '@/src/constants/default-settings';
import { DIAL_API_HOST } from '@/src/constants/default-settings';
import { errorsMessages } from '@/src/constants/errors';

import { authOptions } from './auth/[...nextauth]';
Expand All @@ -30,7 +30,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(400).send(errorsMessages[400]);
}

const url = `${OPENAI_API_HOST}/v1/${modelId}/rate`;
const url = `${DIAL_API_HOST}/v1/${modelId}/rate`;
const token = await getToken({ req });

await fetch(url, {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/server/get-entities.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EntityType } from '@/src/types/common';

import {
OPENAI_API_HOST,
OPENAI_API_VERSION,
DIAL_API_HOST,
DIAL_API_VERSION,
} from '../../constants/default-settings';

import { getApiHeaders } from './get-headers';
Expand All @@ -14,7 +14,7 @@ export async function getEntities<T>(
jwt: string,
jobTitle: string | undefined,
): Promise<T> {
const url = `${OPENAI_API_HOST}/openai/${type}s?api-version=${OPENAI_API_VERSION}`;
const url = `${DIAL_API_HOST}/openai/${type}s?api-version=${DIAL_API_VERSION}`;
const errMsg = `Request for ${type}s returned an error`;
const response = await fetch(url, {
headers: getApiHeaders({ jwt, jobTitle }),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/server/get-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getApiHeaders = ({
if (jwt) {
headers['authorization'] = 'Bearer ' + jwt;
} else if (process.env.AUTH_DISABLED === 'true') {
headers['Api-Key'] = process.env.OPENAI_API_KEY;
headers['Api-Key'] = process.env.DIAL_API_HOST;
}

if (jobTitle) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {

import {
DEFAULT_ASSISTANT_SUBMODEL,
OPENAI_API_HOST,
OPENAI_API_VERSION,
DIAL_API_HOST,
DIAL_API_VERSION,
} from '../../constants/default-settings';
import { errorsMessages } from '@/src/constants/errors';

Expand Down Expand Up @@ -42,10 +42,10 @@ function getUrl(
isAddonsAdded: boolean,
): string {
if (modelType === EntityType.Model && isAddonsAdded) {
return `${OPENAI_API_HOST}/openai/deployments/assistant/chat/completions?api-version=${OPENAI_API_VERSION}`;
return `${DIAL_API_HOST}/openai/deployments/assistant/chat/completions?api-version=${DIAL_API_VERSION}`;
}

return `${OPENAI_API_HOST}/openai/deployments/${modelId}/chat/completions?api-version=${OPENAI_API_VERSION}`;
return `${DIAL_API_HOST}/openai/deployments/${modelId}/chat/completions?api-version=${DIAL_API_VERSION}`;
}

const encoder = new TextEncoder();
Expand Down

0 comments on commit e77f268

Please sign in to comment.