Skip to content

Commit

Permalink
feat(vector-upload): add markdown link extraction and render associat…
Browse files Browse the repository at this point in the history
…ed paper link
  • Loading branch information
mert-ergun committed Feb 16, 2025
1 parent 0a13142 commit 29deb2c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion crossbar_llm/frontend/src/components/VectorUpload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React, { useState, useEffect } from 'react';
import { Button, InputLabel, MenuItem, FormControl, Select, Typography, Box } from '@mui/material';
import { Button, InputLabel, MenuItem, FormControl, Select, Typography, Box, Link } from '@mui/material';
import axios from '../services/api';

// Helper function to extract text and URL from markdown [text](url)
const extractMarkdownLink = (markdown) => {
const match = markdown.match(/\[(.*?)\]\((.*?)\)/);
return match ? { text: match[1], url: match[2] } : { text: '', url: '' };
};

function VectorUpload({
vectorCategory,
setVectorCategory,
Expand Down Expand Up @@ -58,6 +64,20 @@ function VectorUpload({
}
};

// Determine the current paper markdown string based on selection
let currentPaperMarkdown = '';
if (vectorCategory) {
const options = nodeLabelToVectorIndexNames[vectorCategory];
if (Array.isArray(options)) {
if (embeddingType) {
currentPaperMarkdown = options.find(option => option.includes(`[${embeddingType}]`)) || '';
}
} else {
currentPaperMarkdown = options;
}
}
const { text: paperText, url: paperUrl } = extractMarkdownLink(currentPaperMarkdown);

return (
<div>
<FormControl fullWidth margin="normal">
Expand Down Expand Up @@ -97,6 +117,16 @@ function VectorUpload({
</FormControl>
)}

{/* Render professional hyperlink if a paper link is available */}
{paperText && paperUrl && (
<Typography variant="body2" sx={{ mt: 2 }}>
Read the associated paper:&nbsp;
<Link href={paperUrl} target="_blank" rel="noopener" underline="hover">
{paperText}
</Link>
</Typography>
)}

<Box sx={{ display: 'flex', gap: 2, mt: 2 }}>
<Button variant="contained" component="label" fullWidth>
Upload Vector File
Expand Down

0 comments on commit 29deb2c

Please sign in to comment.