You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code sample helps create agents that handle multilingual text processing, including dynamic language detection and bidirectional translation using Azure AI Translator service.
3
+
This code sample helps create agents that handle multilingual text processing, including dynamic language detection and bidirectional translation using Azure AI Translator service.
4
4
5
5
**IMPORTANT NOTE:** Starter templates, instructions, code samples and resources in this msft-agent-samples file (“samples”) are designed to assist in accelerating development of agents for specific scenarios. It is important that you review all provided resources and carefully test Agent behavior in the context of your use case: ([Learn More](https://learn.microsoft.com/en-us/legal/cognitive-services/agents/transparency-note?context=%2Fazure%2Fai-services%2Fagents%2Fcontext%2Fcontext)).
6
6
7
7
Certain Agent offerings may be subject to legal and regulatory requirements, may require licenses, or may not be suitable for all industries, scenarios, or use cases. By using any sample, you are acknowledging that Agents or other output created using that sample are solely your responsibility, and that you will comply with all applicable laws, regulations, and relevant safety standards, terms of service, and codes of conduct.
8
8
9
9
## Use Cases
10
+
10
11
1.**Text Translation**: Translate text between multiple languages for seamless communication.
11
12
2.**Business Communication**: Enable businesses to localize content for global audiences.
12
13
3.**Educational Content**: Translate learning materials to make them accessible to non-native speakers.
13
14
14
15
## Architecture Overview
16
+
15
17
The system consists of:
18
+
16
19
- An AI Agent created with Azure AI Agent Service using `gpt-4o` as the base model.
17
-
- Azure AI Translator integrated for language detection and translation.
20
+
- Azure AI Services resource for accessing language translation feature.
18
21
- A Bicep template to automate provisioning of Azure resources.
19
22
20
23
```text
24
+
21
25
+----------------+
22
26
| User Query |
23
27
| (Any Language) |
@@ -39,6 +43,7 @@ The system consists of:
39
43
## Setup Instructions
40
44
41
45
### Prerequisites
46
+
42
47
- Python 3.8+
43
48
- Azure CLI
44
49
- Azure subscription
@@ -55,55 +60,67 @@ The system consists of:
55
60
- For more info about Azure AI Translator service, see [Text translation Overview](https://learn.microsoft.com/en-us/azure/ai-services/translator/text-translation/overview)
56
61
57
62
### Steps
58
-
1.**Clone the Repository**
59
63
60
-
2.**Set Config Variables**
64
+
1. Clone the Repository in the folder of your choice
|`project_endpoint`| Endpoint for the project this agent is using |
71
75
|`model_name`| Name of the model deployment to be used for the Agent |
72
76
|`translator_resource_connection_name`| Name of the translator resource connection added in the agent project |
73
77
|`connection_id`| Connection ID for the translator resource connection added in the agent project |
74
78
79
+
3. Install the requirements
80
+
81
+
It is recommended to use a virtual environment (via venv or similar) to isolate installation requirements of this sample from other samples.
82
+
83
+
```bash
84
+
pip install -r requirements.txt
85
+
```
86
+
87
+
4. Run the template script
88
+
89
+
```bash
90
+
python template.py
91
+
```
92
+
75
93
## Sample Data Instructions
94
+
76
95
You can try the sample user messages and test the interaction by invoking the agent with prompts as listed in the next section.
77
96
78
97
## Example Agent Interaction
79
-
### User:
80
-
Translate this Chinese poem to English: 白日依山尽,黄河入海流
81
98
82
-
### Agent:
83
-
At the end of the day, the Yellow River flows into the sea.
99
+
```text
100
+
>User: Translate this Chinese poem to English: 白日依山尽,黄河入海流
101
+
102
+
>Agent: At the end of the day, the Yellow River flows into the sea.
84
103
85
-
### User:
86
-
translate this text to Chinese, Spanish, and Korean: Translator Agent handles multilingual text processing, including dynamic language detection and bidirectional translation using Translator service. The translator agent is triggered when the user message has the “translation intent”.
104
+
>User: translate this text to Chinese, Spanish, and Korean: Translator Agent handles multilingual text processing, including dynamic language detection and bidirectional translation using Translator service. The translator agent is triggered when the user message has the “translation intent”.
Spanish: Translator Agent se encarga del procesamiento de texto multilingüe, incluida la detección dinámica de idiomas y la traducción bidireccional mediante el servicio Translator. El agente traductor se activa cuando el mensaje del usuario tiene la "intención de traducción".
93
-
Korean: Translator Agent는 Translator 서비스를 사용하여 동적 언어 감지 및 양방향 번역을 포함한 다국어 텍스트 처리를 처리합니다. 변환기 에이전트는 사용자 메시지에 "번역 의도"가 있을 때 트리거됩니다.
Spanish: Translator Agent se encarga del procesamiento de texto multilingüe, incluida la detección dinámica de idiomas y la traducción bidireccional mediante el servicio Translator. El agente traductor se activa cuando el mensaje del usuario tiene la "intención de traducción".
110
+
Korean: Translator Agent는 Translator 서비스를 사용하여 동적 언어 감지 및 양방향 번역을 포함한 다국어 텍스트 처리를 처리합니다. 변환기 에이전트는 사용자 메시지에 "번역 의도"가 있을 때 트리거됩니다.
94
111
95
-
### User:
96
-
localize this text to Japanese and Germany: The agent can detect the source language for the input text unless the source language is defined in the user message.
112
+
> User: localize this text to Japanese and Germany: The agent can detect the source language for the input text unless the source language is defined in the user message.
Copy file name to clipboardExpand all lines: samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/config.yaml
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@ model_name:
7
7
# The connection name of the above resource when added in the Azure AI Foundry portal to your project
8
8
translator_resource_connection_name:
9
9
10
+
# the region when the translator resource/AI service resource was created.
11
+
translator_resource_region:
12
+
10
13
# Go to the page of above connection in the Azure AI Foundry portal, then construct the connection ID by append "/connections/<language_resource_connection_name>" to the wsid parameter value in the page URL.
11
14
# For example, if the connection page URL contains "wsid=/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/<account_name>/projects/<project_name>",
12
15
# Then the connection ID is /subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/<account_name>/projects/<project_name>/connections/<language_resource_connection_name>
Copy file name to clipboardExpand all lines: samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/requirements.txt
Copy file name to clipboardExpand all lines: samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/template.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,8 @@
39
39
# Create the agent
40
40
agent=agents_client.create_agent(
41
41
model=model_name,
42
-
name="My_Translator_Agent",
43
-
instructions="You are a translation agent. The user can use any language to interface with you and please answer in the same language as the customer. "+
42
+
name="ms-translator",
43
+
instructions="You are a translation agent. The user can use any language to interface with you and please answer in the same language as the user used. "+
44
44
"Any translation asks must be performed via a call to the translator_api. In case of failure to call the translator_api indicate what was the failure",
0 commit comments