镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 14:36:48 +00:00
plugin refactor: phase 1
这个提交包含在:
@@ -0,0 +1,57 @@
|
||||
import os, json, base64
|
||||
from pydantic import BaseModel, Field
|
||||
from textwrap import dedent
|
||||
|
||||
class ArgProperty(BaseModel):
|
||||
title: str = Field(description="The title", default="")
|
||||
description: str = Field(description="The description", default="")
|
||||
default_value: str|float = Field(description="The default value", default="")
|
||||
type: str = Field(description="The type", default="")
|
||||
|
||||
class GptAcademicPluginTemplate():
|
||||
def __init__(self):
|
||||
# please note that `execute` method may run in different threads,
|
||||
# thus you should not store any state in the plugin instance,
|
||||
# which may be accessed by multiple threads
|
||||
pass
|
||||
|
||||
def define_arg_selection_menu(self):
|
||||
"""
|
||||
An example as below:
|
||||
```
|
||||
def define_arg_selection_menu(self):
|
||||
gui_definition = {
|
||||
"main_input":
|
||||
ArgProperty(title="main input", description="description", default_value="default_value", type="string").model_dump_json(),
|
||||
"advanced_arg":
|
||||
ArgProperty(title="advanced arguments", description="description", default_value="default_value", type="string").model_dump_json(),
|
||||
"additional_arg_01":
|
||||
ArgProperty(title="additional", description="description", default_value="default_value", type="string").model_dump_json(),
|
||||
}
|
||||
return gui_definition
|
||||
```
|
||||
"""
|
||||
raise NotImplementedError("You need to implement this method in your plugin class")
|
||||
|
||||
|
||||
def get_js_code_for_generating_menu(self, btnName):
|
||||
define_arg_selection = self.define_arg_selection_menu()
|
||||
|
||||
if len(define_arg_selection.keys()) > 8:
|
||||
raise ValueError("You can only have up to 8 arguments in the define_arg_selection")
|
||||
if "main_input" not in define_arg_selection:
|
||||
raise ValueError("You must have a 'main_input' in the define_arg_selection")
|
||||
if "advanced_arg" not in define_arg_selection:
|
||||
raise ValueError("You must have a 'main_input' in the define_arg_selection")
|
||||
|
||||
DEFINE_ARG_INPUT_INTERFACE = json.dumps(define_arg_selection)
|
||||
return dedent("""
|
||||
()=>generate_menu("{GUI_JS}", "{BTN_NAME}")
|
||||
""".format(
|
||||
GUI_JS=base64.b64encode(DEFINE_ARG_INPUT_INTERFACE.encode('utf-8')).decode('utf-8'),
|
||||
BTN_NAME=btnName
|
||||
)
|
||||
)
|
||||
|
||||
def execute(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_request):
|
||||
raise NotImplementedError("You need to implement this method in your plugin class")
|
||||
在新工单中引用
屏蔽一个用户