from langchain.prompts import PromptTemplate
from langchain.chat_models.base import BaseChatModel
from abc import ABC, abstractmethod
from langchain.schema.messages import HumanMessage, SystemMessage, AIMessage, ChatMessage
from enum import Enum
from utilities.utilities import prompt_utilities
import json
class agent_types(Enum):
STORAGE="storage",
SUMMARY="summary",
ASSIST="story-assist"
def validate_variable(self, variabledict: dict):
for l in self.required_prompt_input_variables:
if l not in variabledict:
raise ValueError(f"{l} not included in vars passed to {__name__}.call")
def call(self, variablesdict, context, utilities : prompt_utilities):
self.validate_variable(variabledict=variablesdict)
prompt = self.get_prompt(variablesdict, context)
response = None
calls = [SystemMessage(content=self.system_prompt_template),
HumanMessage(content=prompt)]
try:
utilities.log_prompt(title=f"Calling {self.key}", messages=calls)
response = self.llm(calls)
except Exception as e:
return f"An error occured: {e.__str__()}. Please try again"
return response.content
def get_prompt(self, variablesdict, context):
prompt = self.prompt_template
for k, v in variablesdict.items():
prompt = prompt.replace(k, v)
return prompt
When I call utilities.log_prompt(title=f"Calling {self.key}", messages=calls), in the class above, why does it expect the self parameter to be passed when Its part of a class?
from .prompt_logger import prompt_logger
from .system_prompt_builder import system_prompt_builder
from .history import history_manager
from langchain.schema.messages import BaseMessage
In the given code, the utilities.log_prompt(title=f"Calling {self.key}", messages=calls) method is called within the call method of the agent class. The self.key attribute is a part of the agent class, and it is being used within the string formatting operation f"Calling {self.key}". The self parameter is not being explicitly passed to the method, but it is being used within the string formatting operation, which is why it requires the self parameter to be available in the context.
The call method is an abstract method in the function_agent class, and it is implemented in the agent class. When the call method is called, it has access to the self.key attribute, which is a part of the agent class. The string formatting operation f"Calling {self.key}" is using the self.key attribute, which is why it requires the self parameter to be available in the context.
In summary, the self parameter is not being explicitly passed to the utilities.log_prompt method, but it is being used within the string formatting operation. The self parameter is available in the context because the call method is called on an instance of the agent class.