refactor: remove unused deepseekChat.ts in favor

of reasoningChatModel.ts and messageProcessor.ts in favor of
alternaitngMessageValidator.ts

- Removed src/lib/deepseekChat.ts as it was duplicative
- All functionality is now handled by reasoningChatModel.ts
- No imports or references to deepseekChat.ts found in codebase

- Removed src/utils/messageProcessor.ts as it was duplicative
- All functionality is now handled by alternatingMessaageValidator.ts
- No imports or references messageProcessor.ts found in codebase
This commit is contained in:
haddadrm
2025-02-28 00:02:21 +04:00
parent 18f627b1af
commit c2df5e47c9
11 changed files with 7 additions and 414 deletions

View File

@@ -12,14 +12,12 @@ interface Discover {
thumbnail: string;
}
// List of available categories
const categories = [
'For You', 'AI', 'Technology', 'Current News', 'Sports',
'Money', 'Gaming', 'Entertainment', 'Art and Culture',
'Science', 'Health', 'Travel'
];
// Memoized header component that won't re-render when content changes
const DiscoverHeader = memo(({
activeCategory,
setActiveCategory,
@@ -31,7 +29,6 @@ const DiscoverHeader = memo(({
}) => {
const categoryContainerRef = useRef<HTMLDivElement>(null);
// Function to scroll categories horizontally
const scrollCategories = (direction: 'left' | 'right') => {
const container = categoryContainerRef.current;
if (!container) return;
@@ -63,7 +60,6 @@ const DiscoverHeader = memo(({
</button>
</div>
{/* Category Navigation with Buttons */}
<div className="relative flex items-center py-4">
<button
className="absolute left-0 z-10 p-1 rounded-full bg-light-secondary dark:bg-dark-secondary hover:bg-light-primary/80 hover:dark:bg-dark-primary/80 transition-colors"
@@ -111,7 +107,6 @@ const DiscoverHeader = memo(({
DiscoverHeader.displayName = 'DiscoverHeader';
// Memoized content component that handles its own loading state
const DiscoverContent = memo(({
activeCategory,
userPreferences,
@@ -124,7 +119,6 @@ const DiscoverContent = memo(({
const [discover, setDiscover] = useState<Discover[] | null>(null);
const [contentLoading, setContentLoading] = useState(true);
// Fetch data based on active category, user preferences, and language
useEffect(() => {
const fetchData = async () => {
setContentLoading(true);
@@ -232,7 +226,6 @@ const DiscoverContent = memo(({
DiscoverContent.displayName = 'DiscoverContent';
// Preferences modal component
const PreferencesModal = memo(({
showPreferences,
setShowPreferences,
@@ -253,7 +246,6 @@ const PreferencesModal = memo(({
const [tempPreferences, setTempPreferences] = useState<string[]>([]);
const [tempLanguages, setTempLanguages] = useState<string[]>([]);
// Initialize temp preferences when modal opens
useEffect(() => {
if (showPreferences) {
setTempPreferences([...userPreferences]);
@@ -261,7 +253,6 @@ const PreferencesModal = memo(({
}
}, [showPreferences, userPreferences, preferredLanguages]);
// Save user preferences
const saveUserPreferences = async (preferences: string[], languages: string[]) => {
try {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/discover/preferences`, {
@@ -393,16 +384,13 @@ const PreferencesModal = memo(({
PreferencesModal.displayName = 'PreferencesModal';
// Main page component
const Page = () => {
// State for the entire page
const [activeCategory, setActiveCategory] = useState('For You');
const [showPreferences, setShowPreferences] = useState(false);
const [userPreferences, setUserPreferences] = useState<string[]>(['AI', 'Technology']);
const [preferredLanguages, setPreferredLanguages] = useState<string[]>(['en']); // Default to English
const [initialLoading, setInitialLoading] = useState(true);
// Load user preferences on component mount
useEffect(() => {
const loadUserPreferences = async () => {
try {
@@ -420,7 +408,6 @@ const Page = () => {
}
} catch (err: any) {
console.error('Error loading preferences:', err.message);
// Use default preferences if loading fails
} finally {
setInitialLoading(false);
}
@@ -454,21 +441,18 @@ const Page = () => {
return (
<div>
{/* Static header that doesn't re-render when content changes */}
<DiscoverHeader
activeCategory={activeCategory}
setActiveCategory={setActiveCategory}
setShowPreferences={setShowPreferences}
/>
{/* Dynamic content that updates independently */}
<DiscoverContent
activeCategory={activeCategory}
userPreferences={userPreferences}
preferredLanguages={preferredLanguages}
/>
{/* Preferences modal */}
<PreferencesModal
showPreferences={showPreferences}
setShowPreferences={setShowPreferences}

View File

@@ -35,7 +35,6 @@ const BatchDeleteChats = ({
setLoading(true);
try {
// Delete chats one by one
for (const chatId of chatIds) {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chats/${chatId}`, {
method: 'DELETE',
@@ -45,7 +44,6 @@ const BatchDeleteChats = ({
});
}
// Update local state
const newChats = chats.filter(chat => !chatIds.includes(chat.id));
setChats(newChats);

View File

@@ -39,11 +39,11 @@ const useSocket = (
const retryCountRef = useRef(0);
const isCleaningUpRef = useRef(false);
const MAX_RETRIES = 3;
const INITIAL_BACKOFF = 1000; // 1 second
const INITIAL_BACKOFF = 1000;
const isConnectionErrorRef = useRef(false);
const getBackoffDelay = (retryCount: number) => {
return Math.min(INITIAL_BACKOFF * Math.pow(2, retryCount), 10000); // Cap at 10 seconds
return Math.min(INITIAL_BACKOFF * Math.pow(2, retryCount), 10000);
};
useEffect(() => {

View File

@@ -16,15 +16,8 @@ const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: Reaso
const [isExpanded, setIsExpanded] = React.useState(true);
const [detailsRefs, setDetailsRefs] = React.useState<HTMLDetailsElement[]>([]);
logger.info('ReasoningPanel rendering with:', {
thinking: thinking,
isExpanded: propExpanded,
detailsRefsCount: detailsRefs.length
});
React.useEffect(() => {
if (propExpanded !== undefined) {
logger.info('Updating expansion state:', propExpanded);
setIsExpanded(propExpanded);
}
}, [propExpanded]);
@@ -33,7 +26,6 @@ const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: Reaso
if (element) {
setDetailsRefs(refs => {
if (!refs.includes(element)) {
logger.info('Adding new details ref');
return [...refs, element];
}
return refs;
@@ -42,11 +34,9 @@ const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: Reaso
}, []);
const expandAll = () => {
logger.info('Expanding all details');
detailsRefs.forEach(ref => ref.open = true);
};
const collapseAll = () => {
logger.info('Collapsing all details');
detailsRefs.forEach(ref => ref.open = false);
};
@@ -73,9 +63,7 @@ const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: Reaso
{thinking.split('\n\n').map((paragraph, index) => {
if (!paragraph.trim()) return null;
// Extract content without the bullet prefix
const content = paragraph.replace(/^[•\-\d.]\s*/, '');
logger.info(`Processing paragraph ${index}:`, content);
return (
<div key={index} className="mb-2 last:mb-0">
@@ -117,4 +105,4 @@ const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: Reaso
);
};
export default ReasoningPanel;
export default ReasoningPanel;

View File

@@ -47,34 +47,21 @@ const MessageBox = ({
const [isThinkingExpanded, setIsThinkingExpanded] = useState(true);
useEffect(() => {
logger.info(`Processing message:`, {
content: message.content,
role: message.role,
messageId: message.messageId
});
const regex = /\[(\d+)\]/g;
const thinkRegex = /<think>(.*?)(?:<\/think>|$)(.*)/s;
// Check for thinking content, including partial tags
const match = message.content.match(thinkRegex);
logger.info(`Think tag match:`, match);
if (match) {
const [_, thinkingContent, answerContent] = match;
// Set thinking content even if </think> hasn't appeared yet
if (thinkingContent) {
logger.info(`Found thinking content:`, thinkingContent.trim());
setThinking(thinkingContent.trim());
setIsThinkingExpanded(true); // Expand when thinking starts
setIsThinkingExpanded(true);
}
// Only set answer content if we have it (after </think>)
if (answerContent) {
logger.info(`Found answer content:`, answerContent.trim());
setIsThinkingExpanded(false); // Collapse when thinking is done
// Process the answer part for sources if needed
setIsThinkingExpanded(false);
if (message.role === 'assistant' && message?.sources && message.sources.length > 0) {
setParsedMessage(
answerContent.trim().replace(
@@ -89,7 +76,6 @@ const MessageBox = ({
setSpeechMessage(answerContent.trim().replace(regex, ''));
}
} else {
// No thinking content - process as before
if (message.role === 'assistant' && message?.sources && message.sources.length > 0) {
setParsedMessage(
message.content.replace(