Skip to content

Commit 2e87c50

Browse files
committed
we'll add anthropic eventually
1 parent f5acf1d commit 2e87c50

File tree

9 files changed

+55
-23
lines changed

9 files changed

+55
-23
lines changed

src/app/api/mocker/[filename]/route.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ export async function GET(req: NextRequest) {
8989
name,
9090
prompt,
9191
})
92-
const data = await imagineJSON<Record<string, any>>(prompt, {}, '{')
92+
const data = await imagineJSON<Record<string, any>>(prompt, {}, '{', {} as any)
9393
return NextResponse.json(data, {
9494
status: 200,
9595
statusText: "OK",
96-
headers
96+
headers,
9797
})
9898
} else if (['txt'].includes(extension)) {
9999
const prompt = mockText(name)

src/app/content/page.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ function Content() {
149149
tasksPrompt(prompt),
150150
{},
151151
'{',
152-
model,
153-
apiKey,
154-
mockData
152+
settings
155153
)
156154
} catch (exc) {
157155
console.error(`tab.content(${id}): generateTasks: failed`, exc)

src/app/search/page.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ function Search() {
8585
searchTemplate(prompt, nbResults),
8686
[],
8787
'[',
88-
settings?.openAIModel,
89-
settings?.openAIKey,
90-
settings?.useMockData
88+
settings
9189
)
9290
} catch (exc) {
9391
console.error(exc)

src/app/settings/page.tsx

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use client"
22

3-
import { type Settings } from '../../types'
3+
import { LLMVendor, type Settings } from '../../types'
44
import { useSettings } from '../../hooks/useSettings'
55
import { SettingInput } from '../../components/inputs/SettingInput'
66
import { Toggle } from '../../components/toggle'
77

88
type BaseField = {
99
label: string
1010
description?: string
11+
vendorSpecific?: LLMVendor
1112
}
1213

1314
export type SpecializedField =
@@ -58,9 +59,14 @@ const fields: Partial<SettingsFields> & MiscPanelFields = {
5859
options: [
5960
{
6061
description:
61-
'OpenAI - about $0.08 per query (includes search + generation)',
62+
'OpenAI (will bill your own account, please be careful)',
6263
value: 'OPENAI',
6364
},
65+
{
66+
description:
67+
'Anthropic (will bill your own account, please be careful)',
68+
value: 'ANTHROPIC',
69+
},
6470
/*
6571
{
6672
description: 'HuggingFace',
@@ -96,20 +102,46 @@ const fields: Partial<SettingsFields> & MiscPanelFields = {
96102
description:
97103
'You need a valid OpenAI account and API token to use this vendor',
98104
type: 'section',
105+
vendorSpecific: "OPENAI",
99106
},
100107
openAIKey: {
101108
label: 'API Key',
102109
description: '',
103110
placeholder: 'Enter your OpenAI API access key',
104111
type: 'password',
105112
defaultValue: '',
113+
vendorSpecific: 'OPENAI',
106114
},
107115
openAIModel: {
108116
label: 'Language Model',
109117
description: '',
110-
placeholder: 'Enter the model (default: gpt-4-turbo)',
118+
placeholder: 'Enter the model (default: gpt-4o)',
119+
type: 'text',
120+
defaultValue: 'gpt-4o',
121+
vendorSpecific: 'OPENAI',
122+
},
123+
anthropic: {
124+
label: 'Anthropic Settings',
125+
description:
126+
'You need a valid Anthropic account and API token to use this vendor',
127+
type: 'section',
128+
vendorSpecific: "ANTHROPIC",
129+
},
130+
anthropicKey: {
131+
label: 'API Key',
132+
description: '',
133+
placeholder: 'Enter your Anthropic API access key',
134+
type: 'password',
135+
defaultValue: '',
136+
vendorSpecific: 'ANTHROPIC',
137+
},
138+
anthropicModel: {
139+
label: 'Language Model',
140+
description: '',
141+
placeholder: 'Enter the model (default: claude-3-5-sonnet-20240620)',
111142
type: 'text',
112-
defaultValue: 'gpt-4-turbo',
143+
defaultValue: 'claude-3-5-sonnet-20240620',
144+
vendorSpecific: 'ANTHROPIC',
113145
},
114146
/*
115147
customPrompts: {
@@ -168,6 +200,7 @@ const fields: Partial<SettingsFields> & MiscPanelFields = {
168200
function Favorites() {
169201
const [settings, setSettings] = useSettings()
170202
const isLoading = !settings
203+
const vendor: LLMVendor = settings.coreVendor
171204

172205
return isLoading ? (
173206
<div className="flex items-center justify-center h-screen w-screen text-gray-800">
@@ -182,7 +215,7 @@ function Favorites() {
182215
Settings
183216
</h3>
184217
<div className="flex flex-col w-full">
185-
{Object.entries(fields).map(
218+
{Object.entries(fields).filter(s => s[1].vendorSpecific ? ( s[1].vendorSpecific === vendor) : true).map(
186219
([name, { label, description, ...field }]) => (
187220
<div key={name} className="flex flex-col py-3 w-full">
188221
{field.type === 'section' ? (

src/hooks/useSettings.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export const useSettings = (
1010
huggingFaceKey: '',
1111
huggingFaceModel: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
1212
openAIKey: '',
13-
openAIModel: 'gpt-4-turbo',
13+
openAIModel: 'gpt-4o',
14+
anthropicKey: '',
15+
anthropicModel: 'claude-3-5-sonnet-20240620',
1416
customTasksPrompt: '',
1517
customHtmlPrompt: '',
1618
customScriptPrompt: '',

src/providers/anthropic/complete.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
import Anthropic from '@anthropic-ai/sdk';
31
import { MessageParam } from '@anthropic-ai/sdk/resources/index.mjs';
42

53
import { CompleteFnParams } from "@/types"

src/providers/openai/complete.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function complete({
1515
}: CompleteFnParams): Promise<string> {
1616

1717
// don't do this if you deploy the latent browser on a server!!!
18-
persisted.model = model || 'gpt-4-turbo'
18+
persisted.model = model || 'gpt-4o'
1919

2020
const openai = await getOpenAI(apiKey)
2121

src/providers/openai/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { presets } from '../../engine/prompts/presets'
1010
import { type PromptSettings } from '../../engine/prompts/types'
1111
import { getOpenAI } from './getOpenAI'
1212
import { complete } from './complete'
13+
import { Settings } from '@/types'
1314

1415
export const imagineString = async (
1516
prompt: string,
@@ -165,22 +166,22 @@ export const imagineJSON = async <T>(
165166
prompt: string,
166167
defaultValue: T,
167168
prefix: string,
168-
model?: string,
169-
apiKey?: string,
170-
mockData?: boolean
169+
settings: Settings
171170
): Promise<T> => {
172171
console.log('imagineJSON> prompt:', prompt)
173172

173+
const { model, apiKey, mockData } = settings
174+
174175
if (mockData) {
175176
return mocks.json<T>(prefix)
176177
}
177178

178179
let output = await imagineString(
179180
prompt,
180181
presets.json,
181-
model,
182-
apiKey,
183-
mockData
182+
typeof model === "string" ? model : undefined,
183+
typeof apiKey === "string" ? apiKey : undefined,
184+
typeof mockData === "boolean" ? mockData : undefined,
184185
)
185186

186187
try {

src/types/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export type Settings = Record<string, string | boolean> & {
7575
huggingFaceModel: string
7676
openAIKey: string
7777
openAIModel: string
78+
anthropicKey: string
79+
anthropicModel: string
7880
customTasksPrompt: string
7981
customHtmlPrompt: string
8082
customScriptPrompt: string

0 commit comments

Comments
 (0)