Skip to content

Commit

Permalink
enhance logger
Browse files Browse the repository at this point in the history
  • Loading branch information
karaposu committed Oct 15, 2024
1 parent bca516b commit ccfbb8d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
35 changes: 35 additions & 0 deletions proteas/bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

class Bin():
def __init__(self):
self.storage= []
self.questinables=[]

def add(self, thing):
self.storage.append(thing)

def reset(self):
self.storage = []

def bring(self, name):

for p in self.storage:
pass

for idx, p in enumerate(self.storage):
if p.name == name:
return p

def bring_by_category(self, cat):
selections=[]
for idx, p in enumerate(self.storage):
if p.category == cat:
selections.append(p)
return selections
def find_questionable_prompts(self):
questinables=[]
for idx, p in enumerate(self.storage):
if p.category=="context_prompts":
# question = p
questinables.append(p)

self.questinables= questinables
67 changes: 20 additions & 47 deletions proteas/proteas.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,28 @@
import string
import yaml
import logging
from .prompt_template_unit import PromptTemplateUnit
from .bin import Bin

# from indented_logger import IndentedLogger
# import logging
# logger_setup = IndentedLogger(name='prepromptbuilder', level=logging.INFO, include_func=True)

l= []

class Bin():
def __init__(self):
self.storage= []
self.questinables=[]

def add(self, thing):
self.storage.append(thing)

def reset(self):
self.storage = []

def bring(self, name):

for p in self.storage:
pass

for idx, p in enumerate(self.storage):
if p.name == name:
return p

def bring_by_category(self, cat):
selections=[]
for idx, p in enumerate(self.storage):
if p.category == cat:
selections.append(p)
return selections
def find_questionable_prompts(self):
questinables=[]
for idx, p in enumerate(self.storage):
if p.category=="context_prompts":
# question = p
questinables.append(p)

self.questinables= questinables


logger = logging.getLogger(__name__)

class Proteas:
def __init__(self, yaml_path=None, logger=None):
def __init__(self, yaml_path=None, debug=False):
"""Initialize the PromptManager without any specific attributes."""
self.bin= Bin()
self.unit_objects=[]
self.debug= debug


# self.logger = logger if logger else logger_setup.get_logger()
self.logger =logger
self.logger = logging.getLogger(__name__)

if yaml_path:
self.load_unit_skeletons_from_yaml(yaml_path)

def _debug(self, message):

if self.debug:
self.logger.debug(message)

def load_yaml_file(self,file_path):
with open(file_path, 'r') as file:
yaml_data = yaml.safe_load(file) # Load the YAML data
Expand All @@ -82,7 +47,8 @@ def load_unit_skeletons_from_yaml(self, yaml_file_path):

yaml_data = self.load_yaml_file(yaml_file_path)
self.unit_objects = self.create_units_from_skeletons(yaml_data)
print( len(self.unit_objects), "prompt template units loaded")
self._debug(f" {len(self.unit_objects)} prompt template units loaded")
#print( len(self.unit_objects), "prompt template units loaded")

def bring_units(self, list_of_unit_names):
p = []
Expand Down Expand Up @@ -404,6 +370,13 @@ def create_prompt(self, question, units, context_data):


def main():
import sys

logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
stream=sys.stdout
)

proteas = Proteas('prompts.yaml')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='proteas', # Package name
version='0.0.2', # Version of your package
version='0.0.3', # Version of your package
author='Enes Kuzucu', # Your name

description='A module to create prompt templates dynamically', # Short description
Expand Down

0 comments on commit ccfbb8d

Please sign in to comment.