-
Notifications
You must be signed in to change notification settings - Fork 203
Trademo branch #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Trademo branch #95
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...microsoft/python/getting-started-agents/3p-tools/Trademo_Global_trade/ReadME.md
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Trademo Shipments And Tariff | ||
|
|
||
| This Python script demonstrates how to use Azure AI to create an agent that queries global trade duties using an OpenAPI specification. | ||
|
|
||
| ## About Tool: | ||
| - Name: Trademo Shipments And Tariff | ||
| - Description: Provides latest duties and past shipment data for trade between multiple countries | ||
|
|
||
|
|
||
| ## Features | ||
| - Creates an Azure AI Project client | ||
| - Sets up OpenAPI connection for global trade data | ||
| - Processes trade duty queries | ||
| - Handles thread/message management | ||
|
|
||
| ## Prerequisites | ||
| - Azure subscription | ||
| - Azure AI Projects resource | ||
| - Python 3.8+ | ||
| - Azure CLI installed and logged in | ||
| - Required Python packages: | ||
| - azure-ai-projects | ||
| - azure-identity | ||
| - jsonref | ||
| - azure-ai-agents | ||
|
|
||
| ## Installation | ||
| Install dependencies: | ||
| ```bash | ||
| pip install azure-ai-projects azure-identity azure-ai-agents jsonref | ||
| ``` | ||
|
|
||
|
|
||
| ## Usage | ||
| Run the script: | ||
| ```bash | ||
| python trademo_and_tariff.py | ||
| ``` | ||
|
|
||
| Before running the sample: | ||
|
|
||
| Obtain the sessionid from trademo which serves as the API_KEY. | ||
|
|
||
| Set up a custom key connection, name the key as 'sessionid' and save the connection name. | ||
|
|
||
| Save that connection name as the PROJECT_OPENAPI_CONNECTION_NAME environment variable | ||
|
|
||
|
|
||
| Set this environment variables with your own values: | ||
| PROJECT_ENDPOINT - the Azure AI Project endpoint, as found in your Foundry Project. | ||
| MODEL - name of the model deployment in the project to use Agents against | ||
| CONNECTION_ID - The ID of connection(connection id should be in the format "/subscriptions/<sub-id>/resourceGroups/<your-rg-name>/providers/Microsoft.CognitiveServices/accounts/<your-ai-services-name>/projects/<your-project-name>/connections/<your-connection-name>") | ||
|
|
||
|
|
||
| ## Example queries processed by the tool: | ||
| - "How many GPUs(HS code 847330) were imported to United States from China in February 2025?" | ||
| - "which were the top countries based on shipment value that exported jewellery(HS code 711319) to usa in 2024?" | ||
| - "Which countries are the biggest exporter of lithium ion battery(HS code 850760) to the US in 2024?" | ||
| - "what is the duty of import for jewllery(HS code = 711319) from India to US?" | ||
| - "Compare current duties on lithium ion batteries(HS code 850760) imported to US" | ||
|
|
||
| ## Notes | ||
| - The script creates and deletes the agent during execution | ||
| - OpenAPI connection requires additional setup in Azure | ||
| - The agent assumes HS 6-digit codes for products automatically | ||
| - Error handling is included for failed runs | ||
|
|
||
|
|
||
| ## Contact | ||
| For any queries, please follow the below escalation matrix: | ||
| - [[email protected]](mailto:[email protected]) | ||
| - [[email protected]](mailto:[email protected]) | ||
| - [[email protected]](mailto:[email protected]) | ||
302 changes: 302 additions & 0 deletions
302
...icrosoft/python/getting-started-agents/3p-tools/Trademo_Global_trade/Trademo_OpenAPI.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,302 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "Trademo Commodity API", | ||
| "version": "v1", | ||
| "description": "This tool provides latest duties, VAT and shipments between any two countries" | ||
| }, | ||
| "servers": [ | ||
| { | ||
| "url": "http://uat.trademo.com/api/v1", | ||
| "description": "UAT Environment" | ||
| } | ||
| ], | ||
| "tags": [ | ||
| { | ||
| "name": "Commodity", | ||
| "description": "Operations related to commodity trade data" | ||
| } | ||
| ], | ||
| "paths": { | ||
| "/commodity_api": { | ||
| "post": { | ||
| "tags": [ | ||
| "Commodity" | ||
| ], | ||
| "summary": "Get Trade related Data", | ||
| "description": "Retrieves import/export data for a specific commodity (HS Code) between two countries within a given time frame.", | ||
| "operationId": "getCommodityData", | ||
| "security": [ | ||
| { | ||
| "ApiKeyAuth": [] | ||
| } | ||
| ], | ||
| "requestBody": { | ||
| "description": "Specify HS Code, trading partners, and time period.", | ||
| "required": true, | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CommodityRequest" | ||
| }, | ||
| "example": { | ||
| "hsCode": "220820", | ||
| "importingCountry": "united states", | ||
| "exportingCountry": "china", | ||
| "tradeTimePeriod": { | ||
| "fromDate": "2023-04-01", | ||
| "toDate": "2025-03-28" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "responses": { | ||
| "200": { | ||
| "description": "Successful retrieval of commodity data", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CommoditySuccessResponse" | ||
| }, | ||
| "example": { | ||
| "status": "Success", | ||
| "data": [ | ||
| { | ||
| "tradingCountry": "China", | ||
| "valueUSD": 5639291, | ||
| "weightKg": 115890, | ||
| "lastReportedTradeMonth": "2025-02", | ||
| "valuePercentageShare": 100.0, | ||
| "weightPercentageShare": 100.0, | ||
| "importDutyMinimum": "Free", | ||
| "importDutyMaximum": "Free", | ||
| "vatMin": "Null", | ||
| "vatMax": "Null", | ||
| "additionalDutyMin": "152.5%", | ||
| "additionalDutyMax": "152.5%" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "400": { | ||
| "description": "Bad Request - Missing or invalid parameters in the payload", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/ErrorResponse400" | ||
| }, | ||
| "example": { | ||
| "status": "failure", | ||
| "message": "Missing parameter tradeTimePeriod->>fromDate in payload." | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "401": { | ||
| "description": "Unauthorized - Invalid or missing Session ID (API Key)", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/ErrorResponse401" | ||
| }, | ||
| "example": { | ||
| "status": "FAILED", | ||
| "message": "Session ID Not Found" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "schemas": { | ||
| "CommodityRequest": { | ||
| "type": "object", | ||
| "required": [ | ||
| "hsCode", | ||
| "importingCountry", | ||
| "exportingCountry", | ||
| "tradeTimePeriod" | ||
| ], | ||
| "properties": { | ||
| "hsCode": { | ||
| "type": "string", | ||
| "description": "SIX digit only Harmonized System (HS) code for the commodity. Sometimes the user will directly provide the HS code, and sometimes it will be derived from the product name.", | ||
| "example": "220820" | ||
| }, | ||
| "importingCountry": { | ||
| "type": "string", | ||
| "description": "The country importing the commodity. This should be in lowercase and should always be the full name of the countries and not the abberiviation.", | ||
| "example": "united states", | ||
| "enum":["afghanistan", "aland islands, finland", "albania", "algeria", "american samoa", "andorra", "angola", "anguilla", "antigua and barbuda", "argentina", "armenia", "aruba", "australia", "austria", "azerbaijan", "bahamas", "bahrain", "bangladesh", "barbados", "belarus", "belgium", "belize", "benin", "bermuda", "bhutan", "bolivia", "bosnia and herzegovina", "botswana", "brazil", "british virgin islands", "brunei", "bulgaria", "burkina faso", "burundi", "cabo verde", "cambodia", "cameroon", "canada", "caribbean netherlands", "cayman islands", "central african republic", "chad", "channel islands", "chile", "china", "christmas island", "cocos islands", "colombia", "comoros", "cook islands", "costa rica", "croatia", "cuba", "curacao", "cyprus", "czech republic", "democratic republic of the congo", "denmark", "djibouti", "dominica", "dominican republic", "east timor", "ecuador", "egypt", "el salvador", "equatorial guinea", "eritrea", "estonia", "eswatini", "ethiopia", "falkland islands", "faroe islands", "fiji", "finland", "france", "french guiana, france", "french polynesia", "gabon", "gambia", "georgia", "germany", "ghana", "gibraltar", "greece", "grenada", "guadeloupe, france", "guam", "guatemala", "guernsey", "guinea", "guinea-bissau", "guyana", "haiti", "honduras", "hong kong", "hungary", "iceland", "india", "indonesia", "iran", "iraq", "ireland", "isle of man", "israel", "italy", "ivory coast", "jamaica", "japan", "jersey", "jordan", "kazakhstan", "kenya", "kiribati", "kosovo", "kuwait", "kyrgyzstan", "laos", "latvia", "lebanon", "lesotho", "liberia", "libya", "liechtenstein", "lithuania", "luxembourg", "macau", "madagascar", "malawi", "malaysia", "maldives", "mali", "malta", "marshall islands", "martinique, france", "mauritania", "mauritius", "mayotte", "mexico", "micronesia", "moldova", "monaco", "mongolia", "montenegro", "montserrat", "morocco", "mozambique", "myanmar", "namibia", "nauru", "nepal", "netherlands", "netherlands antilles", "new caledonia", "new zealand", "nicaragua", "niger", "nigeria", "niue", "norfolk island, australia", "north korea", "north macedonia", "northern mariana islands", "norway", "oman", "pakistan", "palau", "palestine", "panama", "papua new guinea", "paraguay", "peru", "philippines", "pitcairn islands", "poland", "portugal", "puerto rico", "qatar", "republic of the congo", "reunion, france", "romania", "russia", "rwanda", "saint barthelemy", "saint helena", "saint kitts and nevis", "saint lucia", "saint martin", "saint pierre and miquelon", "saint vincent and the grenadines", "samoa", "san marino", "sao tome and principe", "saudi arabia", "senegal", "serbia", "seychelles", "sierra leone", "singapore", "sint maarten", "slovakia", "slovenia", "solomon islands", "somalia", "south africa", "south georgia and the south sandwich islands", "south korea", "south sudan", "spain", "sri lanka", "sudan", "suriname", "svalbard and jan mayen", "sweden", "switzerland", "syria", "taiwan", "tajikistan", "tanzania", "thailand", "tierra del fuego", "togo", "tokelau", "tonga", "trinidad and tobago", "tunisia", "turkey", "turkmenistan", "turks and caicos islands", "tuvalu", "u.s. virgin islands", "uganda", "ukraine", "united arab emirates", "united kingdom", "united states", "uruguay", "uzbekistan", "vanuatu", "vatican city", "venezuela", "vietnam", "wallis and futuna", "yemen", "zambia", "zimbabwe"] | ||
| }, | ||
| "exportingCountry": { | ||
| "type": "string", | ||
| "description": "The country exporting the commodity. This should be in lowercase and should always be the full name of the countries and not the abberiviation.", | ||
| "example": "china", | ||
| "enum": ["","afghanistan", "aland islands, finland", "albania", "algeria", "american samoa", "andorra", "angola", "anguilla", "antigua and barbuda", "argentina", "armenia", "aruba", "australia", "austria", "azerbaijan", "bahamas", "bahrain", "bangladesh", "barbados", "belarus", "belgium", "belize", "benin", "bermuda", "bhutan", "bolivia", "bosnia and herzegovina", "botswana", "brazil", "british virgin islands", "brunei", "bulgaria", "burkina faso", "burundi", "cabo verde", "cambodia", "cameroon", "canada", "caribbean netherlands", "cayman islands", "central african republic", "chad", "channel islands", "chile", "china", "christmas island", "cocos islands", "colombia", "comoros", "cook islands", "costa rica", "croatia", "cuba", "curacao", "cyprus", "czech republic", "democratic republic of the congo", "denmark", "djibouti", "dominica", "dominican republic", "east timor", "ecuador", "egypt", "el salvador", "equatorial guinea", "eritrea", "estonia", "eswatini", "ethiopia", "falkland islands", "faroe islands", "fiji", "finland", "france", "french guiana, france", "french polynesia", "gabon", "gambia", "georgia", "germany", "ghana", "gibraltar", "greece", "grenada", "guadeloupe, france", "guam", "guatemala", "guernsey", "guinea", "guinea-bissau", "guyana", "haiti", "honduras", "hong kong", "hungary", "iceland", "india", "indonesia", "iran", "iraq", "ireland", "isle of man", "israel", "italy", "ivory coast", "jamaica", "japan", "jersey", "jordan", "kazakhstan", "kenya", "kiribati", "kosovo", "kuwait", "kyrgyzstan", "laos", "latvia", "lebanon", "lesotho", "liberia", "libya", "liechtenstein", "lithuania", "luxembourg", "macau", "madagascar", "malawi", "malaysia", "maldives", "mali", "malta", "marshall islands", "martinique, france", "mauritania", "mauritius", "mayotte", "mexico", "micronesia", "moldova", "monaco", "mongolia", "montenegro", "montserrat", "morocco", "mozambique", "myanmar", "namibia", "nauru", "nepal", "netherlands", "netherlands antilles", "new caledonia", "new zealand", "nicaragua", "niger", "nigeria", "niue", "norfolk island, australia", "north korea", "north macedonia", "northern mariana islands", "norway", "oman", "pakistan", "palau", "palestine", "panama", "papua new guinea", "paraguay", "peru", "philippines", "pitcairn islands", "poland", "portugal", "puerto rico", "qatar", "republic of the congo", "reunion, france", "romania", "russia", "rwanda", "saint barthelemy", "saint helena", "saint kitts and nevis", "saint lucia", "saint martin", "saint pierre and miquelon", "saint vincent and the grenadines", "samoa", "san marino", "sao tome and principe", "saudi arabia", "senegal", "serbia", "seychelles", "sierra leone", "singapore", "sint maarten", "slovakia", "slovenia", "solomon islands", "somalia", "south africa", "south georgia and the south sandwich islands", "south korea", "south sudan", "spain", "sri lanka", "sudan", "suriname", "svalbard and jan mayen", "sweden", "switzerland", "syria", "taiwan", "tajikistan", "tanzania", "thailand", "tierra del fuego", "togo", "tokelau", "tonga", "trinidad and tobago", "tunisia", "turkey", "turkmenistan", "turks and caicos islands", "tuvalu", "u.s. virgin islands", "uganda", "ukraine", "united arab emirates", "united kingdom", "united states", "uruguay", "uzbekistan", "vanuatu", "vatican city", "venezuela", "vietnam", "wallis and futuna", "yemen", "zambia", "zimbabwe"] | ||
| }, | ||
| "tradeTimePeriod": { | ||
| "type": "object", | ||
| "required": [ | ||
| "fromDate", | ||
| "toDate" | ||
| ], | ||
| "properties": { | ||
| "fromDate": { | ||
| "type": "string", | ||
| "format": "date", | ||
| "description": "Start date of the trade period (YYYY-MM-DD).", | ||
| "example": "2023-04-01" | ||
| }, | ||
| "toDate": { | ||
| "type": "string", | ||
| "format": "date", | ||
| "description": "End date of the trade period (YYYY-MM-DD).", | ||
| "example": "2025-03-28" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "CommoditySuccessResponse": { | ||
| "type": "object", | ||
| "properties": { | ||
| "status": { | ||
| "type": "string", | ||
| "enum": ["Success"], | ||
| "example": "Success" | ||
| }, | ||
| "data": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/CommodityData" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "CommodityData": { | ||
| "type": "object", | ||
| "properties": { | ||
| "tradingCountry": { | ||
| "type": "string", | ||
| "description": "The exporting country's name.", | ||
| "example": "China" | ||
| }, | ||
| "valueUSD": { | ||
| "type": "number", | ||
| "format": "float", | ||
| "description": "Total trade value in USD.", | ||
| "example": 5639291 | ||
| }, | ||
| "weightKg": { | ||
| "type": "number", | ||
| "format": "float", | ||
| "description": "Total trade weight in Kilograms.", | ||
| "example": 115890 | ||
| }, | ||
| "lastReportedTradeMonth": { | ||
| "type": "string", | ||
| "description": "The latest month for which trade data is included (YYYY-MM).", | ||
| "example": "2025-02" | ||
| }, | ||
| "valuePercentageShare": { | ||
| "type": "number", | ||
| "format": "float", | ||
| "description": "Percentage share of the trade value.", | ||
| "example": 100.0 | ||
| }, | ||
| "weightPercentageShare": { | ||
| "type": "number", | ||
| "format": "float", | ||
| "description": "Percentage share of the trade weight.", | ||
| "example": 100.0 | ||
| }, | ||
| "importDutyMinimum": { | ||
| "type": "string", | ||
| "description": "Minimum applicable import duty.", | ||
| "example": "Free" | ||
| }, | ||
| "importDutyMaximum": { | ||
| "type": "string", | ||
| "description": "Maximum applicable import duty.", | ||
| "example": "Free" | ||
| }, | ||
| "vatMin": { | ||
| "type": "string", | ||
| "description": "Minimum applicable Value Added Tax (VAT).", | ||
| "example": "Null" | ||
| }, | ||
| "vatMax": { | ||
| "type": "string", | ||
| "description": "Maximum applicable Value Added Tax (VAT).", | ||
| "example": "Null" | ||
| }, | ||
| "additionalDutyMin": { | ||
| "type": "string", | ||
| "description": "Minimum applicable additional duties.", | ||
| "example": "152.5%" | ||
| }, | ||
| "additionalDutyMax": { | ||
| "type": "string", | ||
| "description": "Maximum applicable additional duties.", | ||
| "example": "152.5%" | ||
| } | ||
| } | ||
| }, | ||
| "ErrorResponse400": { | ||
| "type": "object", | ||
| "required": [ | ||
| "status", | ||
| "message" | ||
| ], | ||
| "properties": { | ||
| "status": { | ||
| "type": "string", | ||
| "enum": ["failure"], | ||
| "description": "Indicates a failed request due to client error.", | ||
| "example": "failure" | ||
| }, | ||
| "message": { | ||
| "type": "string", | ||
| "description": "Details about the error.", | ||
| "example": "Missing parameter tradeTimePeriod->>fromDate in payload." | ||
| } | ||
| } | ||
| }, | ||
| "ErrorResponse401": { | ||
| "type": "object", | ||
| "required": [ | ||
| "status", | ||
| "message" | ||
| ], | ||
| "properties": { | ||
| "status": { | ||
| "type": "string", | ||
| "enum": ["FAILED"], | ||
| "description": "Indicates a failed request due to authentication error.", | ||
| "example": "FAILED" | ||
| }, | ||
| "message": { | ||
| "type": "string", | ||
| "description": "Details about the authentication error.", | ||
| "example": "Session ID Not Found" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "securitySchemes": { | ||
| "ApiKeyAuth": { | ||
| "type": "apiKey", | ||
| "in": "header", | ||
| "name": "sessionid", | ||
| "description": "API Key (referred to as sessionid) passed in the header for authentication." | ||
| } | ||
| } | ||
| } | ||
| } |
Binary file added
BIN
+128 KB
...thon/getting-started-agents/3p-tools/Trademo_Global_trade/custom_connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.