Giter VIP home page Giter VIP logo

Comments (5)

steven-tey avatar steven-tey commented on July 20, 2024 1

Yes – this is being worked on as part of #29! The hard part is figuring out the AI editing UX – I wrote about it in the PR!

from novel.

jt6677 avatar jt6677 commented on July 20, 2024 1

I added additional command in slash. slah comment is trigget by selectItem so you can add whatever command you need.

  1. extract apis into different hooks
  const {
    complete: continueComplete,
    completion,
    isLoading: isLoadingContinue,
    stop,
  } = useContinueCommand(editor)

  const { complete: breakSteps, isLoading: isLoadingBreakSteps } = useBreakIntoSteps({
    editor,
    project_title,
    project_des,
    task_title,
  })

  const selectItem = useCallback(
    (index: number) => {
      const item = items[index]
      if (item) {
        if (item.title === 'Continue writing') {
          const text = editor.getText()
          continueComplete(text)
        }
        if (item.title === 'Break into steps') {
          const text = editor.getText()
          breakSteps(text)
        } else {
          command(item)
        }
      }
    },
    [continueComplete, breakSteps, command, editor, items]
  )
  1. add to array
const getSuggestionItems = ({ query }: { query: string }) => {
  return [
    {
      title: 'Continue writing',
      description: 'Use AI to expand your thoughts.',
      icon: <Magic className="w-7 text-black" />,
    },
    {
      title: 'Break into steps',
      description: 'Use AI to break action into steps .',
      icon: <Component className="w-7 text-black" />,
    },
]
  1. add spinning indicator for new command (could use switch state for better readability)
            {item.title === 'Continue writing' && isLoadingContinue ? (
                <LoadingCircle />
              ) : item.title === 'Break into steps' && isLoadingBreakSteps ? (
                <LoadingCircle />
              ) : (
                item.icon
              )}

from novel.

jt6677 avatar jt6677 commented on July 20, 2024 1

It would look like this. (I turned off the markdown)
firefox_wtYqHvMWMP

from novel.

steven-tey avatar steven-tey commented on July 20, 2024

@jt6677 oooh very interesting – so you're basically streaming in responses without markdown, and then converting them to markdown once streaming is complete?

Is it possible to stream them in and directly format them as markdown?

from novel.

jt6677 avatar jt6677 commented on July 20, 2024

@jt6677 oooh very interesting – so you're basically streaming in responses without markdown, and then converting them to markdown once streaming is complete?

Is it possible to stream them in and directly format them as markdown?

For what I understand, tiptap does not play nice with markdown. Individual paragraph or each circled step is a tiptap node.

const taskItems = completion
       .split(/\n(?=\d+\.)/) // Splits at the start of each numbered item
       .filter((task) => task.trim().length > 0) // Filters out any empty strings
       .map((task) => {
         const taskText = task.trim().slice(3) // Removes the numbering and leading space from each task item
         return {
           type: 'taskItem',
           attrs: {
             checked: false,
           },
           content: [
             {
               type: 'paragraph',
               content: [{ type: 'text', text: taskText }],
             },
           ],
         }
       })

     const taskList = {
       type: 'taskList',
       content: taskItems,
     }

     editor?.chain().deleteRange({ from, to }).insertContent(taskList).run() 

Basically, I take the finial result (after streaming), split into array of text and parse each text as a special tiptap node(taskItem). There is a problem in current version of novel; streamed markdown would appear to be correctly formatted at first. But to Tiptap, it was just a SINGLE node with text. Any editing on the markdown text would cause the text to lose all format, and collapse into a single paragraph.

The solution I am using in my app is just parse individual text to tiptap nodes whether is a paragraph or a taskItem.

from novel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.