Skip to content

Commit 9c3ea2f

Browse files
authored
Merge pull request #95 from Vanshmo-sher/trademo_branch
Trademo branch
2 parents 38611a3 + 10f7e4d commit 9c3ea2f

File tree

4 files changed

+480
-0
lines changed

4 files changed

+480
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Trademo Shipments And Tariff
2+
3+
This Python script demonstrates how to use Azure AI to create an agent that queries global trade duties using an OpenAPI specification.
4+
5+
## About Tool:
6+
- Name: Trademo Shipments And Tariff
7+
- Description: Provides latest duties and past shipment data for trade between multiple countries
8+
9+
10+
## Features
11+
- Creates an Azure AI Project client
12+
- Sets up OpenAPI connection for global trade data
13+
- Processes trade duty queries
14+
- Handles thread/message management
15+
16+
## Prerequisites
17+
- Azure subscription
18+
- Azure AI Projects resource
19+
- Python 3.8+
20+
- Azure CLI installed and logged in
21+
- Required Python packages:
22+
- azure-ai-projects
23+
- azure-identity
24+
- jsonref
25+
- azure-ai-agents
26+
27+
## Installation
28+
Install dependencies:
29+
```bash
30+
pip install azure-ai-projects azure-identity azure-ai-agents jsonref
31+
```
32+
33+
34+
## Usage
35+
Run the script:
36+
```bash
37+
python trademo_and_tariff.py
38+
```
39+
40+
Before running the sample:
41+
42+
Obtain the sessionid from trademo which serves as the API_KEY.
43+
44+
Set up a custom key connection, name the key as 'sessionid' and save the connection name.
45+
46+
Save that connection name as the PROJECT_OPENAPI_CONNECTION_NAME environment variable
47+
48+
49+
Set this environment variables with your own values:
50+
PROJECT_ENDPOINT - the Azure AI Project endpoint, as found in your Foundry Project.
51+
MODEL - name of the model deployment in the project to use Agents against
52+
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>")
53+
54+
55+
## Example queries processed by the tool:
56+
- "How many GPUs(HS code 847330) were imported to United States from China in February 2025?"
57+
- "which were the top countries based on shipment value that exported jewellery(HS code 711319) to usa in 2024?"
58+
- "Which countries are the biggest exporter of lithium ion battery(HS code 850760) to the US in 2024?"
59+
- "what is the duty of import for jewllery(HS code = 711319) from India to US?"
60+
- "Compare current duties on lithium ion batteries(HS code 850760) imported to US"
61+
62+
## Notes
63+
- The script creates and deletes the agent during execution
64+
- OpenAPI connection requires additional setup in Azure
65+
- The agent assumes HS 6-digit codes for products automatically
66+
- Error handling is included for failed runs
67+
68+
69+
## Contact
70+
For any queries, please follow the below escalation matrix:
71+
72+
73+
Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Trademo Commodity API",
5+
"version": "v1",
6+
"description": "This tool provides latest duties, VAT and shipments between any two countries"
7+
},
8+
"servers": [
9+
{
10+
"url": "http://uat.trademo.com/api/v1",
11+
"description": "UAT Environment"
12+
}
13+
],
14+
"tags": [
15+
{
16+
"name": "Commodity",
17+
"description": "Operations related to commodity trade data"
18+
}
19+
],
20+
"paths": {
21+
"/commodity_api": {
22+
"post": {
23+
"tags": [
24+
"Commodity"
25+
],
26+
"summary": "Get Trade related Data",
27+
"description": "Retrieves import/export data for a specific commodity (HS Code) between two countries within a given time frame.",
28+
"operationId": "getCommodityData",
29+
"security": [
30+
{
31+
"ApiKeyAuth": []
32+
}
33+
],
34+
"requestBody": {
35+
"description": "Specify HS Code, trading partners, and time period.",
36+
"required": true,
37+
"content": {
38+
"application/json": {
39+
"schema": {
40+
"$ref": "#/components/schemas/CommodityRequest"
41+
},
42+
"example": {
43+
"hsCode": "220820",
44+
"importingCountry": "united states",
45+
"exportingCountry": "china",
46+
"tradeTimePeriod": {
47+
"fromDate": "2023-04-01",
48+
"toDate": "2025-03-28"
49+
}
50+
}
51+
}
52+
}
53+
},
54+
"responses": {
55+
"200": {
56+
"description": "Successful retrieval of commodity data",
57+
"content": {
58+
"application/json": {
59+
"schema": {
60+
"$ref": "#/components/schemas/CommoditySuccessResponse"
61+
},
62+
"example": {
63+
"status": "Success",
64+
"data": [
65+
{
66+
"tradingCountry": "China",
67+
"valueUSD": 5639291,
68+
"weightKg": 115890,
69+
"lastReportedTradeMonth": "2025-02",
70+
"valuePercentageShare": 100.0,
71+
"weightPercentageShare": 100.0,
72+
"importDutyMinimum": "Free",
73+
"importDutyMaximum": "Free",
74+
"vatMin": "Null",
75+
"vatMax": "Null",
76+
"additionalDutyMin": "152.5%",
77+
"additionalDutyMax": "152.5%"
78+
}
79+
]
80+
}
81+
}
82+
}
83+
},
84+
"400": {
85+
"description": "Bad Request - Missing or invalid parameters in the payload",
86+
"content": {
87+
"application/json": {
88+
"schema": {
89+
"$ref": "#/components/schemas/ErrorResponse400"
90+
},
91+
"example": {
92+
"status": "failure",
93+
"message": "Missing parameter tradeTimePeriod->>fromDate in payload."
94+
}
95+
}
96+
}
97+
},
98+
"401": {
99+
"description": "Unauthorized - Invalid or missing Session ID (API Key)",
100+
"content": {
101+
"application/json": {
102+
"schema": {
103+
"$ref": "#/components/schemas/ErrorResponse401"
104+
},
105+
"example": {
106+
"status": "FAILED",
107+
"message": "Session ID Not Found"
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
},
116+
"components": {
117+
"schemas": {
118+
"CommodityRequest": {
119+
"type": "object",
120+
"required": [
121+
"hsCode",
122+
"importingCountry",
123+
"exportingCountry",
124+
"tradeTimePeriod"
125+
],
126+
"properties": {
127+
"hsCode": {
128+
"type": "string",
129+
"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.",
130+
"example": "220820"
131+
},
132+
"importingCountry": {
133+
"type": "string",
134+
"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.",
135+
"example": "united states",
136+
"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"]
137+
},
138+
"exportingCountry": {
139+
"type": "string",
140+
"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.",
141+
"example": "china",
142+
"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"]
143+
},
144+
"tradeTimePeriod": {
145+
"type": "object",
146+
"required": [
147+
"fromDate",
148+
"toDate"
149+
],
150+
"properties": {
151+
"fromDate": {
152+
"type": "string",
153+
"format": "date",
154+
"description": "Start date of the trade period (YYYY-MM-DD).",
155+
"example": "2023-04-01"
156+
},
157+
"toDate": {
158+
"type": "string",
159+
"format": "date",
160+
"description": "End date of the trade period (YYYY-MM-DD).",
161+
"example": "2025-03-28"
162+
}
163+
}
164+
}
165+
}
166+
},
167+
"CommoditySuccessResponse": {
168+
"type": "object",
169+
"properties": {
170+
"status": {
171+
"type": "string",
172+
"enum": ["Success"],
173+
"example": "Success"
174+
},
175+
"data": {
176+
"type": "array",
177+
"items": {
178+
"$ref": "#/components/schemas/CommodityData"
179+
}
180+
}
181+
}
182+
},
183+
"CommodityData": {
184+
"type": "object",
185+
"properties": {
186+
"tradingCountry": {
187+
"type": "string",
188+
"description": "The exporting country's name.",
189+
"example": "China"
190+
},
191+
"valueUSD": {
192+
"type": "number",
193+
"format": "float",
194+
"description": "Total trade value in USD.",
195+
"example": 5639291
196+
},
197+
"weightKg": {
198+
"type": "number",
199+
"format": "float",
200+
"description": "Total trade weight in Kilograms.",
201+
"example": 115890
202+
},
203+
"lastReportedTradeMonth": {
204+
"type": "string",
205+
"description": "The latest month for which trade data is included (YYYY-MM).",
206+
"example": "2025-02"
207+
},
208+
"valuePercentageShare": {
209+
"type": "number",
210+
"format": "float",
211+
"description": "Percentage share of the trade value.",
212+
"example": 100.0
213+
},
214+
"weightPercentageShare": {
215+
"type": "number",
216+
"format": "float",
217+
"description": "Percentage share of the trade weight.",
218+
"example": 100.0
219+
},
220+
"importDutyMinimum": {
221+
"type": "string",
222+
"description": "Minimum applicable import duty.",
223+
"example": "Free"
224+
},
225+
"importDutyMaximum": {
226+
"type": "string",
227+
"description": "Maximum applicable import duty.",
228+
"example": "Free"
229+
},
230+
"vatMin": {
231+
"type": "string",
232+
"description": "Minimum applicable Value Added Tax (VAT).",
233+
"example": "Null"
234+
},
235+
"vatMax": {
236+
"type": "string",
237+
"description": "Maximum applicable Value Added Tax (VAT).",
238+
"example": "Null"
239+
},
240+
"additionalDutyMin": {
241+
"type": "string",
242+
"description": "Minimum applicable additional duties.",
243+
"example": "152.5%"
244+
},
245+
"additionalDutyMax": {
246+
"type": "string",
247+
"description": "Maximum applicable additional duties.",
248+
"example": "152.5%"
249+
}
250+
}
251+
},
252+
"ErrorResponse400": {
253+
"type": "object",
254+
"required": [
255+
"status",
256+
"message"
257+
],
258+
"properties": {
259+
"status": {
260+
"type": "string",
261+
"enum": ["failure"],
262+
"description": "Indicates a failed request due to client error.",
263+
"example": "failure"
264+
},
265+
"message": {
266+
"type": "string",
267+
"description": "Details about the error.",
268+
"example": "Missing parameter tradeTimePeriod->>fromDate in payload."
269+
}
270+
}
271+
},
272+
"ErrorResponse401": {
273+
"type": "object",
274+
"required": [
275+
"status",
276+
"message"
277+
],
278+
"properties": {
279+
"status": {
280+
"type": "string",
281+
"enum": ["FAILED"],
282+
"description": "Indicates a failed request due to authentication error.",
283+
"example": "FAILED"
284+
},
285+
"message": {
286+
"type": "string",
287+
"description": "Details about the authentication error.",
288+
"example": "Session ID Not Found"
289+
}
290+
}
291+
}
292+
},
293+
"securitySchemes": {
294+
"ApiKeyAuth": {
295+
"type": "apiKey",
296+
"in": "header",
297+
"name": "sessionid",
298+
"description": "API Key (referred to as sessionid) passed in the header for authentication."
299+
}
300+
}
301+
}
302+
}
128 KB
Loading

0 commit comments

Comments
 (0)