This function calls a text generation model to support tasks such as text-to-text conversations and Q&A.
Currently, only PolarDB PostgreSQL Standard Edition clusters in the China (Beijing) region support calls to built-in models.
Syntax
text AI_Text_Generation(text content);
text AI_Text_Generation(text content, text model_id);Parameters
Parameter Name | Description |
content | The input text for the conversation. |
model_id | The ID of the model. If you do not specify this parameter, the built-in model |
Return value
Returns the generated text.
Description
You can use this function directly without creating a model. By default, it calls the built-in model
_dashscope/text-generation/deepseek-r1to perform tasks such as text-to-text conversations and Q&A.You can call other text understanding models by specifying the model_id parameter.
For more information about the built-in model
_dashscope/text-generation/deepseek-r1, see DeepSeek large language model.
Preparations
The built-in model for this function is integrated from the text-to-text models provided by Alibaba Cloud Model Studio.
Set the model's token information: Use the AI_SetModelToken function to set the API key for your Alibaba Cloud Model Studio account.
Modify the model call address: Use the AI_AlterModel function to modify the call address of the built-in model. Replace the original address,
https://dashscope.aliyuncs.com, with the PrivateLink endpoint for Alibaba Cloud Model Studio,https://vpc-cn-beijing.dashscope.aliyuncs.com. For example:SELECT polar_ai.AI_AlterModel('_dashscope/text-generation/deepseek-r1', model_url=>'https://vpc-cn-beijing.dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation');
Examples
Do not specify the model_id parameter.
SELECT polar_ai.ai_text_generation('What is the population of China?'::text);The following result is returned:
ai_text_generation -------------------------------------------------------------------------------------------------------------------------------------------------- As of 2023, the total population of China (including **the Chinese mainland, Hong Kong, Macao, and Taiwan**) is approximately **1.412 billion**. The breakdown is as follows: + + 1. **The Chinese mainland**: Approximately **1.402 billion** (preliminary statistics from the National Bureau of Statistics for 2023). + - Notably, the population of the Chinese mainland experienced a slight decline in 2023 (a decrease of about 2.08 million from 2022). This is the first negative growth since 1961, mainly due to low birth rates and an aging population. + + 2. **Taiwan region**: Approximately 23.49 million (data released by Taiwan authorities in 2023). + 3. **Hong Kong Special Administrative Region**: Approximately 7.47 million (statistics from the Hong Kong government in 2023). + 4. **Macao Special Administrative Region**: Approximately 680,000 (statistics from the Macao government in 2023). + + **Key background information**: + - China was once one of the fastest-growing countries in terms of population. However, in recent years, the birth rate has continued to decline (the total fertility rate was about 1.0 in 2023). Coupled with an aging population (over 20% of the population is over 60 years old), the population structure faces challenges. + - At the policy level, there has been a shift from "family planning" to encouraging childbirth (such as the three-child policy), but the effects are not yet significant. + + For the latest dynamic data, follow the annual reports of the National Bureau of Statistics or the reports from the United Nations Population Fund. (1 row)Call the function and specify the model_id parameter. In this example, the model_id is set to the built-in model
_dashscope/text-generation/deepseek-r1.SELECT polar_ai.ai_text_generation('What is the origin of the Dragon Boat Festival?'::text, '_dashscope/text-generation/deepseek-r1');The following result is returned:
ai_text_generation ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- The origin of the Dragon Boat Festival is related to various historical legends and ancient customs. The most widely known story is the commemoration of the patriotic poet Qu Yuan from the Warring States period. However, other explanations exist in different regions and cultural backgrounds. The following are the main theories: + + --- + + ### **1. Commemorating Qu Yuan (The mainstream theory)** + - **Background**: Qu Yuan (circa 340 BC–278 BC) was a minister and poet of the State of Chu during the Warring States period. He was exiled after being ostracized by nobles for advocating reforms to resist the State of Qin. After the capital of Chu was captured by the Qin army, Qu Yuan, in despair, drowned himself in the Miluo River. + - **Associated legends**: + - The local people rowed boats to retrieve his body, which evolved into the custom of **dragon boat racing**. + - To prevent fish and shrimp from eating Qu Yuan's body, the people threw rice dumplings into the river. This became the origin of **zongzi** (sticky rice dumplings). + - **Cultural impact**: This story was widely spread due to Qu Yuan's patriotic image and literary achievements (such as "Li Sao"), becoming the mainstream explanation for the Dragon Boat Festival. + + --- + + ### **2. Commemorating other historical figures** + - **Wu Zixu (in the Wu-Yue region)**: A famous general of the State of Wu during the Spring and Autumn period. After being falsely accused, he committed suicide and his body was thrown into the river. Later generations commemorated him on the fifth day of the fifth lunar month. + - **Cao E (in the Zhejiang region)**: A young girl from the Eastern Han Dynasty who drowned herself in a river while searching for her father. Her filial piety was said to have moved the local community, leading to a commemorative custom. + - **Jie Zitui (in parts of the Shanxi region)**: Associated with the Cold Food Festival, but some regions combine his commemoration with the Dragon Boat Festival. + + --- + + ### **3. Ancient summer solstice customs and warding off evil spirits and plagues** + The Dragon Boat Festival may have originally been related to the summer solstice. The ancients believed that the fifth lunar month (the "evil month") was a time of heat, humidity, and venomous creatures, requiring ceremonies to ward off evil: + - **Hanging mugwort and calamus**: The scent of these herbs was believed to repel insects and prevent plagues. + - **Wearing perfume pouches and tying five-color threads**: Symbolized warding off illness and praying for good fortune. + - **Drinking realgar wine**: To repel snakes and insects and prevent diseases. + + --- + + ### **4. Dragon totem worship (Southern Baiyue culture)** + Archaeological findings show that the Baiyue peoples in the middle and lower reaches of the Yangtze River had a custom of holding dragon boat races in the fifth lunar month to worship the water god. After merging with the culture of the Central Plains, this became part of the Dragon Boat Festival. + + --- + + ### **Summary** + The Dragon Boat Festival is the result of the fusion of multiple cultural factors. The story of **commemorating Qu Yuan** became mainstream due to literary dissemination and patriotic sentiment. However, the core of the festival still revolves around the ancient traditions of **warding off evil and praying for health during the summer**. In 2009, the Dragon Boat Festival was inscribed on the UNESCO Representative List of the Intangible Cultural Heritage of Humanity, becoming an important symbol of Chinese culture. (1 row)