Spaces:
Sleeping
Sleeping
Commit
·
132e0f4
1
Parent(s):
66e93d1
agent api
Browse files- app/api/chat/route.ts +11 -3
app/api/chat/route.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
| 8 |
ChatCompletionContentPartImage,
|
| 9 |
} from 'openai/resources';
|
| 10 |
import { MessageWithSelectedDataset } from '../../../lib/types';
|
|
|
|
| 11 |
|
| 12 |
export const runtime = 'edge';
|
| 13 |
|
|
@@ -21,14 +22,21 @@ export async function POST(req: Request) {
|
|
| 21 |
messages: MessageWithSelectedDataset[];
|
| 22 |
};
|
| 23 |
|
| 24 |
-
const
|
| 25 |
-
|
| 26 |
-
if (!userId) {
|
| 27 |
return new Response('Unauthorized', {
|
| 28 |
status: 401,
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
const formattedMessage: ChatCompletionMessageParam[] = messages.map(
|
| 33 |
message => {
|
| 34 |
const { dataset, ...rest } = message;
|
|
|
|
| 8 |
ChatCompletionContentPartImage,
|
| 9 |
} from 'openai/resources';
|
| 10 |
import { MessageWithSelectedDataset } from '../../../lib/types';
|
| 11 |
+
import { postAgentChat } from '@/lib/fetch';
|
| 12 |
|
| 13 |
export const runtime = 'edge';
|
| 14 |
|
|
|
|
| 22 |
messages: MessageWithSelectedDataset[];
|
| 23 |
};
|
| 24 |
|
| 25 |
+
const session = await auth();
|
| 26 |
+
if (!session?.user?.email) {
|
|
|
|
| 27 |
return new Response('Unauthorized', {
|
| 28 |
status: 401,
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
| 32 |
+
// const lastMessage = messages[messages.length - 1];
|
| 33 |
+
// const firstMessage = messages[0];
|
| 34 |
+
|
| 35 |
+
// const resp = await postAgentChat({
|
| 36 |
+
// input: lastMessage.content,
|
| 37 |
+
// image: firstMessage.dataset?.[0]?.url,
|
| 38 |
+
// });
|
| 39 |
+
|
| 40 |
const formattedMessage: ChatCompletionMessageParam[] = messages.map(
|
| 41 |
message => {
|
| 42 |
const { dataset, ...rest } = message;
|