Commit f65e8af9 authored by Kantz's avatar Kantz
Browse files

cleanup

parent f1184f7f
......@@ -6,6 +6,8 @@ venv/
.env-gwdg
.env-stochastik
__pycache__/
*.pyc
drawings/
backend/app/storage/
sources/
logs/
......@@ -13,7 +13,3 @@ pgvector
pyyaml
sentence-transformers
transformers==4.57.6
torch
peft
torchvision
export type OrchestratorName = "qa" | "tutor" | "task" | "socratic";
import {
DEFAULT_ORCHESTRATOR,
FALLBACK_ORCHESTRATORS,
normalizeOrchestrator,
type OrchestratorName,
} from "../utils/orchestrator";
export type OrchestratorConfigResponse = {
default_orchestrator: OrchestratorName;
available_orchestrators: OrchestratorName[];
};
const FALLBACK_ORCHESTRATORS: OrchestratorName[] = ["qa", "tutor", "task", "socratic"];
const normalizeOrchestrator = (value: string): OrchestratorName | null => {
if (
value === "qa" ||
value === "tutor" ||
value === "task" ||
value === "socratic"
) {
return value;
}
return null;
};
export const getFallbackOrchestrators = (): OrchestratorName[] =>
[...FALLBACK_ORCHESTRATORS];
......@@ -30,7 +21,7 @@ export async function fetchOrchestratorConfig(): Promise<OrchestratorConfigRespo
const payload = await response.json();
const defaultOrchestrator =
normalizeOrchestrator(String(payload?.default_orchestrator || "")) || "qa";
normalizeOrchestrator(String(payload?.default_orchestrator || "")) || DEFAULT_ORCHESTRATOR;
const availableRaw = Array.isArray(payload?.available_orchestrators)
? payload.available_orchestrators
: [];
......
import { useId } from "react";
import type { OrchestratorName } from "../../api/orchestratorApi";
import type { OrchestratorName } from "../../utils/orchestrator";
import { t } from "../../i18n";
type OrchestratorSelectProps = {
......
......@@ -4,7 +4,7 @@ import ChatPage from "./ChatPage";
import SocraticSelectionPage from "./SocraticSelectionPage";
import TaskSelectionPage from "./TaskSelectionPage";
import { TutorSessionProvider, useTutorSession } from "../state/tutorSession";
import { getSelectionRouteForOrchestrator } from "../utils/orchestratorRoutes";
import { getSelectionRouteForOrchestrator } from "../utils/orchestrator";
function StartRoute() {
const { isTasksInitialized, selectedOrchestrator } = useTutorSession();
......
......@@ -9,31 +9,20 @@ import SocraticPanel from "../components/Task/SocraticPanel";
import TaskPanel from "../components/Task/TaskPanel";
import type { ChatMessage } from "../components/Chat/MessageList";
import type { RetrievedDoc } from "../components/Retrieval/DocPanel";
import type { OrchestratorName } from "../api/orchestratorApi";
import { selectTask, selectTopic } from "../api/taskApi";
import { t } from "../i18n";
import { createSessionId, useTutorSession } from "../state/tutorSession";
import { getSelectionRouteForOrchestrator, isSocraticOrchestrator } from "../utils/orchestratorRoutes";
import {
getSelectionRouteForOrchestrator,
isTaskCoupledOrchestrator,
normalizeOrchestrator,
type OrchestratorName,
} from "../utils/orchestrator";
import { normalizeTopicKey as normalizeTopicKey } from "../utils/topicKey";
import sumintLogo from "../../SuMINT-Logo.png";
const initialMessages: ChatMessage[] = [];
const normalizeOrchestrator = (value: string | null | undefined): OrchestratorName | null => {
if (
value === "qa" ||
value === "tutor" ||
value === "task" ||
value === "socratic"
) {
return value;
}
return null;
};
const isTaskCoupledOrchestrator = (value: string | null | undefined): boolean =>
value === "task";
type ArchivedChatSummary = {
chat_id: string;
saved_at: string;
......@@ -236,9 +225,10 @@ export default function ChatPage() {
const socraticBootstrapRef = useRef<string>("");
const deepLinkTarget = useMemo(() => {
const orchestrator = String(searchParams.get("orchestrator") || "")
const orchestratorValue = String(searchParams.get("orchestrator") || "")
.trim()
.toLowerCase();
const orchestrator = normalizeOrchestrator(orchestratorValue);
const fileId = String(searchParams.get("file_id") || "").trim();
const rawTaskId = String(searchParams.get("task_id") || "").trim();
const rawTopicKey = String(
......@@ -252,12 +242,12 @@ export default function ChatPage() {
const hasFileId = Boolean(fileId);
const hasTaskId = Boolean(taskId);
const hasTopicKey = Boolean(topicKey);
const isTaskOrchestrator = isTaskCoupledOrchestrator(orchestrator);
const isSocratic = isSocraticOrchestrator(orchestrator as OrchestratorName);
const isTaskOrchestrator = orchestrator === "task";
const isSocratic = orchestrator === "socratic";
const hasAnyTaskParam = hasFileId || hasTaskId || hasTopicKey;
const hasRequiredTaskParams = hasFileId && hasTaskId;
const hasRequiredTopicParams = hasTopicKey;
const key = `${orchestrator}|${fileId}|${taskId}|${topicKey}`;
const key = `${orchestratorValue}|${fileId}|${taskId}|${topicKey}`;
return {
fileId,
......
import { useEffect, useMemo, useRef } from "react";
import { useNavigate } from "react-router-dom";
import type { OrchestratorName } from "../api/orchestratorApi";
import { selectTopic } from "../api/taskApi";
import OrchestratorSelect from "../components/Orchestrator/OrchestratorSelect";
import { t } from "../i18n";
import { useTutorSession } from "../state/tutorSession";
import { getSelectionRouteForOrchestrator } from "../utils/orchestratorRoutes";
import {
getSelectionRouteForOrchestrator,
type OrchestratorName,
} from "../utils/orchestrator";
import "../styles/theme.css";
import sumintLogo from "../../SuMINT-Logo.png";
......
import { useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import type { OrchestratorName } from "../api/orchestratorApi";
import OrchestratorSelect from "../components/Orchestrator/OrchestratorSelect";
import TaskContent from "../components/Task/TaskContent";
import { selectTask } from "../api/taskApi";
import { t } from "../i18n";
import { useTutorSession } from "../state/tutorSession";
import { getSelectionRouteForOrchestrator } from "../utils/orchestratorRoutes";
import {
getSelectionRouteForOrchestrator,
type OrchestratorName,
} from "../utils/orchestrator";
import "../styles/theme.css";
import sumintLogo from "../../SuMINT-Logo.png";
......
......@@ -13,8 +13,12 @@ import { t } from "../i18n";
import {
fetchOrchestratorConfig,
getFallbackOrchestrators,
type OrchestratorName,
} from "../api/orchestratorApi";
import {
DEFAULT_ORCHESTRATOR,
isTaskCoupledOrchestrator,
type OrchestratorName,
} from "../utils/orchestrator";
import {
fetchTaskDetails,
fetchSocraticTopics,
......@@ -93,16 +97,13 @@ export const getDefaultTaskId = (tasks: Array<{ task_id: string }>): string =>
const isSelectableTaskFile = (file: TaskFile): boolean =>
Array.isArray(file.tasks) && file.tasks.length > 0;
const isTaskCoupledOrchestrator = (value: OrchestratorName): boolean =>
value === "task" || value === "socratic";
const formatTopicRefs = (refs: [number, number, number, number][]): string =>
refs.map((ref) => ref.join(":")).join(", ");
export function TutorSessionProvider({ children }: PropsWithChildren) {
const [chatSessionId, setChatSessionId] = useState<string>(() => createSessionId());
const [selectedOrchestrator, setSelectedOrchestratorState] =
useState<OrchestratorName>("qa");
useState<OrchestratorName>(DEFAULT_ORCHESTRATOR);
const [availableOrchestrators, setAvailableOrchestrators] = useState<OrchestratorName[]>(
() => getFallbackOrchestrators()
);
......
export const ORCHESTRATORS = ["qa", "tutor", "task", "socratic"] as const;
export type OrchestratorName = (typeof ORCHESTRATORS)[number];
export const DEFAULT_ORCHESTRATOR: OrchestratorName = "qa";
export const FALLBACK_ORCHESTRATORS: OrchestratorName[] = [...ORCHESTRATORS];
export const normalizeOrchestrator = (
value: string | null | undefined
): OrchestratorName | null => {
if (typeof value !== "string") {
return null;
}
return ORCHESTRATORS.find((item) => item === value) ?? null;
};
export const isSocraticOrchestrator = (value: OrchestratorName): boolean =>
value === "socratic";
export const isTaskSelectionOrchestrator = (value: OrchestratorName): boolean =>
value === "task";
export const isTaskCoupledOrchestrator = (value: OrchestratorName): boolean =>
value === "task" || value === "socratic";
export const getSelectionRouteForOrchestrator = (value: OrchestratorName): string => {
if (value === "socratic") {
return "/select-socratic";
}
if (value === "task") {
return "/select-task";
}
return "/chat";
};
import type { OrchestratorName } from "../api/orchestratorApi";
export const isTaskSelectionOrchestrator = (value: OrchestratorName): boolean =>
value === "task";
export const isSocraticOrchestrator = (value: OrchestratorName): boolean =>
value === "socratic";
export const getSelectionRouteForOrchestrator = (value: OrchestratorName): string => {
if (value === "socratic") {
return "/select-socratic";
}
if (value === "task") {
return "/select-task";
}
return "/chat";
};
export {
getSelectionRouteForOrchestrator,
isSocraticOrchestrator,
isTaskSelectionOrchestrator,
type OrchestratorName,
} from "./orchestrator";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment