-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from Technoculture/storm
Article Generation
- Loading branch information
Showing
13 changed files
with
244 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import axios from "axios"; | ||
import { env } from "@/app/env.mjs"; | ||
import { saveToDB } from "@/utils/apiHelper"; | ||
import { auth } from "@clerk/nextjs"; | ||
import { nanoid } from "ai"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const POST = async (request: NextRequest) => { | ||
const url = request.url; | ||
const urlArray = url.split("/"); | ||
const { orgSlug } = auth(); | ||
const body = await request.json(); | ||
|
||
const response = await axios.post( | ||
`${env.KEYCLOAK_BASE_URL}/realms/${env.KEYCLOAK_REALM}/protocol/openid-connect/token`, | ||
new URLSearchParams({ | ||
client_id: env.KEYCLOAK_CLIENT_ID, | ||
client_secret: env.KEYCLOAK_CLIENT_SECRET, | ||
grant_type: "client_credentials", | ||
}), | ||
{ | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}, | ||
); | ||
const accessToken = response.data.access_token; | ||
|
||
const stormResponse = await axios.post( | ||
`${env.STORM_ENDPOINT}`, | ||
{ | ||
topic: body.topic, | ||
search_top_k: 5, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}, | ||
); | ||
|
||
const chatId = body.chatId; | ||
const orgId = body.orgId; | ||
const userId = body.userId; | ||
const latestResponse = { | ||
id: nanoid(), | ||
role: "assistant" as const, | ||
content: stormResponse?.data?.content, | ||
createdAt: new Date(), | ||
audio: "", | ||
}; | ||
|
||
await saveToDB({ | ||
_chat: [], | ||
chatId: Number(chatId), | ||
orgSlug: orgSlug as string, | ||
latestResponse: latestResponse, | ||
userId: userId, | ||
orgId: orgId, | ||
urlArray: urlArray, | ||
}); | ||
return NextResponse.json({ | ||
data: stormResponse.data, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.