Repository navigation
Update dependencies, add GROQ_API_KEY to env, and implement chat comp… #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd13555
Update dependencies, add GROQ_API_KEY to env, and implement chat comp…
carhartlewis 5665b6b
Merge branch 'main' into lewis/ai-chat
carhartlewis d84ee62
Remove deprecated model "llama-3.1-8b-instant" from ModelPicker compo…
carhartlewis 6452e5d
Merge branch 'lewis/ai-chat' of github.com:trycompai/comp into lewis/…
carhartlewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,33 +1,73 @@ | ||
| import { openai } from "@ai-sdk/openai"; | ||
| import { streamText } from "ai"; | ||
| import { env } from "@/env.mjs"; | ||
| import { auth } from "@/auth"; | ||
| import { model, type modelID } from "@/hooks/ai/providers"; | ||
| import { | ||
| getOrgTool, | ||
| getVendorsTool, | ||
| getPoliciesTool, | ||
| getRisksTool, | ||
| getCloudTestsTool, | ||
| getFrameworkTool, | ||
| getVendorDetailsTool, | ||
| getPolicyDetails, | ||
| } from "@/hooks/ai/tools"; | ||
| import { db } from "@bubba/db"; | ||
| import { streamText, type UIMessage } from "ai"; | ||
|
|
||
| export const maxDuration = 30; | ||
|
|
||
| export async function POST(req: Request) { | ||
| const { messages } = await req.json(); | ||
| const { | ||
| messages, | ||
| selectedModel, | ||
| }: { messages: UIMessage[]; selectedModel: modelID } = await req.json(); | ||
|
|
||
| const session = await auth(); | ||
|
|
||
| if (!env.OPENAI_API_KEY) { | ||
| return new Response( | ||
| JSON.stringify({ error: "OpenAI API key is not configured" }), | ||
| { status: 500 }, | ||
| ); | ||
| if (!session?.user.organizationId) { | ||
| return new Response("Unauthorized", { status: 401 }); | ||
| } | ||
|
|
||
| try { | ||
| const result = await streamText({ | ||
| model: openai("gpt-4o-mini"), | ||
| system: | ||
| "You are a helpful assistant. Provide concise, accurate, and helpful responses to user queries.", | ||
| messages, | ||
| }); | ||
|
|
||
| return result.toDataStreamResponse(); | ||
| } catch (error) { | ||
| console.error("Error in chat API:", error); | ||
| return new Response( | ||
| JSON.stringify({ | ||
| error: "An error occurred while processing your request", | ||
| }), | ||
| { status: 500 }, | ||
| ); | ||
| const org = await db.organization.findUnique({ | ||
| where: { | ||
| id: session.user.organizationId, | ||
| }, | ||
| }); | ||
|
|
||
| if (!org) { | ||
| return new Response("Organization not found", { status: 404 }); | ||
| } | ||
|
|
||
| const systemPrompt = ` | ||
| You are an expert in governance, risk, and compliance. | ||
|
|
||
| You're a helpful assistant in Comp AI, a platform that helps companies | ||
| get compliant with frameworks like SOC 2, ISO 27001 and GDPR - similar to Vanta and Drata. | ||
|
|
||
| You have access to various tools to help gather information. You can: | ||
| 1. Use multiple tools in sequence to gather comprehensive information | ||
| 2. Chain tool calls together to get more detailed information | ||
| 3. Use tools to verify or expand upon information from previous tool calls | ||
|
|
||
| When using tools: | ||
| - Start with broader queries to get an overview | ||
| - Then use specific queries to get detailed information | ||
| `; | ||
|
|
||
| const result = streamText({ | ||
| model: model.languageModel(selectedModel), | ||
| system: systemPrompt, | ||
| messages, | ||
| tools: { | ||
| getOrgTool, | ||
| getVendorsTool, | ||
| getPoliciesTool, | ||
| getRisksTool, | ||
| getCloudTestsTool, | ||
| getFrameworkTool, | ||
| getVendorDetailsTool, | ||
| getPolicyDetails, | ||
| }, | ||
| }); | ||
|
|
||
| return result.toDataStreamResponse({ sendReasoning: true }); | ||
| } | ||
This file contains hidden or 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,17 @@ | ||
| import { LogoSpinner } from "../logo-spinner"; | ||
|
|
||
| type Props = { | ||
| firstName: string; | ||
| }; | ||
|
|
||
| export function ChatEmpty({ firstName }: Props) { | ||
| return ( | ||
| <div className="w-full mt-[200px] todesktop:mt-24 md:mt-24 flex flex-col items-center justify-center text-center"> | ||
| <LogoSpinner raceColor="#00DC73" /> | ||
| <span className="font-medium text-xl mt-6"> | ||
| Hi {firstName}, how can I help <br /> | ||
| you today? | ||
| </span> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Extract the system prompt into a dedicated configuration.
The multi-line system prompt could be moved to a separate file or constants configuration, improving readability and maintainability—especially if it grows further or requires updates.