mirror of
https://github.com/ONLYOFFICE/desktop-sdk.git
synced 2026-02-10 18:15:05 +08:00
Add tools for generate docx/pdf/pptx
This commit is contained in:
@ -5279,6 +5279,11 @@ window.AscDesktopEditor.CallInFrame(\"" +
|
||||
return files;
|
||||
}
|
||||
|
||||
virtual void ExecuteJS(const std::string& code)
|
||||
{
|
||||
CefV8Context::GetCurrentContext()->GetFrame()->ExecuteJavaScript(code, "", 0);
|
||||
}
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(CAscEditorNativeV8Handler);
|
||||
};
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
{
|
||||
"type": "function",
|
||||
"name": "generate_docx",
|
||||
"description": "Use this function if you are asked to generate a textual document (report, article, letter, etc.) based on a description. Input: a detailed description of what needs to be generated.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "Detailed description of the document to generate, including its topic, structure, tone, and format."
|
||||
}
|
||||
},
|
||||
"required": ["description"]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
#include "./../internal/base.h"
|
||||
|
||||
namespace generate_docx
|
||||
{
|
||||
std::string description()
|
||||
{
|
||||
return "\
|
||||
{\
|
||||
\"type\": \"function\",\
|
||||
\"name\": \"generate_docx\",\
|
||||
\"description\": \"Use this function if you are asked to generate a textual document (report, article, letter, etc.) based on a description. Input: a detailed description of what needs to be generated.\",\
|
||||
\"parameters\": {\
|
||||
\"type\": \"object\",\
|
||||
\"properties\": {\
|
||||
\"description\": {\
|
||||
\"type\": \"string\",\
|
||||
\"description\": \"Detailed description of the document to generate, including its topic, structure, tone, and format.\"\
|
||||
}\
|
||||
},\
|
||||
\"required\": [\"description\"]\
|
||||
}\
|
||||
}";
|
||||
}
|
||||
|
||||
std::string main(const std::string& arg, CAIToolsHelper* helper)
|
||||
{
|
||||
json returnValue = json::object();
|
||||
|
||||
json param = json::parse(arg);
|
||||
if (!param.contains("description") || !param["description"].is_string())
|
||||
{
|
||||
returnValue["status"] = "error";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string description = param["description"];
|
||||
std::string code = "window.AscDesktopEditor.generateNew(\"docx\", \"ai-gen-docx\", " + json(description).dump() + ");";
|
||||
helper->ExecuteJS(code);
|
||||
|
||||
returnValue["status"] = "success";
|
||||
}
|
||||
|
||||
return returnValue.dump();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
{
|
||||
"type": "function",
|
||||
"name": "generate_form",
|
||||
"description": "Use this function if you are asked to generate a form or document template (contract, any document for filling) based on a description. Input: a detailed description of the desired form or template.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "Detailed description of the form or template to generate, including purpose, structure."
|
||||
}
|
||||
},
|
||||
"required": ["description"]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
#include "./../internal/base.h"
|
||||
|
||||
namespace generate_form
|
||||
{
|
||||
std::string description()
|
||||
{
|
||||
return "\
|
||||
{\
|
||||
\"type\": \"function\",\
|
||||
\"name\": \"generate_form\",\
|
||||
\"description\": \"Use this function if you are asked to generate a form or document template (contract, any document for filling) based on a description. Input: a detailed description of the desired form or template.\",\
|
||||
\"parameters\": {\
|
||||
\"type\": \"object\",\
|
||||
\"properties\": {\
|
||||
\"description\": {\
|
||||
\"type\": \"string\",\
|
||||
\"description\": \"Detailed description of the form or template to generate, including purpose, structure.\"\
|
||||
}\
|
||||
},\
|
||||
\"required\": [\"description\"]\
|
||||
}\
|
||||
}";
|
||||
}
|
||||
|
||||
std::string main(const std::string& arg, CAIToolsHelper* helper)
|
||||
{
|
||||
json returnValue = json::object();
|
||||
|
||||
json param = json::parse(arg);
|
||||
if (!param.contains("description") || !param["description"].is_string())
|
||||
{
|
||||
returnValue["status"] = "error";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string description = param["description"];
|
||||
std::string code = "window.AscDesktopEditor.generateNew(\"pdf\", \"ai-gen-form\", " + json(description).dump() + ");";
|
||||
helper->ExecuteJS(code);
|
||||
|
||||
returnValue["status"] = "success";
|
||||
}
|
||||
|
||||
return returnValue.dump();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
{
|
||||
"type": "function",
|
||||
"name": "generate_pptx",
|
||||
"description": "Use this function if you are asked to generate a complete presentation with a custom theme, fonts, and streaming content. Input: a detailed description of the presentation to create, including topic, number of slides, and style.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topic": {
|
||||
"type": "string",
|
||||
"description": "Presentation topic."
|
||||
},
|
||||
"slideCount": {
|
||||
"type": "string",
|
||||
"description": "Number of slides to generate."
|
||||
},
|
||||
"style": {
|
||||
"type": "string",
|
||||
"description": "Visual style of the presentation: modern, classic, minimal, or corporate."
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
#include "./../internal/base.h"
|
||||
|
||||
namespace generate_pptx
|
||||
{
|
||||
std::string description()
|
||||
{
|
||||
return "\
|
||||
{\
|
||||
\"type\": \"function\",\
|
||||
\"name\": \"generate_pptx\",\
|
||||
\"description\": \"Use this function if you are asked to generate a complete presentation with a custom theme, fonts, and streaming content. Input: a detailed description of the presentation to create, including topic, number of slides, and style.\",\
|
||||
\"parameters\": {\
|
||||
\"type\": \"object\",\
|
||||
\"properties\": {\
|
||||
\"topic\": {\
|
||||
\"type\": \"string\",\
|
||||
\"description\": \"Presentation topic.\"\
|
||||
},\
|
||||
\"slideCount\": {\
|
||||
\"type\": \"string\",\
|
||||
\"description\": \"Number of slides to generate.\"\
|
||||
},\
|
||||
\"style\": {\
|
||||
\"type\": \"string\",\
|
||||
\"description\": \"Visual style of the presentation: modern, classic, minimal, or corporate.\"\
|
||||
}\
|
||||
},\
|
||||
\"required\": []\
|
||||
}\
|
||||
}";
|
||||
}
|
||||
|
||||
std::string main(const std::string& arg, CAIToolsHelper* helper)
|
||||
{
|
||||
json returnValue = json::object();
|
||||
|
||||
json param = json::parse(arg);
|
||||
if (!param.is_object())
|
||||
{
|
||||
returnValue["status"] = "error";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string value = json(param).dump();
|
||||
std::string code = "window.AscDesktopEditor.generateNew(\"pptx\", \"ai-gen-pptx\", " + json(value).dump() + ");";
|
||||
helper->ExecuteJS(code);
|
||||
|
||||
returnValue["status"] = "success";
|
||||
}
|
||||
|
||||
return returnValue.dump();
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,9 @@
|
||||
#include "../folder_content_reader/main.cpp"
|
||||
#include "../form_field_analyser/main.cpp"
|
||||
#include "../form_field_filler/main.cpp"
|
||||
#include "../generate_docx/main.cpp"
|
||||
#include "../generate_form/main.cpp"
|
||||
#include "../generate_pptx/main.cpp"
|
||||
#include "../recent_files_reader/main.cpp"
|
||||
|
||||
struct TFuncInstance
|
||||
@ -26,6 +29,9 @@ public:
|
||||
m_funcs.insert(std::make_pair("folder_content_reader", TFuncInstance(folder_content_reader::description(), folder_content_reader::main)));
|
||||
m_funcs.insert(std::make_pair("form_field_analyser", TFuncInstance(form_field_analyser::description(), form_field_analyser::main)));
|
||||
m_funcs.insert(std::make_pair("form_field_filler", TFuncInstance(form_field_filler::description(), form_field_filler::main)));
|
||||
m_funcs.insert(std::make_pair("generate_docx", TFuncInstance(generate_docx::description(), generate_docx::main)));
|
||||
m_funcs.insert(std::make_pair("generate_form", TFuncInstance(generate_form::description(), generate_form::main)));
|
||||
m_funcs.insert(std::make_pair("generate_pptx", TFuncInstance(generate_pptx::description(), generate_pptx::main)));
|
||||
m_funcs.insert(std::make_pair("recent_files_reader", TFuncInstance(recent_files_reader::description(), recent_files_reader::main)));
|
||||
}
|
||||
};
|
||||
|
||||
@ -65,6 +65,8 @@ public:
|
||||
virtual void OpenTemplate(const std::wstring& path, const std::wstring& name = L"") = 0;
|
||||
virtual void OpenFile(const std::wstring& path) = 0;
|
||||
virtual std::vector<CRecentFileInfo> GetRecents() = 0;
|
||||
|
||||
virtual void ExecuteJS(const std::string& code) = 0;
|
||||
};
|
||||
|
||||
class CFunctions;
|
||||
|
||||
Reference in New Issue
Block a user