Skip to content

Commit

Permalink
ai
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Oct 25, 2024
1 parent 9468f73 commit 5b97b2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { generateText } from 'ai';
import type { NextRequest } from 'next/server';

export async function POST(req: NextRequest) {
const { prompt, system, apiKey: key } = await req.json();
const {
prompt,
system,
apiKey: key,
model = 'gpt-4o-mini',
} = await req.json();

const apiKey = key || process.env.OPENAI_API_KEY;

Expand All @@ -16,15 +21,13 @@ export async function POST(req: NextRequest) {
);
}

console.log(apiKey);

const openai = createOpenAI({ apiKey });

try {
const result = await generateText({
abortSignal: req.signal,
maxTokens: 50,
model: openai('gpt-4o-mini'),
model: openai(model),
prompt: prompt,
system,
temperature: 0.7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function SettingsDialog() {
body: {
...completeOptions.body,
apiKey: tempKey,
model: model.value,
},
});
};
Expand Down Expand Up @@ -184,7 +185,7 @@ export function SettingsDialog() {
</Popover>

<Button type="submit" className="w-full">
Set API Key
Save
</Button>
</form>
<p className="mt-4 text-sm text-muted-foreground">
Expand Down

0 comments on commit 5b97b2d

Please sign in to comment.