Skip to content

Devt 30 main autogenerate loop #66

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ NEXT_PUBLIC_HOSTED_DOMAIN="nyu.edu"

SUPABASE_SERVICE_ROLE_KEY=<SUBSTITUTE_SUPABASE_SERVICE_ROLE_KEY>
RAGFLOW_API_KEY=<API_KEY>
RAGFLOW_API_URL=<RAGFLOW_API_URL>
RAGFLOW_API_URL=<RAGFLOW_API_URL>
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"plugins": ["prettier-plugin-tailwindcss"]
"plugins": ["prettier-plugin-tailwindcss"],
"endOfLine": "auto"
}
2 changes: 1 addition & 1 deletion .tekton/events/trigger_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
params:
- name: git-repo-url
value: $(body.repository.url)
value: $(body.repository.clone_url)
- name: git-repo-name
value: $(body.repository.name)
- name: git-revision
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"cSpell.words": [
"bitnami",
"Chatrooms",
"pipelinerun",
"Ragflow",
"Sonner",
"supabase",
"taskrun",
"tekton",
Expand Down
8 changes: 3 additions & 5 deletions app/auth/callback/route.ts → app/api/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";
import { createClient } from "@shared/utils/supabase/server";

export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
Expand All @@ -8,10 +8,8 @@ export async function GET(request: Request) {
const next = searchParams.get("next") ?? "/";

const error = searchParams.get("error_description");
if (error && error === "Database error saving new user") {
return NextResponse.redirect(
`${origin}/auth/unauthorized?message=ORGANIZATION_EMAIL_REQUIRED`
);
if (error) {
return NextResponse.redirect(`${origin}/error/unauthorized`);
}

if (code) {
Expand Down
19 changes: 3 additions & 16 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type NextRequest } from "next/server";

const API_URL = process.env.RAGFLOW_API_URL + "/api" || "";
const API_URL = `${process.env.RAGFLOW_API_URL}/api` || "";
const API_KEY = process.env.RAGFLOW_API_KEY;

export async function GET(request: NextRequest) {
Expand All @@ -17,7 +17,6 @@ export async function GET(request: NextRequest) {
"Content-Type": "application/json",
},
});
// const resJson = await res.json();
return Response.json({ success: 200 });
case "delete_sessions":
await fetch(`${API_URL}/v1/chats/${assistant}/sessions`, {
Expand Down Expand Up @@ -49,19 +48,7 @@ export async function GET(request: NextRequest) {
}
);
return Response.json((await sessions.json()).data);
default:
return Response.json({ error: "Invalid method" }, { status: 400 });
}

// const res = await fetch(
// `${API_URL}/v1/chats/`,
// {
// method: "DELETE",
// headers: {
// Authorization: `Bearer ${API_KEY}`,
// "Content-Type": "application/json",
// },
// }
// );
// const resJson = await res.json();

// return Response.json(resJson.data);
}
40 changes: 0 additions & 40 deletions app/api/document/[datasetId]/[documentId]/route.ts

This file was deleted.

36 changes: 36 additions & 0 deletions app/chat/[classroomId]/AutogenerateButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use client";
import { useTransition } from "react";
import { autogenerateMaterial } from "./actions";

type AutogenerateButtonProps = {
classroomId: number;
};

export default function AutogenerateButton({
classroomId,
}: AutogenerateButtonProps) {
const [isPending, startTransition] = useTransition();

async function handleClick() {
startTransition(async () => {
try {
const result = await autogenerateMaterial(classroomId);
console.log("Generated material:", result);
// After autogeneration, reload the page to update generated content.
window.location.reload();
} catch (error) {
console.error("Error during autogeneration:", error);
}
});
}

return (
<button
onClick={handleClick}
disabled={isPending}
className="rounded bg-blue-500 px-4 py-2 text-white"
>
{isPending ? "Generating..." : "Autogenerate Material"}
</button>
);
}
146 changes: 146 additions & 0 deletions app/chat/[classroomId]/GeneratedMaterialsSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
"use client";

import { useState, useEffect } from "react";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogClose,
} from "@/shared/components/ui/dialog"; // adjust path per your project

type Session = {
id: string;
name: string;
messages: { role: string; content: string }[];
};

interface GeneratedMaterialsSidebarProps {
assistantId: string;
realUserId: string;
}

export default function GeneratedMaterialsSidebar({
assistantId,
}: GeneratedMaterialsSidebarProps) {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const [sessions, setSessions] = useState<Session[]>([]);
const [selectedSession, setSelectedSession] = useState<Session | null>(null);

useEffect(() => {
async function fetchSessions() {
try {
// Use your existing API route to get sessions.
const res = await fetch(
`/api/chat?method=get_sessions&id=${assistantId}`
);
if (!res.ok) {
const errorText = await res.text();
throw new Error(
`Failed to fetch sessions: ${res.status} ${errorText}`
);
}
const data = await res.json();
setSessions(data);
} catch (error) {
console.error("Error fetching sessions:", error);
}
}
if (isSidebarOpen) {
fetchSessions();
}
}, [isSidebarOpen, assistantId]);

return (
<>
{/* Toggle the sidebar on button click */}
<button
onClick={() => setIsSidebarOpen((prev) => !prev)}
className="fixed right-4 top-4 z-50 rounded bg-blue-500 px-4 py-2 text-white"
>
Sessions
</button>

{/* Sidebar Panel – always rendered for animation */}
<div
className={`fixed right-0 top-0 z-40 h-full w-80 transform overflow-y-auto bg-white p-4 shadow-xl transition-transform duration-300 ${
isSidebarOpen ? "translate-x-0" : "translate-x-full"
}`}
>
<div className="mb-4 flex items-center justify-between">
<h2 className="text-lg font-bold">Chat Sessions</h2>
<button
onClick={() => setIsSidebarOpen(false)}
className="text-red-500"
>
Close
</button>
</div>
{sessions.length === 0 ? (
<p>No sessions found.</p>
) : (
<div>
{/* Wrap the ul in a div to avoid nesting error */}
<div>
<ul className="space-y-2">
{sessions.map((session) => (
<li key={session.id}>
<button
onClick={() => setSelectedSession(session)}
className="w-full text-left text-blue-600 underline"
>
{session.name || session.id}
</button>
</li>
))}
</ul>
</div>
</div>
)}
</div>

{/* Modal for Session Details – slide in from the right */}
<Dialog
open={!!selectedSession}
onOpenChange={() => setSelectedSession(null)}
>
<div
className={`fixed inset-0 flex transform items-center justify-center transition-transform duration-300 ${
selectedSession ? "translate-x-0" : "translate-x-full"
}`}
>
<DialogContent className="max-h-[80vh] max-w-md overflow-y-auto">
<DialogHeader>
<DialogTitle>
{selectedSession?.name || "Session Details"}
</DialogTitle>
<DialogDescription>
{selectedSession?.messages.length ? (
<div>
<ul className="space-y-2">
{selectedSession.messages.map((msg, index) => (
<li key={index} className="rounded border p-2">
<strong>{msg.role}:</strong> {msg.content}
</li>
))}
</ul>
</div>
) : (
<p>No messages in this session.</p>
)}
</DialogDescription>
</DialogHeader>
<div className="mt-4">
<DialogClose asChild>
<button className="rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600">
Close
</button>
</DialogClose>
</div>
</DialogContent>
</div>
</Dialog>
</>
);
}
Loading
Loading