feat: add tiptap table extension

This commit is contained in:
Jiang Feng 2025-04-27 10:39:02 +08:00
parent d77d3484c4
commit 741e2f0e62
10 changed files with 154 additions and 43 deletions

View File

@ -11,20 +11,20 @@ from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You are an AI writing assistant that continues existing text based on context from prior text.
- Give more weight/priority to the later characters than the beginning ones.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate
"""
def prose_continue_node(state: ProseState):
logger.info("Generating prose continue content...")
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You are an AI writing assistant that continues existing text based on context from prior text.
- Give more weight/priority to the later characters than the beginning ones.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate
"""
),
SystemMessage(content=prompt),
HumanMessage(content=state["content"]),
],
)

View File

@ -11,20 +11,20 @@ from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You are an AI writing assistant that fixes grammar and spelling errors in existing text.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate.
- If the text is already correct, just return the original text.
"""
def prose_fix_node(state: ProseState):
logger.info("Generating prose fix content...")
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You are an AI writing assistant that fixes grammar and spelling errors in existing text.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate.
- If the text is already correct, just return the original text.
"""
),
SystemMessage(content=prompt),
HumanMessage(content=f"The existing text is: {state['content']}"),
],
)

View File

@ -11,19 +11,19 @@ from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You are an AI writing assistant that improves existing text.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate.
"""
def prose_improve_node(state: ProseState):
logger.info("Generating prose improve content...")
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You are an AI writing assistant that improves existing text.
- Limit your response to no more than 200 characters, but make sure to construct complete sentences.
- Use Markdown formatting when appropriate.
"""
),
SystemMessage(content=prompt),
HumanMessage(content=f"The existing text is: {state['content']}"),
],
)

View File

@ -11,18 +11,18 @@ from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You are an AI writing assistant that lengthens existing text.
- Use Markdown formatting when appropriate.
"""
def prose_longer_node(state: ProseState):
logger.info("Generating prose longer content...")
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You are an AI writing assistant that lengthens existing text.
- Use Markdown formatting when appropriate.
"""
),
SystemMessage(content=prompt),
HumanMessage(content=f"The existing text is: {state['content']}"),
],
)

View File

@ -10,6 +10,10 @@ from src.llms.llm import get_llm_by_type
from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You are an AI writing assistant that shortens existing text.
- Use Markdown formatting when appropriate.
"""
def prose_shorter_node(state: ProseState):
@ -17,12 +21,7 @@ def prose_shorter_node(state: ProseState):
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You are an AI writing assistant that shortens existing text.
- Use Markdown formatting when appropriate.
"""
),
SystemMessage(content=prompt),
HumanMessage(content=f"The existing text is: {state['content']}"),
],
)

View File

@ -10,6 +10,11 @@ from src.llms.llm import get_llm_by_type
from src.prose.graph.state import ProseState
logger = logging.getLogger(__name__)
prompt = """
You area an AI writing assistant that generates text based on a prompt.
- You take an input from the user and a command for manipulating the text."
- Use Markdown formatting when appropriate.
"""
def prose_zap_node(state: ProseState):
@ -17,13 +22,7 @@ def prose_zap_node(state: ProseState):
model = get_llm_by_type(AGENT_LLM_MAP["prose_writer"])
prose_content = model.invoke(
[
SystemMessage(
content="""
You area an AI writing assistant that generates text based on a prompt.
- You take an input from the user and a command for manipulating the text."
- Use Markdown formatting when appropriate.
"""
),
SystemMessage(content=prompt),
HumanMessage(
content=f"For this text: {state['content']}.\nYou have to respect the command: {state['command']}"
),

View File

@ -37,6 +37,10 @@
"@radix-ui/react-tooltip": "^1.2.0",
"@t3-oss/env-nextjs": "^0.11.0",
"@tailwindcss/typography": "^0.5.16",
"@tiptap/extension-table": "^2.11.7",
"@tiptap/extension-table-cell": "^2.11.7",
"@tiptap/extension-table-header": "^2.11.7",
"@tiptap/extension-table-row": "^2.11.7",
"@tiptap/react": "^2.11.7",
"best-effort-json-parser": "^1.1.3",
"class-variance-authority": "^0.7.1",

50
web/pnpm-lock.yaml generated
View File

@ -68,6 +68,18 @@ importers:
'@tailwindcss/typography':
specifier: ^0.5.16
version: 0.5.16(tailwindcss@4.1.4)
'@tiptap/extension-table':
specifier: ^2.11.7
version: 2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))(@tiptap/pm@2.11.7)
'@tiptap/extension-table-cell':
specifier: ^2.11.7
version: 2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))
'@tiptap/extension-table-header':
specifier: ^2.11.7
version: 2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))
'@tiptap/extension-table-row':
specifier: ^2.11.7
version: 2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))
'@tiptap/react':
specifier: ^2.11.7
version: 2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))(@tiptap/pm@2.11.7)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
@ -1468,6 +1480,27 @@ packages:
peerDependencies:
'@tiptap/core': ^2.7.0
'@tiptap/extension-table-cell@2.11.7':
resolution: {integrity: sha512-JMOkSYRckc5SJP86yGGiHzCxCR8ecrRENvTWAKib6qer2tutxs5u42W+Z8uTcHC2dRz7Fv54snOkDoqPwkf6cw==}
peerDependencies:
'@tiptap/core': ^2.7.0
'@tiptap/extension-table-header@2.11.7':
resolution: {integrity: sha512-wPRKpliS5QQXgsp//ZjXrHMdLICMkjg2fUrQinOiBa7wDL5C7Y+SehtuK4s2tjeAkyAdj+nepfftyBRIlUSMXg==}
peerDependencies:
'@tiptap/core': ^2.7.0
'@tiptap/extension-table-row@2.11.7':
resolution: {integrity: sha512-K254RiXWGXGjz5Cm835hqfQiwnYXm8aw6oOa3isDh4A1B+1Ev4DB2vEDKMrgaOor3nbTsSYmAx2iEMrZSbpaRg==}
peerDependencies:
'@tiptap/core': ^2.7.0
'@tiptap/extension-table@2.11.7':
resolution: {integrity: sha512-rfwWkNXz/EZuhc8lylsCWPbx0Xr5FlIhreWFyeoXYrDEO3x4ytYcVOpNmbabJYP2semfM0PvPR5o84zfFkLZyg==}
peerDependencies:
'@tiptap/core': ^2.7.0
'@tiptap/pm': ^2.7.0
'@tiptap/extension-task-item@2.11.7':
resolution: {integrity: sha512-m+UyE85nnqhQ4epLMYqdwaQj6DoqGGUNE0gyJOtJB1qhBi7GM7yPEDoiX82ByaQetWjoZIduRuQSRfgkD0MEeA==}
peerDependencies:
@ -5168,6 +5201,23 @@ snapshots:
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)
'@tiptap/extension-table-cell@2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))':
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)
'@tiptap/extension-table-header@2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))':
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)
'@tiptap/extension-table-row@2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))':
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)
'@tiptap/extension-table@2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))(@tiptap/pm@2.11.7)':
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)
'@tiptap/pm': 2.11.7
'@tiptap/extension-task-item@2.11.7(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))(@tiptap/pm@2.11.7)':
dependencies:
'@tiptap/core': 2.11.7(@tiptap/pm@2.11.7)

View File

@ -1,10 +1,56 @@
import ReportEditor from "~/components/editor";
const content = `
# How Many Times Faster is the Speed of Light Compared to the Speed of Sound?
## Key Points
- The speed of light in a vacuum is about 300,000 kilometers per second, while its speed in media like water, glass, and diamond is lower.
- The speed of sound varies greatly depending on the medium. In air, it ranges from 331 m/s at 0 °C to 346.1 m/s at 25 °C, and is much higher in water and solids.
- Calculations show the speed of light is 874030.49 times faster than the speed of sound in air.
- It is 202289.11 times faster than the speed of sound in water.
- And 50300.75 times faster than the speed of sound in steel.
## Overview
This research focuses on determining how many times faster the speed of light is compared to the speed of sound. The speed of light and sound are fundamental physical quantities, and understanding their relationship can provide insights into various natural phenomena and technological applications. The speed of light is known to be extremely fast, but the exact multiple compared to the speed of sound, which varies depending on the medium, is what this study aims to uncover.
## Detailed Analysis
### Speed of Light
- **In a Vacuum**: The speed of light in a vacuum is precisely defined as 299,792.458 kilometers per second, often approximated as 300,000 kilometers per second for scientific calculations.
- **In Other Media**:
- In water (refractive index of 1.3), light slows down to about 225,000 kilometers per second.
- In glass (refractive index of 1.5), its speed is approximately 200,000 kilometers per second.
- In diamond (refractive index of 2.4), the speed of light is reduced to 125,000 kilometers per second.
### Speed of Sound
- **In Air**:
- At 0 °C and sea - level, the speed of sound in dry air is about 331 m/s.
- At 20 °C, it is about 343 m/s.
- At 25 °C, it is about 346.1 m/s.
- **In Water**:
- In fresh water at 20 °C, sound travels at about 1481 m/s.
- In salt water under specific conditions (1000 kilopascals, 10 °C and 3% salinity), it travels at about 1500 m/s.
- **In Other Media**:
- In iron, sound travels at 5120 m/s.
- In diamond, sound travels at 12,000 m/s.
### Comparison of Speeds
| Medium | Speed of Light (m/s) | Speed of Sound (m/s) | Multiple (Light/Sound) |
| ---- | ---- | ---- | ---- |
| Air | 299792458 | 343 (at 20 °C) | 874030.49 |
| Water | 299792458 | 1481 (fresh water at 20 °C) | 202289.11 |
| Steel (assumed similar to iron) | 299792458 | 5120 | 50300.75 |
## Key Citations
- [Speed of Light - Evident Scientific](https://evidentscientific.com/en/microscope-resource/knowledge-hub/lightandcolor/speedoflight)
- [Speed of sound - Wikipedia](https://en.wikipedia.org/wiki/Speed_of_sound)
`;
export default function Page() {
return (
<main className="flex h-full w-full">
<div className="flex h-screen flex-auto">
<ReportEditor />
<ReportEditor content={content} />
</div>
</main>
);

View File

@ -22,6 +22,10 @@ import {
Youtube,
} from "novel";
import { Markdown } from "tiptap-markdown";
import { Table } from "@tiptap/extension-table";
import { TableHeader } from "@tiptap/extension-table-header";
import { TableRow } from "@tiptap/extension-table-row";
import { TableCell } from "@tiptap/extension-table-cell";
import { cx } from "class-variance-authority";
import { common, createLowlight } from "lowlight";
@ -143,6 +147,11 @@ const mathematics = Mathematics.configure({
const characterCount = CharacterCount.configure();
const table = Table.configure();
const tableRow = TableRow.configure();
const tableCell = TableCell.configure();
const tableHeader = TableHeader.configure();
const markdownExtension = Markdown.configure({
html: true,
tightLists: true,
@ -163,6 +172,10 @@ export const defaultExtensions = [
updatedImage,
taskList,
taskItem,
table,
tableRow,
tableCell,
tableHeader,
horizontalRule,
aiHighlight,
codeBlockLowlight,