Using APIs to Call an Application
The agent development platform allows you to call APIs for created applications. Before calling an application, create an application by referring to Basic Settings.
Obtaining the Call Path
To obtain the call path of an application, perform the following steps:
- Log in to ModelArts Studio and click Agent Dev.
- In the navigation pane, choose Application Management. In the function list on the top of the page, click Single-Agent Application. On the application development page that is displayed, click
> Call Path of the required application.
Figure 1 Obtaining the call path of an application
- In the Call Path dialog box, click Copy Path.
The conversation_id parameter indicates the session ID, which uniquely identifies a session. You can set the session ID to any value in the standard UUID format. For example, conversation_id in the following figure can be replaced with 550e8400-e29b-41d4-a716-446655440000.
Figure 2 Call path details
Obtaining a Token
Obtain the token by following the instructions provided in section "Calling REST APIs" > "Authentication" in API Reference.
Using Postman to Call APIs
- Create a POST request in Postman and enter the API of the application.
- Set the request header parameters.
- KEY: Content-Type; VALUE: application/json
- The header parameter X-Auth-Token is mandatory, and the parameter value is the token obtained in Obtaining a Token.
Figure 3 Configuring the request header
- In Postman, choose Body > raw. The following is an example of configuring the request body: The query parameter is a question raised by the user, and is used as an input of the application.
{ "query": "Introduce the scenic spots in Beijing."} - Click Send on Postman to send the request. If status code 200 is returned, the API is successfully called. The following is an example response:
data:{"event":"start","createdTime":1744636611503}data:{"event":"message","content":"Beijing","createdTime":1744636611816}data:{"event":"message","content":"Yes","createdTime":1744636611854}data:{"event":"message","content":"China","createdTime":1744636611890}data:{"event":"message","content":"Capital","createdTime":1744636611925}...data:{"event":"message","content":"Anytime","createdTime":1744636624119}data:{"event":"message","content":"Tell me","createdTime":1744636624154}data:{"event":"message","content":".","createdTime":1744636624190}data:{"event":"statistic_data","latency":{"overall":13.17},"createdTime":1744636624265}data:{"event":"summary_response","content":"Beijing is the capital of China. It has rich historical and cultural heritage and modern city landscapes. Here are some famous tourist attractions:\n\n###Historical and cultural attractions\n- **Imperial Palace**\n - Features: The largest palace complex in the world, the palace of the Ming and Qing Dynasties, showcased the ancient Chinese architectural art and royal culture. \n - Suggestion: You are advised to reserve at least half a day for the visit. It is recommended that you purchase tickets online in advance to avoid queuing. \n\n- **Tian'anmen Square**\n - Features: The world's largest city square, surrounded by important buildings such as the Monument of People's Heroes and Chairman Mao's Memorial Hall. \n-Suggestion: Visit in the morning or evening to avoid peak hours. \n\n- **Summer Palace**\n-Features: The most complete Royal Garden in China, based on Kunming Lake and Wanshou Mountain, integrates the design style of Jiangnan Garden. \n - Suggestion: Suitable for family travel. You can take a cruise boat to visit Kunming Lake. \n\n###Modern Scenic Spots\n- **Bird's Nest and Water Cube**\n - Features: The main venue of the 2008 Beijing Olympic Games has become a landmark building in Beijing. \n -Suggestion: You can see the light show at night. \n\n- **798 Art Zone**\n - Features: A collection of art exhibitions and creative studios, a paradise for art enthusiasts. \n - Suggestion: It is suitable for visiting in the afternoon or evening. You can enjoy the artistic atmosphere here. \n\n- **Sanlitun**\n - Feature: Beijing's most fashionable shopping and entertainment area with many international brand stores and restaurants. \n-Suggestion: It is recommended that you go to Beijing at night to experience nightlife in Beijing. \n\nWe hope that the information is helpful for your travel plan. If you need more detailed trip planning or other information, please feel free to let me know.","role":"assistant","createdTime":1744636624266}data:{"event":"done","createdTime":1744636624276}
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot