Skip to main content
alexanderp3125138
Inspiring
March 13, 2024
Answered

Script to integrate local LLM for proofreading

  • March 13, 2024
  • 1 reply
  • 9682 views

Hey folks,

I'm thinking of writing a script to add local LLM api support to FrameMaker. I basically want to get AI assisted proofreading/text correction by doing the following (using a local lightweight Mistral-7B model):

1. Select text, then send it via button press to an LLM client  running on my computer (LM Studio or ollama) for proofreading
2. Receive & process the proofreading results
3. Apply the suggestions to the text in FrameMaker

 

Before I dive into what might just be an impossible task due to ExtendScript limitations (I'd have to do quite a lot of digging, I'm not a real coder), do you think this is doable? I'd be very grateful for any insights, or tips where to start. 🙂🙏

    Correct answer frameexpert

    Thanks for your reply, I really appreciate it. 🙂


    I'm looking for a way to actually select a paragraph with Extendscript. The idea is that I want the user to be able to either select text with the mouse, or, if nothing is selected, simply select the whole next paragraph. This kind of advanced either/or functionality will be reserved for later though. I'll stitch it together once both parts are working independently. 

     

    Right now, option 1 is working fine, the text is sent over to the llm via api, connection is staying alive as long as needed, corrected text is received and pasted back into the document, overwriting the previous (selected) text. 

     

    Now for option 2, if the text gets copied and sent over automatically without selecting it first, it gets corrected, too, but then inserted into the paragraph at insertion point, so I end up with the old and new text.

     

    So all I need is a way to select the next paragraph relative to the cursor position. I think I could integrate this easily with the getText function that's already working. I could also paste my whole script text here, but that would probably just unnecessarily blow up my post, and I don't want to bother you guys even more with walls of text. 😉


    These two short videos will explain text locations and text ranges:

    https://youtu.be/6ywYWU4VC7g?si=pA7llQ5vS8nIlqwt

    https://youtu.be/fH5giAcDp6Q?si=lerkUNDTWdSoLKjO

    If you are in a hurry, the second one will show you how to select a paragraph.

    1 reply

    frameexpert
    Community Expert
    Community Expert
    March 13, 2024

    How can your LLM receive inputs? You could send text via a commandline from ExtendScript. ExtendScript does allow some integration with other programs via C++.

    www.frameexpert.com
    alexanderp3125138
    Inspiring
    March 13, 2024

    Input is received via local api (LM Studio = http://localhost:1234/, ollama = http://localhost:11434/). I'm wondering if it's possible to create some sort of automated "roundtrip", with text pushed to the api, and completion received automatically.

    Legend
    March 15, 2024

    I'll just throw this in here as WIP. Here's what's happening:

    1. I can't get the script to actually add my text selection to the JSON string, there's simply nothing happening.

    2. If I take the "var highlighted text" snippet out, the script does send the system prompt to LLM studio successfully, which then generates an answer, and tries to send it back.

    3. In that case, I then receive an error message in FrameMaker ("Corrected Text: undefined"), which means something is received, but not in the correct format.

    Anway, here's my code so far (please bear with me, I'm no coder and am trying to piece this together somehow 😇

     

     

    [Edit: code deprecated & removed, update further below]

     


    Hi, I definitely commend you for trying to do this... much of the value of FrameMaker is found in the ability to customize it and very few users actually leverage this value. So I encourage you to keep going. Having said that, you are attempting to do a variety of complicated things all at once and I think you need to back up, study a little more, and go piece by piece. For example, right in the beginning you have "app.activeDocument.selection", but neither the "activeDocument" nor "selection" properties actually exist. I could be wrong, but I suspect that nobody is willing to spend lots of time giving free ExtendScript training, so my recommendation is to back up a bit, learn the individual pieces, then come back if you have specific questions. I hope you don't take this the wrong way... I just think it is the best approach for anyone of they want to succeed at something so ambitious and also get productive help from the people who volunteer their time here.

     

    Russ