import React, { useState, useEffect } from "react"; import './App.css'; import ChatBox from './ChatBox'; import axios from 'axios'; import { getHost } from '../../helpers/getHost'; interface ChatBoxSettings { report_source: string; report_type: string; tone: string; } interface ChatBoxProps { chatBoxSettings: ChatBoxSettings; setChatBoxSettings: React.Dispatch>; } export default function Modal({ setChatBoxSettings, chatBoxSettings }: ChatBoxProps) { const [showModal, setShowModal] = useState(false); const [activeTab, setActiveTab] = useState('search'); const [apiVariables, setApiVariables] = useState({ ANTHROPIC_API_KEY: '', TAVILY_API_KEY: '', LANGCHAIN_TRACING_V2: 'true', LANGCHAIN_API_KEY: '', OPENAI_API_KEY: '', DOC_PATH: './my-docs', RETRIEVER: 'tavily', // Set default retriever to Tavily GOOGLE_API_KEY: '', GOOGLE_CX_KEY: '', BING_API_KEY: '', SEARCHAPI_API_KEY: '', SERPAPI_API_KEY: '', SERPER_API_KEY: '', SEARX_URL: '', LANGGRAPH_HOST_URL: '' }); useEffect(() => { const storedConfig = localStorage.getItem('apiVariables'); if (storedConfig) { setApiVariables(JSON.parse(storedConfig)); } else { axios.get(`${getHost()}/getConfig`) .then(response => { setApiVariables(response.data); localStorage.setItem('apiVariables', JSON.stringify(response.data)); }) .catch(error => { console.error('Error fetching config:', error); }); } }, [showModal]); const handleSaveChanges = () => { setChatBoxSettings(chatBoxSettings); localStorage.setItem('apiVariables', JSON.stringify(apiVariables)); setShowModal(false); }; const handleInputChange = (e: { target: { name: any; value: any; }; }) => { const { name, value } = e.target; setApiVariables(prevState => ({ ...prevState, [name]: value })); localStorage.setItem('apiVariables', JSON.stringify({ ...apiVariables, [name]: value })); }; const renderConditionalInputs = () => { switch (apiVariables.RETRIEVER) { case 'google': return ( <>
); case 'bing': return (
); case 'searchapi': return (
); case 'serpapi': return (
); case 'googleSerp': return (
); case 'searx': return (
); // Add cases for other retrievers if needed default: return null; } }; return (
{showModal ? ( <>
{activeTab === 'search' && (
)} {activeTab === 'api' && (
{renderConditionalInputs()}
{apiVariables.LANGCHAIN_API_KEY && ( <>
)}
)}
) : null}
); }