Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions app/api/app-idea-chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import { getAnthropicModel } from '@/lib/anthropic-model'
import { getCurrentUser } from '@/lib/auth'
import { deductCredits, CREDITS } from '@/lib/credits'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

export interface AppIdeaSuggestion {
name: string
Expand Down Expand Up @@ -141,7 +150,7 @@ Always respond with valid JSON only (no markdown fences):
{ role: 'user', content: message },
]

const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: getAnthropicModel(),
max_tokens: 2048,
system: systemPrompt,
Expand Down
13 changes: 11 additions & 2 deletions app/api/build-app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import { getCurrentUser } from '@/lib/auth'
import { getAnthropicModel } from '@/lib/anthropic-model'
import type { AppBlueprint } from '@/lib/queries'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

type Platform = 'github' | 'gitlab'

Expand Down Expand Up @@ -59,7 +68,7 @@ Rules:
Return format: {"path/to/file.ts": "...full content...", "README.md": "..."}
`

const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: getAnthropicModel(),
max_tokens: 8192,
messages: [{ role: 'user', content: prompt }],
Expand Down
13 changes: 11 additions & 2 deletions app/api/pattern-analyzer/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import { getAnthropicModel } from '@/lib/anthropic-model'
import { getCurrentUser } from '@/lib/auth'
import { deductCredits, CREDITS } from '@/lib/credits'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

export interface ProjectSuggestion {
name: string
Expand Down Expand Up @@ -154,7 +163,7 @@ Respond ONLY with a valid JSON object (no markdown fences) matching this exact s
]
}`

const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: getAnthropicModel(),
max_tokens: 4096,
messages: [{ role: 'user', content: prompt }],
Expand Down
13 changes: 11 additions & 2 deletions lib/app-discovery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Anthropic } from '@anthropic-ai/sdk'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

export interface DiscoveredApp {
name: string
Expand Down Expand Up @@ -44,7 +53,7 @@ For each app, provide:

Format as JSON array with objects containing these fields.`

const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 8000,
messages: [
Expand Down
15 changes: 12 additions & 3 deletions lib/code-completion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Anthropic } from '@anthropic-ai/sdk'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

/**
* Represents a code snippet with semantic metadata
Expand Down Expand Up @@ -61,7 +70,7 @@ Extract and return JSON with:
Return ONLY valid JSON, no markdown formatting.`

try {
const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 2000,
messages: [{ role: 'user', content: prompt }],
Expand Down Expand Up @@ -261,7 +270,7 @@ Complete the code:
\`\`\`${language}`

try {
const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 4000,
messages: [{ role: 'user', content: prompt }],
Expand Down
13 changes: 11 additions & 2 deletions lib/cross-platform-scanner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { cookies } from 'next/headers'
import { Anthropic } from '@anthropic-ai/sdk'

const anthropic = new Anthropic()
let __anthropicClient: Anthropic | null = null
function getAnthropic(): Anthropic {
if (__anthropicClient) return __anthropicClient
const key = process.env.ANTHROPIC_API_KEY
if (!key) {
throw new Error('ANTHROPIC_API_KEY is not configured')
}
__anthropicClient = new Anthropic({ apiKey: key })
return __anthropicClient
}

interface ScannedFile {
path: string
Expand Down Expand Up @@ -55,7 +64,7 @@ For each file, provide:
- Reusability score
- Can this be combined with other files to build apps?`

const response = await anthropic.messages.create({
const response = await getAnthropic().messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 4000,
messages: [
Expand Down
Loading