Virsical AI Analysis is a React-based AI analysis component library that provides intelligent analysis dialog and analysis button components that can be easily integrated into your React applications. This component library supports Markdown rendering, streaming responses, copying analysis results, and other features to provide users with a smooth AI analysis experience.
- Node.js 14.x or higher
- React 16.14.0 or higher
- Supports pnpm, npm, or yarn package managers
- Install dependencies using pnpm (recommended):
pnpm install virsical-ai-report-analysis
Or using npm:
npm install virsical-ai-report-analysis
Or using yarn:
yarn add virsical-ai-report-analysis
- Import components in your project:
import AITool from 'virsical-ai-report-analysis';
const { Analysis, BtnAnalysis } = AITool;
Use the following commands to start the development environment:
# Using pnpm (recommended)
pnpm start:legacy
# Or using standard mode
pnpm start
Use the following commands to build the project:
# Using pnpm (recommended)
pnpm build:legacy
# Or using standard mode
pnpm build
pnpm test
BtnAnalysis is a button component that triggers AI analysis.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
handleClick | Function | Yes | - | Callback function when the button is clicked |
className | String | No | - | Custom style class name |
style | Object | No | - | Custom inline style |
import React, { useState } from 'react';
import AITool from 'virsical-ai-report-analysis';
const { BtnAnalysis } = AITool;
function MyComponent() {
const [analysisVisible, setAnalysisVisible] = useState(false);
const [analysisQuestion, setAnalysisQuestion] = useState('');
return (
<div>
<BtnAnalysis
handleClick={() => {
setAnalysisVisible(true);
setAnalysisQuestion('Please analyze the key information in this text');
}}
/>
</div>
);
}
Analysis is an AI analysis dialog component used to display AI analysis results.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
visible | Boolean | Yes | - | Controls the display and hiding of the dialog |
analysisQuestion | String | Yes | - | Question or text to be analyzed |
handleVisible | Function | Yes | - | Callback function to control the dialog display status |
Authorization | String | Yes | - | Authentication information, format is "bearer {token}" |
requestUrl | String | Yes | - | Request address for the AI analysis service |
signatureKey | String | No | - | Signature key (if signature verification is required) |
restfulSignature | Boolean | No | false | Whether to use RESTful signature |
className | String | No | - | Custom style class name |
style | Object | No | - | Custom inline style |
payload | Object | No | {} | Additional request parameters |
import React, { useState } from 'react';
import AITool from 'virsical-ai-report-analysis';
const { Analysis, BtnAnalysis } = AITool;
function MyComponent() {
const [analysisVisible, setAnalysisVisible] = useState(false);
const [analysisQuestion, setAnalysisQuestion] = useState('');
return (
<div>
<BtnAnalysis
handleClick={() => {
setAnalysisVisible(true);
setAnalysisQuestion('Please analyze the key information in this text');
}}
/>
{analysisVisible && (
<Analysis
visible={analysisVisible}
analysisQuestion={analysisQuestion}
handleVisible={() => setAnalysisVisible(false)}
Authorization="bearer YOUR_TOKEN_HERE"
requestUrl="https://your-api-endpoint.com/ai/analysis"
signatureKey="YOUR_SIGNATURE_KEY"
restfulSignature={true}
/>
)}
</div>
);
}
Here is a complete usage example:
import React, { useState } from 'react';
import AITool from 'virsical-ai-report-analysis';
const { Analysis, BtnAnalysis } = AITool;
function AIAnalysisDemo() {
const [analysisVisible, setAnalysisVisible] = useState(false);
const [analysisQuestion, setAnalysisQuestion] = useState('');
return (
<div>
<h1>AI Analysis Example</h1>
<BtnAnalysis
handleClick={() => {
setAnalysisVisible(true);
setAnalysisQuestion('Biography of Li Bai');
}}
/>
{analysisVisible && (
<Analysis
visible={analysisVisible}
analysisQuestion={analysisQuestion}
handleVisible={() => setAnalysisVisible(false)}
Authorization="bearer YOUR_TOKEN_HERE"
requestUrl="https://your-api-endpoint.com/ai/analysis"
signatureKey="YOUR_SIGNATURE_KEY"
restfulSignature={true}
payload={{
// You can add additional request parameters
language: 'en-US',
maxTokens: 1000
}}
/>
)}
</div>
);
}
export default AIAnalysisDemo;
- Markdown Rendering: Supports AI responses in Markdown format, including tables, code blocks, etc.
- Streaming Response: Real-time display of AI analysis results with typewriter effect.
- Copy Function: One-click copying of analysis results.
- Custom Styling: Support for customizing component styles through className and style attributes.
- Responsive Design: Adapts to different screen sizes.
- Please ensure you have valid API authentication information (Authorization) before use.
- The request URL needs to support streaming response format.
- If you encounter cross-origin issues, please ensure your API server has the correct CORS policy configured.
- The component handles error cases internally, but it is recommended to add additional error handling logic in production environments.
A: Please ensure the Authorization format is correct, usually "bearer {token}". Check if the token has expired or if the permissions are sufficient.
A: You can customize the style through className and style attributes, or modify CSS files in your project to override the default styles.
A: The component uses react-markdown and the remark-gfm plugin, supporting standard Markdown syntax and GitHub Flavored Markdown extensions, including tables, task lists, strikethrough, etc.
If you have any questions or suggestions, please contact: wenbei@wafersystems.com