Skip to content

Commit

Permalink
increment plugin API major version due to changed Responder interface…
Browse files Browse the repository at this point in the history
… in previous commit 92a67c3. add version check when loading plugins. (#37)
  • Loading branch information
RossBencina authored Oct 23, 2023
1 parent 65a60d4 commit a2ccdbf
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 20 deletions.
38 changes: 35 additions & 3 deletions prapti/core/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import types
import json
import importlib.metadata
from dataclasses import dataclass

import pydantic
from cancel_token import CancellationToken
Expand All @@ -22,6 +23,32 @@

builtin_actions: ActionNamespace = ActionNamespace()

# plugin version check -------------------------------------------------------

@dataclass
class Version:
major: int
minor: int
patch: int

def parse_semver(version: str) -> Version:
parts = version.split(".") # basic major.minor.patch semver only
return Version(major=int(parts[0]), minor=int(parts[1]), patch=int(parts[2]))

def plugin_version_is_compatible(prapti_api_version: str, plugin_api_version: str):
"""determine compatibility based on semver semantics. see https://semver.org/"""
prapti_api_version_v = parse_semver(prapti_api_version)
plugin_api_version_v = parse_semver(plugin_api_version)
if plugin_api_version_v.major != prapti_api_version_v.major:
# incompatible major API versions
return False
if plugin_api_version_v.minor > prapti_api_version_v.minor:
# plugin may use newer features that are unavailble in core
return False
return True

PRAPTI_API_VERSION = "1.0.0"

# plugin management ----------------------------------------------------------

# Plugin loading proceeds in the following steps:
Expand Down Expand Up @@ -49,16 +76,21 @@

def load_plugin_entry_point(plugin_name, source_loc: SourceLocation, log: DiagnosticsLogger) -> Plugin|None:
result: Plugin|None = loaded_plugin_entry_points.get(plugin_name, None)
if not result:
if not result: # if not already loaded
if plugin_entry_point := installed_plugin_entry_points.get(plugin_name, None):
try:
plugin = plugin_entry_point.load()
if plugin.name != plugin_entry_point.name:
log.warning("plugin-name-inconsistency", f"plugin entry point name '{plugin_entry_point.name}' does not match plugin name '{plugin.name}'. get someone to fix the code.")
result = plugin

if plugin_version_is_compatible(prapti_api_version=PRAPTI_API_VERSION, plugin_api_version=plugin.api_version):
result = plugin
else:
log.error("incompatible-plugin-version", f"couldn't load plugin '{plugin_name}'. plugin API version {plugin.api_version} is not compatible with Prapti API version {PRAPTI_API_VERSION}. you need to upgrade the plugin or downgrade Prapti.")
except Exception as ex:
log.error("load-plugin-entry-point-exception", f"exception while loading plugin entry point '{plugin_entry_point.name}': {repr(ex)}", source_loc)
log.error("load-plugin-entry-point-exception", f"couldn't load plugin '{plugin_name}'. an error occurred: exception while loading plugin entry point '{plugin_entry_point.name}': {repr(ex)}", source_loc)
log.logger.debug(ex, exc_info=True)
result = None
else:
log.error("plugin-not-found", f"couldn't load plugin '{plugin_name}'. plugin not found. use `%!plugins.list` to list available plugins.", source_loc)
return result
Expand Down
2 changes: 1 addition & 1 deletion prapti/plugins/capture_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def on_response_completed(self, context: HooksContext):
class CaptureEverythingPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.capture_everything",
version = "0.0.1",
description = "Automatically capture each prapti run to a file",
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/endpoints/gpt4all_chat_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class GPT4AllChatResponderPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "experimental.gpt4all.chat",
version = "0.0.1",
version = "0.0.2",
description = "Responder using the GPT4All Chat Completion API",
capabilities = PluginCapabilities.RESPONDER
)
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/endpoints/koboldcpp_text_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class KoboldcppResponderPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "koboldcpp.text",
version = "0.0.1",
version = "0.0.2",
description = "Responder using the Koboldcpp text completions API",
capabilities = PluginCapabilities.RESPONDER
)
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/endpoints/local_openai_chat_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class LocalOpenAIChatResponderPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "local.openai.chat",
version = "0.0.1",
version = "0.0.2",
description = "Responder for using local LLMs that offer the OpenAI-compatible Chat Completion API",
capabilities = PluginCapabilities.RESPONDER
)
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/endpoints/openai_chat_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class OpenAIChatResponderPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "openai.chat",
version = "0.0.1",
version = "0.0.2",
description = "Responder using the OpenAI Chat Completion API",
capabilities = PluginCapabilities.RESPONDER
)
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/experimental_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class AgentsPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.experimental.agents",
version = "0.0.2",
version = "0.0.3",
description = "Multi-agent responses",
capabilities = PluginCapabilities.ACTIONS | PluginCapabilities.RESPONDER
)
Expand Down
2 changes: 1 addition & 1 deletion prapti/plugins/experimental_gitlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def on_response_completed(self, context: HooksContext):
class GitlogPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.experimental.gitlog",
version = "0.0.1",
description = "Hooks for git conversation tracking",
Expand Down
2 changes: 1 addition & 1 deletion prapti/plugins/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def include_code(name: str, raw_args: str, context: ActionContext) -> None|str|M
class IncludePlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.include",
version = "0.0.1",
description = "Commands for including file contents",
Expand Down
2 changes: 1 addition & 1 deletion prapti/plugins/prapti_test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def teast_test(name: str, raw_args: str, context: ActionContext) -> None|str|Mes
class TestActionsPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.test.test_actions",
version = "0.0.1",
description = "Actions used to test Prapti",
Expand Down
2 changes: 1 addition & 1 deletion prapti/plugins/prapti_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestConfigConfiguration(BaseModel):
class TestConfigPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.test.test_config",
version = "0.0.1",
description = "Plugin used to test Prapti",
Expand Down
4 changes: 2 additions & 2 deletions prapti/plugins/prapti_test_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def generate_responses(self, input_: list[Message], cancellation_token: Cancella
class TestResponderPlugin(Plugin):
def __init__(self):
super().__init__(
api_version = "0.1.0",
api_version = "1.0.0",
name = "prapti.test.test_responder",
version = "0.0.1",
version = "0.0.2",
description = "Responder used to test Prapti",
capabilities = PluginCapabilities.RESPONDER
)
Expand Down

0 comments on commit a2ccdbf

Please sign in to comment.