If not, is there an example of an extension that does something similar that I can use as a base to create one?
Thanks,
L
If not, is there an example of an extension that does something similar that I can use as a base to create one?
Thanks,
L
Just tell it to create an Open Document Text file.
What do you mean? I’m looking at doing something where I can write a question in LO Writer, it sends the query to ChatGPT (or another AI engine) and puts the answer in the current document.
Why do you want to do it inside the Writer application? (Do you heard about the Ctrl-C; Ctrl-V keys? )
Try the extensions for translations, as it is the same principle: Send a text, receive another and manage some api-access and keys:
https://extensions.libreoffice.org/en/extensions/show/pagetranslate
https://extensions.libreoffice.org/en/extensions/show/anaphraseus
And you may check how the integration of DeepL in LibreOffice was done…
It’s just a matter of copy and paste. If ChatGPT is not able to produce a a structured office document, how should LibreOffice know from the plain text about headings, outline hierarchies etc.
You want to design a formatted and structured office document with some text content from something which is not able to design a text document, so the design job remains on your side. The usual solution is copy&paste plain, unformatted text and then apply appropriate styles to the right paragraphs.
DeepL and similar tools transfer the existing formatting and structure from the translated source document into the translation. As far as I know, it has formatting capabilities similar to this forum software which is far below the capabilities of an text processor like Writer or Word ChatGPT produces unformatted text. Either it will learn to output formatted text with outline levels or you have to do the formatting/outline all mostly by yourself.
EDIT: I saw a video where someone told the bot to generate a todo list in html with css. In future something similar may be possible with the Open Document Format (or ooxml at least).
Out of curiosity I asked it to make an extension yesterday, it gave a couple of options for ChatGPT APIs, gave a Python script for LO and gave a brief description on how to package it. It sounded plausible but incomplete. As I don’t know Python from rattlesnake, I won’t be going further.
Of course, I don’t know how correct it was. I hope better than the nonsense answers it gave to some other questions to which I knew the answers.
Thanks, I’ll look at those and see what they do.
L
@karolus here it is:
The first step is to decide which programming language you want to use for the extension. Libreoffice supports several languages, including Python, Java, and C++, among others. For this example, let’s assume you are using Python.
Next, you’ll need to install the necessary packages to interact with ChatGPT. The most common way to interact with ChatGPT is via an API. There are several options for ChatGPT APIs, including OpenAI’s API, Hugging Face’s API, and more.
Once you’ve chosen your API and installed the necessary packages, you can begin coding your extension. Here is an example Python script that sends a query to ChatGPT and puts the answer in the current document:
import uno
import requests
def get_answer(query):
# Send the query to ChatGPT API
api_key = "<YOUR API KEY>"
headers = {"Authorization": f"Bearer {api_key}"}
url = "<YOUR API URL>"
data = {"query": query}
response = requests.post(url, headers=headers, json=data)
# Get the answer from the response
answer = response.json()["answer"]
return answer
def insert_answer():
# Get the current document
context = uno.getComponentContext()
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
model = desktop.getCurrentComponent()
# Get the query from the user
query = uno.getRunningContext().getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", context)
query.setTitle("Enter your query")
if query.execute() == uno.getConstantByName("com.sun.star.ui.dialogs.ExecutableDialogResults.OK"):
query_string = query.getFiles()[0]
# Get the answer from ChatGPT
answer = get_answer(query_string)
# Insert the answer into the document
cursor = model.getCurrentController().getViewCursor()
cursor.setString(answer)
To use this script as an extension in Libreoffice Writer, you’ll need to package it as an add-on. You can do this by creating a manifest file that specifies the script as an AddOn and then packaging the manifest and script into an OXT file. Once you have the OXT file, you can install it in Libreoffice Writer using the Extension Manager
I hope this helps you get started on creating an extension for Libreoffice Writer that interacts with ChatGPT!
@EarnestAl Ok the »get_answer« -function looks somewhat reasonable, but after that it’s just wild guessing!
Ha ha. It does very well at stringing plausible nonsense together. It could make a poem of how to it but I won’t ask
Mankind has enough of its own (not artificial) graphomaniacs.
Seems LibreOffice might need to do something a little more sophisticated if it is to maintain compatibility with Microsoft Office. Please see Microsoft to demo its new ChatGPT-like AI in Word, PowerPoint, and Outlook soon - The Verge
Are you able to build something similar to this (but for LibreOffice):
https://github.com/analyticsinmotion/add-chatgpt-to-microsoft-word
Thanks.
Why? If you can’t use 2 different applications you are the perfect MS Word victim.
Here’s a link that explains how you can get ChatGPT to write formulae in Excel. I haven’t tried it but I don’t see any reason why a similar technique shouldn’t work in LibreOffice Calc.