harvesthealth commited on
Commit
fc051a4
·
verified ·
1 Parent(s): 2cb33c7

Refactor: Consolidate AI providers to Blablador (3/5)

Browse files
Files changed (1) hide show
  1. app/api/text-generation/route.ts +6 -13
app/api/text-generation/route.ts CHANGED
@@ -1,22 +1,15 @@
1
  import { streamText } from 'ai';
2
- import { createOpenAI } from '@ai-sdk/openai';
3
-
4
- const customOpenAI = createOpenAI({
5
- apiKey: process.env.BLABLADOR_API_KEY || '',
6
- baseURL: 'https://api.openai.com/v1', // Trick the SDK to use the OpenAI format
7
- fetch: async (url, options) => {
8
- const newUrl = url.toString().replace('https://api.openai.com/v1', 'https://api.helmholtz-blablador.fz-juelich.de/v1');
9
- return fetch(newUrl, options);
10
- },
11
- });
12
 
13
  export const runtime = 'edge';
14
 
15
  export async function POST(req: Request) {
16
- const { prompt, model } = await req.json();
 
 
17
 
18
  const result = await streamText({
19
- model: customOpenAI(model || 'alias-code'),
20
  messages: [
21
  {
22
  role: 'user',
@@ -26,4 +19,4 @@ export async function POST(req: Request) {
26
  });
27
 
28
  return result.toTextStreamResponse();
29
- }
 
1
  import { streamText } from 'ai';
2
+ import getProviderForModel from '@/lib/ai/provider-manager';
 
 
 
 
 
 
 
 
 
3
 
4
  export const runtime = 'edge';
5
 
6
  export async function POST(req: Request) {
7
+ const { prompt } = await req.json();
8
+
9
+ const { client, actualModel } = getProviderForModel('text');
10
 
11
  const result = await streamText({
12
+ model: client(actualModel),
13
  messages: [
14
  {
15
  role: 'user',
 
19
  });
20
 
21
  return result.toTextStreamResponse();
22
+ }