This repository contains the code for the Azure OpenAI code migration project. The project aims to migrate code that might contain legacy componets to a new version based on provided API documentation using RAG techniques. The project is built using the Azure OpenAI API and the Azure Functions framework.
- Azure OpenAI is provisioned and models gpt-4.0-turbo and text-embedding-ada-002 are deployed. You can provision the model from the Azure Portal.
- Python and VSCode or any other code editor is installed to run juptyer notebooks.
-
Install Python 3.8 or later. You can download Python from the official Python website.
-
Create Conda environment using the following command:
conda create -n code-migration python=3.10- Activate conda environment and install the required packages using the following command:
pip install -r requirements.txt- Rename secrets.env.rename to secrets.env and fill in the required values.
- Open vectordb_builder.ipynb notebook and attach the conda environment to the notebook.
- Once the vector database is built, run the code_gen_with_rag.ipynb notebook to generate the code.
- Review the generated code and make any necessary changes.
convert the below php code to use paypal orders v2 rest api. Do not omit any parts of the provided code. Provide your fully converted code. Do not produce simplified code. always generate full code.
Item Specifications:
<tr><td colspan="2"><br/><br/><div id="paymentMethods"></div></td></tr>
<tr><td> -- OR -- </td></tr>
<tr><td ><input type="Submit" alt="Proceed to Checkout" class="btn btn-primary btn-large" value="Proceed to Checkout" name="checkout"/></td></tr>
</table>
</div>
</div>
</form>
1) Click on ‘Checkout with PayPal’ button and see the experience.
2) If you get any Firewall warning, add rule to the Firewall to allow incoming connections for your application.
3) Checkout with PayPal using a buyer sandbox account provided on this page. And you're done! Or you can use Proceed to Checkout for Express Checkout Mark flow.
4) The sample code uses default sandbox credentials which are set in paypal_config.php. You can create your own credentials by creating PayPal Seller and Buyer accounts on Sandbox here.
5) Make following changes in paypal_config.php:
- If using your own Sandbox seller account, update PP_USER_SANDBOX, PP_PASSWORD_SANDBOX and PP_SIGNATURE_SANDBOX values with your sandbox credentials
- SANDBOX_FLAG: Kept true for working with Sandbox, it will be false for live.
2) Copy the below <form> .. </form> to your shopping cart page.
<form id="myContainer" action="paypal_ec_redirect.php" method="POST">
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="10.00"></input>
<input type="hidden" name="currencyCodeType" value="USD"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<!--Pass additional input parameters based on your shopping cart. For complete list of all the parameters click here -->
</form>3) Include the following script on your shopping cart page:
<script type="text/javascript">var formdata = {PAYMENTREQUEST_0_AMT: 10 , paymentType:'SALE', PAYMENTREQUEST_0_CURRENCYCODE: 'USD'};
paypal.Button.render({
env: 'sandbox', // sandbox | production locale: 'en_US', style: { size: 'small', // tiny | small | medium color: 'gold', // gold | blue | silver shape: 'pill', // pill | rect label: 'checkout' // checkout | credit }, payment: function(resolve) { jQuery.post(CREATE_PAYMENT_URL,formdata,function(data) { resolve(data); // no data.token, b/c data.token is json format }); }, /* Optional: show a 'Pay Now' button in the checkout flow rather than Continue */ commit: true, onAuthorize: function(data, actions) { var EXECUTE_PAYMENT_URL = 'SetExpressCheckout_URL'; jQuery.post(EXECUTE_PAYMENT_URL, { payToken: data.paymentID, payerId: data.payerID }, function(response) { //if funding error restart if (response === '10486') { actions.restart(); } //success actions.redirect(); }); }, onCancel: function(data, actions) { actions.redirect('{CANCEL_URL}'); } }, '#paymentMethods');
}
</script>
<script src="//www.paypalobjects.com/api/checkout.js" ></script>
4) Open your browser and navigate to your Shopping cart page. Click on 'Checkout with PayPal' button and complete the flow.
5) Read more details on Express Checkout API here.
6) Use of "commit: true" to see "Pay Now" on PayPal Checkout screen is highly recommended to increase buyer conversion rate.
7) For more upgrade details refer Checkout.js v4 Upgrade Guide.
</div>
</div>
var buyerCredentials = [{"email":"ron@hogwarts.com", "password":"qwer1234"},
{"email":"sallyjones1234@gmail.com", "password":"p@ssword1234"},
{"email":"joe@boe.com", "password":"123456789"},
{"email":"hermione@hogwarts.com", "password":"123456789"},
{"email":"lunalovegood@hogwarts.com", "password":"123456789"},
{"email":"ginnyweasley@hogwarts.com", "password":"123456789"},
{"email":"bellaswan@awesome.com", "password":"qwer1234"},
{"email":"edwardcullen@gmail.com", "password":"qwer1234"}];
var randomBuyer = getRandomNumberInRange(0,buyerCredentials.length);
document.getElementById("buyer_email").value =buyerCredentials[randomBuyer].email;
document.getElementById("buyer_password").value =buyerCredentials[randomBuyer].password;
converted code here:
```php
<!DOCTYPE HTML>
<?php
include('header.php');
include('paypal_config.php');
$_SESSION['EXPRESS_MARK'] = NULL;
?>
<div class="span5">
<form class="form" action="create_order.php" method="POST">
<div class="row-fluid">
<div class="span6 inner-span">
<table>
<!-- Product details -->
<tr><h3> DIGITAL SLR CAMERA </h3></tr>
<tr><img src="img/camera.jpg" width="300" height="250"/></tr>
<!-- Additional details omitted for brevity -->
</table>
</div>
<div class="span6 inner-span">
<p class="lead"> Item Specifications:</p>
<table>
<!-- Item details -->
<tr><td>Total Amount:</td><td><input type="text" name="amount" value="17" readonly/></td></tr>
<tr><td>Currency Code:</td><td><select name="currency_code" readonly>
<option value="USD" selected>USD</option></select></td></tr>
<!-- Additional details omitted for brevity -->
<tr><td ><input type="Submit" alt="Proceed to Checkout" class="btn btn-primary btn-large" value="Proceed to Checkout" name="checkout"/></td></tr>
</table>
</div>
</div>
</form>
</div>
<!-- Additional layout code omitted for brevity -->
<!-- Include PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID¤cy=USD"></script>
<script type="text/javascript">
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"amount": {"currency_code": "USD", "value": "17"}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Handle successful transaction here
window.location.replace("success.php");
});
},
onCancel: function(data) {
// Handle cancelation here
window.location.replace("cancel.php");
},
onError: function(err) {
// Handle errors here
console.error(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
<div id="paypal-button-container"></div>
<!-- Additional layout and script code omitted for brevity -->
<?php include('footer.php') ?>
```php
| Item Name: | |
| Item ID: | |
| Description: | |
| Quantity: | |
| Price: | |
| Tax: | |
| Shipping Amount: | |
| Handling Amount: | |
| Shipping Discount: | |
| Insurance Amount: | |
| Total Amount: | |
| /> | |
| Currency Code: | USD |
| Payment Type: |
