Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions apps/postgres-new/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NEXT_PUBLIC_SUPABASE_URL="<supabase-api-url>"
NEXT_PUBLIC_IS_PREVIEW=true

OPENAI_API_KEY="<openai-api-key>"
# OPENAI_API_BASE="https://api.openai.com/v1"
# OPENAI_MODEL="gpt-4o-2024-08-06"
15 changes: 12 additions & 3 deletions apps/postgres-new/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openai } from '@ai-sdk/openai'
import { createOpenAI } from '@ai-sdk/openai'
import { ToolInvocation, convertToCoreMessages, streamText } from 'ai'
import { codeBlock } from 'common-tags'
import { convertToCoreTools, maxMessageContext, maxRowLimit, tools } from '~/lib/tools'
Expand All @@ -12,6 +12,15 @@ type Message = {
toolInvocations?: (ToolInvocation & { result: any })[]
}

const chatModel = process.env.OPENAI_MODEL || 'gpt-4o-2024-08-06'

// Configure OpenAI client with custom base URL
const openai = createOpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_API_BASE || 'https://api.openai.com/v1',
compatibility: 'strict',
})

export async function POST(req: Request) {
const { messages }: { messages: Message[] } = await req.json()

Expand Down Expand Up @@ -49,7 +58,7 @@ export async function POST(req: Request) {

When importing CSVs try to solve the problem yourself (eg. use a generic text column, then refine)
vs. asking the user to change the CSV. No need to select rows after importing.

You also know math. All math equations and expressions must be written in KaTex and must be wrapped in double dollar \`$$\`:
- Inline: $$\\sqrt{26}$$
- Multiline:
Expand All @@ -61,7 +70,7 @@ export async function POST(req: Request) {

Feel free to suggest corrections for suspected typos.
`,
model: openai('gpt-4o-2024-08-06'),
model: openai(chatModel),
messages: convertToCoreMessages(trimmedMessageContext),
tools: convertToCoreTools(tools),
})
Expand Down