Skip to content

Commit 25b5872

Browse files
committed
chat: add configure openai api base and model
1 parent 2480217 commit 25b5872

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

apps/postgres-new/app/api/chat/route.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openai } from '@ai-sdk/openai'
1+
import { createOpenAI } from '@ai-sdk/openai'
22
import { ToolInvocation, convertToCoreMessages, streamText } from 'ai'
33
import { codeBlock } from 'common-tags'
44
import { convertToCoreTools, maxMessageContext, maxRowLimit, tools } from '~/lib/tools'
@@ -12,6 +12,15 @@ type Message = {
1212
toolInvocations?: (ToolInvocation & { result: any })[]
1313
}
1414

15+
const chatModel = process.env.OPENAI_MODEL || 'gpt-4o-2024-08-06'
16+
17+
// Configure OpenAI client with custom base URL
18+
const openai = createOpenAI({
19+
apiKey: process.env.OPENAI_API_KEY,
20+
baseURL: process.env.OPENAI_API_BASE || 'https://api.openai.com/v1',
21+
compatibility: 'strict',
22+
})
23+
1524
export async function POST(req: Request) {
1625
const { messages }: { messages: Message[] } = await req.json()
1726

@@ -49,7 +58,7 @@ export async function POST(req: Request) {
4958
5059
When importing CSVs try to solve the problem yourself (eg. use a generic text column, then refine)
5160
vs. asking the user to change the CSV. No need to select rows after importing.
52-
61+
5362
You also know math. All math equations and expressions must be written in KaTex and must be wrapped in double dollar \`$$\`:
5463
- Inline: $$\\sqrt{26}$$
5564
- Multiline:
@@ -61,7 +70,7 @@ export async function POST(req: Request) {
6170
6271
Feel free to suggest corrections for suspected typos.
6372
`,
64-
model: openai('gpt-4o-2024-08-06'),
73+
model: openai(chatModel),
6574
messages: convertToCoreMessages(trimmedMessageContext),
6675
tools: convertToCoreTools(tools),
6776
})

0 commit comments

Comments
 (0)