Skip to content

Commit

Permalink
http error usage
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeCrusher committed Oct 22, 2023
1 parent 08d841c commit 0d41da6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pypi-core/openplugincore/openplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ def request_chain(name, arguments, headers):
request_out = request_chain(**llm_chain_out, headers=plugin_headers)
# if request_out.status_code is not within 200s then raise http error
if request_out.status_code < 200 or request_out.status_code >= 300:
raise HTTPError(f"API call failed, API returned the following non-JSON response:\n{request_out.content}")
raise HTTPError(
url=self.manifest["api"]["url"],
code=request_out.status_code,
msg=f"Call to \"{self.name}\" API failed",
hdrs={},
fp=None,
)
json_response = request_out.json()

if truncate:
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.7.1",
version="0.7.2",
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: 25 additions & 0 deletions pypi-core/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,31 @@ def test_initiate_and_fetch_askyourpdf():

assert len(json_content["summary"]) > 0

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

# create chatgpt request that will call the addTodo function
chatgpt_prompt = 'Take this diagram to explain how a car works using a mermaid diagram of type graph. Return the link.'
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"])

print(json.dumps(json_content, indent=2))

assert json_content["diagramLanguage"] == "mermaid"

"""
TEMPLATE for testing a new plugin
0. test the plugin with a prompt in ChatGPT
Expand Down

0 comments on commit 0d41da6

Please sign in to comment.