from pydantic import BaseModel, Field
from langchain.agents import initialize_agent, Tool, AgentType
from langchain.tools import BaseTool,
class GetIncidentsByUserInput(BaseModel):
"""Input for Get Incidents by User."""
assigned_to: str = Field(..., description="Name of the person assigned to the incident")
class GetIncidentsByUserTool(BaseTool):
name = "get_incidents_by_user"
description = "Useful for when you need to get all incidents assigned to a user. You should input the name of the person assigned to the incident."
# Get variables from Input Class
def _run(self, assigned_to: str, run_manager: Optional[CallbackManagerForToolRun] = None):
print("i'm running")
response = get_incidents_by_user(service_now_uri_main, service_now_username, service_now_password, assigned_to)
return response
def _arun(self, assigned_to: str):
raise NotImplementedError("This tool does not support async")
args_schema: Optional[Type[BaseModel]] = GetIncidentsByUserInput
app = Flask(__name__)
# Initialize Flask-RESTx`your text`
api = Api(app)
chat_model = api.model('Chat', {
'userquestion': fields.String(description='The user question'),
'userinfo': fields.String(description='The user information'),
'userAD': fields.String(description='The user Active Directory information')
})
tools = [CreateServiceRequestTool(), CreateIncidentTool(),GetIncidentsByUserTool()]
redis_client = Redis()
@api.route('/chat')
class Chat(Resource):
@api.expect(chat**your text**_model)
def post(self):
try:
userquestion = request.json['userquestion']
userinfo = request.json['userinfo']
userAD = request.json['userAD']
memory = ConversationBufferMemory()
open_ai_agent = initialize_agent(tools, llm)
memory.chat_memory.add_user_message(f"input: {userinfo}")
response = open_ai_agent(prompt,userinfo)
if __name__ == '__main__':
app.run
I want to access varible userinfo from flask route chat or from flask main to the GetIncidentsByUserTool which was present outside of the flask instance without specifiyng the global varibale i want to access
I have tried this way
def init(self, userinfo):
self.userinfo = userinfo
but I am getting error`
New contributor
MANASA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.