Skip to content

Commit

Permalink
openplugin memo root_url
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeCrusher committed Aug 20, 2023
1 parent 6241dde commit e0f7f18
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pypi-core/openplugincore/openplugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# C:\Projects\OpenPlugin\openplugin\pypi-core\openplugincore\openplugin.py

import json
from urllib.error import HTTPError
import requests
Expand Down
14 changes: 11 additions & 3 deletions pypi-core/openplugincore/openplugin_memo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# C:\Projects\OpenPlugin\openplugin\pypi-core\openplugincore\openplugin_memo.py

import requests
from openplugincore import OpenPlugin
import os
Expand All @@ -19,17 +21,23 @@ def init(self):
self.plugins_directory[key] = value
print('MEMO READY')

def init_openplugin(self, plugin_name=None, root_url=None):
if not plugin_name and not root_url:
raise Exception('Plugin name not found')
plugin = OpenPlugin(plugin_name=plugin_name, root_url=root_url, openai_api_key=os.getenv('OPENAI_API_KEY'))
plugin.init()
return plugin

def init_plugin(self, plugin_name):
if not self.plugins_directory:
raise Exception('Plugin directory not initialized')
plugin_url = self.plugins_directory.get(plugin_name)
if plugin_url is None:
raise Exception('Plugin not found')
plugin = OpenPlugin(plugin_name=plugin_name, openai_api_key=os.getenv('OPENAI_API_KEY'))
plugin.init()
plugin = self.init_openplugin(plugin_name=plugin_name)
self.add_plugin(plugin)
return plugin

# method to add an OpenPlugin to the plugins map
def add_plugin(self, plugin):
if not plugin.name:
Expand Down
2 changes: 1 addition & 1 deletion pypi-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
# the name must match the folder name 'verysimplemodule'
name='openplugincore',
version="0.6.3",
version="0.6.4",
author="Sebastian Sosa",
author_email="[email protected]",
description='Seamlessly integrate with OpenAI ChatGPT plugins via API (or client), offering the same powerful functionality as the ChatGPT api + plugins!',
Expand Down
20 changes: 20 additions & 0 deletions pypi-core/tests/test_openplugin_memo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ def test_retrieve_plugins():
open_plugin_memo.remove_plugin('__testing__')
todo_openplugin = open_plugin_memo.get_plugin('__testing__')
assert todo_openplugin is None

def test_root_url_full_suite():
open_plugin_memo = OpenPluginMemo()
open_plugin_memo.init()

todo_openplugin = open_plugin_memo.init_openplugin(root_url='http://127.0.0.1:3333')
assert todo_openplugin.manifest is not None
assert len(todo_openplugin.functions) == 2

response = todo_openplugin.fetch_plugin(
messages=todo_plugin["messages"],
model='gpt-3.5-turbo-0613',
)

assert response is not None
assert response['role'] == 'function'
assert response['name'] == 'addTodo'

json_content = json.loads(response['content'])
assert json_content['todo'] == todo_plugin['request_out.json()']['todo']

0 comments on commit e0f7f18

Please sign in to comment.