Last active
April 13, 2023 15:52
-
-
Save dhinag/8761b4f46d578c2dff3116e0be60a467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from langchain.agents import initialize_agent | |
from langchain.llms import OpenAI | |
import json | |
from langchain.agents import Tool | |
from flask import Flask | |
from flask_cors import CORS | |
from flask import * | |
import json, time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llm = OpenAI(temperature=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = Flask(__name__) | |
CORS(app) | |
@app.route('/request/admin/', methods=['GET']) | |
def home_page(): | |
query = str(request.args.get('question')) #/request/admin/?question=Dhina | |
agent_response = agent.run(query) | |
data_set = {'Message': agent_response} | |
json_dump = json.dumps(data_set) | |
return json_dump | |
if __name__ == "__main__": | |
app.run(port=7778) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<h3 class="display-7">Welcome to Power Platform Admin Copilot</h3> | |
<div class="form-group"> | |
<p> | |
<textarea id="txtAction" name="input" class="form-control col-md-6" placeholder="What action do you want me to take?"></textarea> | |
</p> | |
<p><button id="btnAction" class="btn btn-primary">Submit</button> </p> | |
<label id="lblResult" for="static-info" class="control-label text-left p-3 mb-2 bg-success text-white" style="display: none;"></label> | |
</div> | |
</div> | |
<script src="<https://code.jquery.com/jquery-3.6.4.min.js>" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script> | |
<script type="text/javascript"> | |
$("#btnAction").click(function() | |
{ | |
$("#lblResult").show(); | |
//call agent from Python agent | |
$("#lblResult").text("Using LLM to determine the actions required and in what order...") | |
$.get( "<https://localhost:7778/request/admin/?question=>" + $("#txtAction").val()) | |
.done(function( data ) { | |
var obj = jQuery.parseJSON(data); | |
$("#lblResult").text(obj.Message); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tools = [ | |
Tool( | |
name="Assign Security Role", func=assign_security_role, description=description_sr | |
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request_format_sr = '{{"user":"<user name>","role":"<role>"}}' | |
description_sr = f'helps to assign security role to the user. For example, if you get a query "assign security role system administrator to the user Dhina", the role is System Administrator and Dhina is the user name. Another example would be "assign the role Supervisor to John", then Supervisor is the role and John is the user name. Input should be JSON in the following format: {request_format_sr}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assign_security_role_DVAPI(user: str = None, role: str = None) -> str: | |
print("\nCalling Dataverse API to assign '" + role + "' security role to user '" + user + "'") | |
def assign_security_role(json_request: str) -> str: | |
arguments_dictionary = json.loads(json_request) | |
user = arguments_dictionary["user"] | |
role = arguments_dictionary["role"] | |
return assign_security_role_DVAPI(user=user, role=role) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assign_security_role_DVAPI(user: str = None, role: str = None) -> str: | |
print("\nCalling Dataverse API to assign '" + role + "' security role to user '" + user + "'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
agent = initialize_agent( | |
tools, | |
llm, | |
agent="zero-shot-react-description", | |
verbose=True | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parser = argparse.ArgumentParser(description='agent calling power platform api to perform actions') | |
parser.add_argument('-q', '--question', dest='question', type=str, help='question to submit to the agent. Enclose the question sentence in quotes.', required=True) | |
args = parser.parse_args() | |
agent.run(args.question) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python lc-agent-cli/lc_pp_cli_agent.py -q 'assign system administrator role to the user dhina' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python lc-agent-cli/lc_pp_cli_agent.py -q 'assign system administrator role to the user dhina and add to the team Contact Center Agents' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#parser = argparse.ArgumentParser(description='agent calling power platform api to perform actions') | |
#parser.add_argument('-q', '--question', dest='question', type=str, help='question to submit to the agent. Enclose the question sentence in quotes.', required=True) | |
#args = parser.parse_args() | |
#agent.run(args.question) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment