Skip to content

Commit

Permalink
Add OPENAI_BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
lvwzhen committed May 4, 2023
1 parent bfacffe commit 6ae9d68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env.example
Expand Up @@ -5,4 +5,5 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=

# Get your key at https://platform.openai.com/account/api-keys
OPENAI_KEY=
OPENAI_KEY=
OPENAI_BASE_URL=
7 changes: 4 additions & 3 deletions pages/api/vector-search.ts
Expand Up @@ -11,6 +11,7 @@ export const config = {
}

const openAiKey = process.env.OPENAI_KEY
const openAiBaseUrl = process.env.OPENAI_BASE_URL
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY

Expand Down Expand Up @@ -44,7 +45,7 @@ export default async function handler(req: NextRequest) {

// Moderate the content to comply with OpenAI T&C
const sanitizedQuery = query.trim()
const moderationResponse = await fetch('https://api.openai.com/v1/moderations', {
const moderationResponse = await fetch('https://' + openAiBaseUrl + '/v1/v1/moderations', {
method: 'POST',
headers: {
Authorization: `Bearer ${openAiKey}`,
Expand All @@ -64,7 +65,7 @@ export default async function handler(req: NextRequest) {
})
}

const embeddingResponse = await fetch('https://api.openai.com/v1/embeddings', {
const embeddingResponse = await fetch('https://' + openAiBaseUrl + '/v1/v1/embeddings', {
method: 'POST',
headers: {
Authorization: `Bearer ${openAiKey}`,
Expand Down Expand Up @@ -143,7 +144,7 @@ export default async function handler(req: NextRequest) {
stream: true,
}

const response = await fetch('https://api.openai.com/v1/chat/completions', {
const response = await fetch('https://' + openAiBaseUrl + '/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${openAiKey}`,
Expand Down

0 comments on commit 6ae9d68

Please sign in to comment.