Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeCrusher committed Aug 22, 2023
2 parents 6038996 + b80cdc6 commit 584a7d9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 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
25 changes: 1 addition & 24 deletions pypi-core/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,6 @@ def test_initiate_and_fetch_portfoliopilot():
# Replace the line below with a test for the final output in json_content
assert isinstance(json_content["top_stocks"], list)

def test_initiate_and_fetch_C3_Glide():
plugin = OpenPlugin("C3_Glide", verbose=True)
assert plugin.manifest is not None

# create chatgpt request that will call the addTodo function
chatgpt_prompt = 'Provide me TAF for KJFK with reguards to aviation weather'
response = plugin.fetch_plugin(
messages=[
{
"role": "user",
"content": chatgpt_prompt
}
],
model="gpt-3.5-turbo-0613",
temperature=0,
)

assert response is not None
assert response["role"] == "function"
json_content = json.loads(response["content"])

# Replace the line below with a test for the final output in json_content
assert isinstance(json_content["tafs"], list)

@pytest.mark.skip(reason="Could not parse: requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1")
def test_initiate_and_fetch_Ai_PDF():
plugin = OpenPlugin("Ai_PDF", verbose=True)
Expand All @@ -304,6 +280,7 @@ def test_initiate_and_fetch_Ai_PDF():
# Replace the line below with a test for the final output in json_content
assert isinstance(json_content[0], str)

@pytest.mark.skip(reason="requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1")
def test_initiate_and_fetch_askyourpdf():
plugin = OpenPlugin("askyourpdf", verbose=True)
assert plugin.manifest is not None
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 584a7d9

Please sign in to comment.