prompt-caller 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prompt_caller-0.0.1/PKG-INFO +21 -0
- prompt_caller-0.0.1/README.md +9 -0
- prompt_caller-0.0.1/prompt_caller/__init__.py +0 -0
- prompt_caller-0.0.1/prompt_caller/__main__.py +7 -0
- prompt_caller-0.0.1/prompt_caller/prompt_caller.py +95 -0
- prompt_caller-0.0.1/prompt_caller.egg-info/PKG-INFO +21 -0
- prompt_caller-0.0.1/prompt_caller.egg-info/SOURCES.txt +10 -0
- prompt_caller-0.0.1/prompt_caller.egg-info/dependency_links.txt +1 -0
- prompt_caller-0.0.1/prompt_caller.egg-info/requires.txt +1 -0
- prompt_caller-0.0.1/prompt_caller.egg-info/top_level.txt +1 -0
- prompt_caller-0.0.1/setup.cfg +4 -0
- prompt_caller-0.0.1/setup.py +55 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: prompt_caller
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API
|
|
5
|
+
Author: Thiago Nepomuceno
|
|
6
|
+
Author-email: thiago@neps.academy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: toml
|
|
12
|
+
|
|
13
|
+
# Neps Academy AI
|
|
14
|
+
|
|
15
|
+
This package is responsible for all Neps Academy features related to AI
|
|
16
|
+
|
|
17
|
+
# Build and Upload
|
|
18
|
+
|
|
19
|
+
python setup.py sdist bdist_wheel
|
|
20
|
+
|
|
21
|
+
twine upload dist/\*
|
|
File without changes
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
import yaml
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
from jinja2 import Template
|
|
7
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
8
|
+
from langchain_openai import ChatOpenAI
|
|
9
|
+
from pydantic import BaseModel, Field, create_model
|
|
10
|
+
|
|
11
|
+
load_dotenv()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PromptCaller:
|
|
15
|
+
|
|
16
|
+
def _loadPrompt(self, file_path):
|
|
17
|
+
with open(file_path, "r") as file:
|
|
18
|
+
content = file.read()
|
|
19
|
+
|
|
20
|
+
# Split YAML header and the body
|
|
21
|
+
header, body = content.split("---", 2)[1:]
|
|
22
|
+
|
|
23
|
+
# Parse the YAML header
|
|
24
|
+
model_config = yaml.safe_load(header.strip())
|
|
25
|
+
|
|
26
|
+
# Step 2: Parse the JSX body and return it
|
|
27
|
+
return model_config, body.strip()
|
|
28
|
+
|
|
29
|
+
def _renderTemplate(self, body, context):
|
|
30
|
+
template = Template(body)
|
|
31
|
+
return template.render(context)
|
|
32
|
+
|
|
33
|
+
def _parseJSXBody(self, body):
|
|
34
|
+
elements = []
|
|
35
|
+
tag_pattern = r"<(system|user|assistant)>(.*?)</\1>"
|
|
36
|
+
|
|
37
|
+
matches = re.findall(tag_pattern, body, re.DOTALL)
|
|
38
|
+
|
|
39
|
+
for tag, content in matches:
|
|
40
|
+
elements.append({"role": tag, "content": content.strip()})
|
|
41
|
+
|
|
42
|
+
return elements
|
|
43
|
+
|
|
44
|
+
def loadPrompt(self, promptName, context=None):
|
|
45
|
+
# initialize context
|
|
46
|
+
if context is None:
|
|
47
|
+
context = {}
|
|
48
|
+
|
|
49
|
+
configuration, template = self._loadPrompt(
|
|
50
|
+
os.path.join("prompts", f"{promptName}.prompt")
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
template = self._renderTemplate(template, context)
|
|
54
|
+
|
|
55
|
+
parsedMessages = self._parseJSXBody(template)
|
|
56
|
+
|
|
57
|
+
messages = []
|
|
58
|
+
|
|
59
|
+
for message in parsedMessages:
|
|
60
|
+
if message.get("role") == "system":
|
|
61
|
+
messages.append(SystemMessage(content=message.get("content")))
|
|
62
|
+
|
|
63
|
+
if message.get("role") == "user":
|
|
64
|
+
messages.append(HumanMessage(content=message.get("content")))
|
|
65
|
+
|
|
66
|
+
return configuration, messages
|
|
67
|
+
|
|
68
|
+
def createPydanticModel(self, dynamic_dict):
|
|
69
|
+
# Create a dynamic Pydantic model from the dictionary
|
|
70
|
+
fields = {
|
|
71
|
+
key: (str, Field(description=f"Description for {key}"))
|
|
72
|
+
for key in dynamic_dict.keys()
|
|
73
|
+
}
|
|
74
|
+
# Dynamically create the Pydantic model with the fields
|
|
75
|
+
return create_model("DynamicModel", **fields)
|
|
76
|
+
|
|
77
|
+
def call(self, promptName, context=None):
|
|
78
|
+
|
|
79
|
+
configuration, messages = self.loadPrompt(promptName, context)
|
|
80
|
+
|
|
81
|
+
output = None
|
|
82
|
+
|
|
83
|
+
if "output" in configuration:
|
|
84
|
+
output = configuration.get("output")
|
|
85
|
+
configuration.pop("output")
|
|
86
|
+
|
|
87
|
+
chat = ChatOpenAI(**configuration)
|
|
88
|
+
|
|
89
|
+
if output:
|
|
90
|
+
dynamicModel = self.createPydanticModel(output)
|
|
91
|
+
chat = chat.with_structured_output(dynamicModel)
|
|
92
|
+
|
|
93
|
+
response = chat.invoke(messages)
|
|
94
|
+
|
|
95
|
+
return response
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: prompt_caller
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API
|
|
5
|
+
Author: Thiago Nepomuceno
|
|
6
|
+
Author-email: thiago@neps.academy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: toml
|
|
12
|
+
|
|
13
|
+
# Neps Academy AI
|
|
14
|
+
|
|
15
|
+
This package is responsible for all Neps Academy features related to AI
|
|
16
|
+
|
|
17
|
+
# Build and Upload
|
|
18
|
+
|
|
19
|
+
python setup.py sdist bdist_wheel
|
|
20
|
+
|
|
21
|
+
twine upload dist/\*
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
prompt_caller/__init__.py
|
|
4
|
+
prompt_caller/__main__.py
|
|
5
|
+
prompt_caller/prompt_caller.py
|
|
6
|
+
prompt_caller.egg-info/PKG-INFO
|
|
7
|
+
prompt_caller.egg-info/SOURCES.txt
|
|
8
|
+
prompt_caller.egg-info/dependency_links.txt
|
|
9
|
+
prompt_caller.egg-info/requires.txt
|
|
10
|
+
prompt_caller.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prompt_caller
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import setuptools
|
|
2
|
+
import shutil
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from setuptools.command.sdist import sdist
|
|
6
|
+
from wheel.bdist_wheel import bdist_wheel
|
|
7
|
+
|
|
8
|
+
with open("README.md", "r") as fh:
|
|
9
|
+
long_description = fh.read()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def clean_folders():
|
|
13
|
+
print("Removing temporary folders.")
|
|
14
|
+
|
|
15
|
+
TMP_FOLDERS = ["neps_academy_ai.egg-info", "build"]
|
|
16
|
+
for folder in TMP_FOLDERS:
|
|
17
|
+
if os.path.exists(folder):
|
|
18
|
+
shutil.rmtree(folder)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SdistCommand(sdist):
|
|
22
|
+
"""Custom build command."""
|
|
23
|
+
|
|
24
|
+
def run(self):
|
|
25
|
+
sdist.run(self)
|
|
26
|
+
clean_folders()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class BdistWheelCommand(bdist_wheel):
|
|
30
|
+
"""Custom build command."""
|
|
31
|
+
|
|
32
|
+
def run(self):
|
|
33
|
+
bdist_wheel.run(self)
|
|
34
|
+
clean_folders()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
setuptools.setup(
|
|
38
|
+
name="prompt_caller",
|
|
39
|
+
version="0.0.1",
|
|
40
|
+
author="Thiago Nepomuceno",
|
|
41
|
+
author_email="thiago@neps.academy",
|
|
42
|
+
description="This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API",
|
|
43
|
+
long_description=long_description,
|
|
44
|
+
long_description_content_type="text/markdown",
|
|
45
|
+
include_package_data=True,
|
|
46
|
+
# url="https://github.com/username/neps_academy_ai",
|
|
47
|
+
packages=setuptools.find_packages(),
|
|
48
|
+
classifiers=[
|
|
49
|
+
"Programming Language :: Python :: 3",
|
|
50
|
+
"License :: OSI Approved :: MIT License",
|
|
51
|
+
"Operating System :: OS Independent",
|
|
52
|
+
],
|
|
53
|
+
install_requires=["toml"],
|
|
54
|
+
cmdclass={"sdist": SdistCommand, "bdist_wheel": BdistWheelCommand},
|
|
55
|
+
)
|