Skip to content

Commit

Permalink
Merge pull request #22 from CakeCrusher/refactor/oplangchain
Browse files Browse the repository at this point in the history
migrate langchain to oplangchain with test
  • Loading branch information
CakeCrusher authored Aug 10, 2023
2 parents 3c7c5e9 + 8167777 commit e7abbbb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ envOpenplugin

log.txt
node_modules
package-lock.json
package-lock.json
logs
2 changes: 1 addition & 1 deletion npm-core/openplugincore/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export { OpenPluginMemo } from './openpluginMemo';

// under utils export openaiModelsInfo
export { openaiModelsInfo } from './util/constants';
export { estimateTokens } from './util/prompting';
export { estimateTokens } from './util/prompting';
14 changes: 7 additions & 7 deletions pypi-core/openplugincore/openplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from .types import ChatgptAssistantMessage, ChatgptFunctionMessage, PluginConfigs
from .utils.constants import openai_models_info
from .utils.prompting import estimate_tokens, tokens_to_chars, truncate_json_root
from langchain.chains.openai_functions.openapi import openapi_spec_to_openai_fn
from langchain.utilities.openapi import OpenAPISpec
from langchain.output_parsers.openai_functions import JsonOutputFunctionsParser
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage, AIMessage, SystemMessage, FunctionMessage
from langchain import LLMChain
from oplangchain.chains.openai_functions.openapi import openapi_spec_to_openai_fn
from oplangchain.utilities.openapi import OpenAPISpec
from oplangchain.output_parsers.openai_functions import JsonOutputFunctionsParser
from oplangchain.prompts import ChatPromptTemplate
from oplangchain.chat_models import ChatOpenAI
from oplangchain.schema import HumanMessage, AIMessage, SystemMessage, FunctionMessage
from oplangchain import LLMChain
import openai
from dotenv import load_dotenv
load_dotenv()
Expand Down
Binary file added pypi-core/requirements.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions 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.2",
version="0.6.3",
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 All @@ -17,7 +17,7 @@
install_requires=[
'requests',
'openai',
'langchain',
'oplangchain',
'python-dotenv',
], # add any additional packages

Expand Down
23 changes: 23 additions & 0 deletions pypi-core/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def test_initiate_and_fetch_scholarai():
# Replace the line below with a test for the final output in json_content
assert isinstance(json_content["total_num_results"], int)

@pytest.mark.skip(reason="Not whitelisted")
def test_initiate_and_fetch_rephrase():
plugin = OpenPlugin("rephrase")
assert plugin.manifest is not None
Expand Down Expand Up @@ -303,6 +304,28 @@ 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)

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

chatgpt_prompt = 'summarize this pdf https://eforms.com/download/2018/01/Non-Disclosure-Agreement-Template.pdf'
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"])

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

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

0 comments on commit e7abbbb

Please sign in to comment.