"id"
:
"as-v1tqiiqgg4"
,
"object"
:
"chat.completion"
,
"created"
:
1702551146
,
"result"
:
" Hello! I'm happy to help you with your question. The Great Wall of China is an ancient series of fortifications built across the northern borders of China to protect the Chinese Empire from invasions by nomadic tribes. It was constructed over the course of many centuries, with the first versions of the wall being built as early as the 7th century BC. The wall was continuously expanded and fortified over time, with the most famous and impressive sections being built during the Ming Dynasty (1368-1644).\n\nThe Great Wall stretches for over 4,000 miles, making it one of the longest structures ever built. It was originally built to be up to 30 feet high and up to 25 feet wide, with watchtowers and beacon towers spaced at regular intervals. The wall was designed to be impenetrable, with its thick stone and brick construction making it difficult for invaders to breach.\n\nThe Great Wall is not only an engineering marvel but also a testament to the ingenuity and determination of the Chinese people. It has become a symbol of China's rich history and culture, and is now one of the most popular tourist attractions in the country. Visitors can walk or hike along certain sections of the wall, taking in the stunning views of the surrounding countryside and learning about the history of this incredible structure.\n\nI hope this introduction to the Great Wall has been helpful! Is there anything else you would like to know about this amazing historical site?"
,
"is_truncated"
:
false
,
"need_clear_history"
:
false
,
"usage"
:
{
"prompt_tokens"
:
5
,
"completion_tokens"
:
320
,
"total_tokens"
:
325
# 步骤一,获取access_token,替换下列示例中的应用API Key与应用Secret Keycurl'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]'# 步骤二,调用本文API,使用步骤一获取的access_token,替换下列示例中的“调用接口获取的access_token”;替换示例中的创建服务时填写的API名称curl -XPOST 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/[创建服务时填写的api名称}]?access_token=[步骤一调用接口获取的access_token]' -d '{
"messages": [
{"role":"user","content":"Please introduce The Great Wall"},
{"role":"assistant","content":"Hello! I'm happy to help you with your question. The Great Wall of China is an ancient series of fortifications built across the northern borders of China to protect the Chinese Empire from invasions by nomadic tribes. It was constructed over the course of many centuries, with the first versions of the wall being built as early as the 7th century BC. The wall was continuously expanded and fortified over time, with the most famous and impressive sections being built during the Ming Dynasty (1368-1644).\n\nThe Great Wall stretches for over 4,000 miles, making it one of the longest structures ever built. It was originally built to be up to 30 feet high and up to 25 feet wide, with watchtowers and beacon towers spaced at regular intervals. The wall was designed to be impenetrable, with its thick stone and brick construction making it difficult for invaders to breach.\n\nThe Great Wall is not only an engineering marvel but also a testament to the ingenuity and determination of the Chinese people. It has become a symbol of China's rich history and culture, and is now one of the most popular tourist attractions in the country. Visitors can walk or hike along certain sections of the wall, taking in the stunning views of the surrounding countryside and learning about the history of this incredible structure.\n\nI hope this introduction to the Great Wall has been helpful! Is there anything else you would like to know about this amazing historical site?"},
{"role":"user","content": "Please introduce Beijing"}
}'|iconv -f utf-8 -t utf-8
import requests
import json
defget_access_token():
使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key
url ="https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[应用API Key]&client_secret=[应用Secret Key]"
payload = json.dumps("")
headers ={'Content-Type':'application/json','Accept':'application/json'
response = requests.request("POST", url, headers=headers, data=payload)return response.json().get("access_token")defmain():
替换下列示例中的创建服务时填写的API名称
url ="https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/[创建服务时填写的API名称]?access_token="+ get_access_token()
payload = json.dumps({"messages":["role":"user","content":"Please introduce The Great Wall""role":"assistant","content":"Hello! I'm happy to help you with your question. The Great Wall of China is an ancient series of fortifications built across the northern borders of China to protect the Chinese Empire from invasions by nomadic tribes. It was constructed over the course of many centuries, with the first versions of the wall being built as early as the 7th century BC. The wall was continuously expanded and fortified over time, with the most famous and impressive sections being built during the Ming Dynasty (1368-1644).\n\nThe Great Wall stretches for over 4,000 miles, making it one of the longest structures ever built. It was originally built to be up to 30 feet high and up to 25 feet wide, with watchtowers and beacon towers spaced at regular intervals. The wall was designed to be impenetrable, with its thick stone and brick construction making it difficult for invaders to breach.\n\nThe Great Wall is not only an engineering marvel but also a testament to the ingenuity and determination of the Chinese people. It has become a symbol of China's rich history and culture, and is now one of the most popular tourist attractions in the country. Visitors can walk or hike along certain sections of the wall, taking in the stunning views of the surrounding countryside and learning about the history of this incredible structure.\n\nI hope this introduction to the Great Wall has been helpful! Is there anything else you would like to know about this amazing historical site?""role":"user","content":"Please introduce Beijing"
headers ={'Content-Type':'application/json'
response = requests.request("POST", url, headers=headers, data=payload)print(response.text)if __name__ =='__main__':
main()
响应示例(多轮)
HTTP/1.1200 OK
Date: Mon,12 Apr 202106:27:55 GMT
Content-Type: application/json;charset=utf-8
Statement: AI-generated
"id":"as-bx27f2i6cp","object":"chat.completion","created":1702551504,"result":" Hello! I'd be happy to introduce Beijing, the capital city of China. Beijing is a city with a rich history dating back over 3,000 years, and it has been the capital of China for over 800 years. It is known for its cultural and historical landmarks, as well as its vibrant modern society.\n\nBeijing is located in the northern part of China, and it is the country's second-largest city after Shanghai. It has a population of over 21 million people, and it is a major transportation hub with a large international airport, a busy train station, and an extensive network of buses and subways.\n\nBeijing is perhaps most famous for its many UNESCO World Heritage Sites, including the Great Wall of China, the Forbidden City, and the Temple of Heaven. The Great Wall is a fortification that was built over several centuries to protect China from invaders, and it stretches for over 4,000 miles. The Forbidden City is a palace complex that was the residence of Chinese emperors for over 500 years, and it is home to many important historical artifacts. The Temple of Heaven is a beautiful Taoist temple that was used by emperors for ceremonies and sacrifices.\n\nIn addition to its historical landmarks, Beijing is also known for its vibrant cultural scene. The city has a thriving arts community, with many museums, galleries, and performance venues. Beijing is also famous for its cuisine, with many traditional dishes such as Peking duck, jiaozi (dumplings), and zhajiangmian (noodles with fermented soybean paste).\n\nBeijing has hosted many major international events, including the 2008 Summer Olympics and the 2014 APEC Summit. The city is also home to many universities and research institutions, making it a hub for education and innovation.\n\nOverall, Beijing is a city that offers a unique blend of history, culture, and modernity, and it is a must-visit destination for anyone interested in exploring China's rich heritage and contemporary society.","is_truncated":false,"need_clear_history":false,"usage":{"prompt_tokens":328,"completion_tokens":448,"total_tokens":776
data: {"id":"as-2m3nh3th6b","object":"chat.completion","created":1702551868,"sentence_id":0,"is_end":false,"is_truncated":false,"result":" Hello! I'm happy to help you with your question. The Great Wall of China is an ancient series of fortifications built to protect the Chinese Empire from invasions by foreign enemies, particularly the nomadic tribes from the north. It stretches for over 4,000 miles, making it one of the longest structures ever built.\n\nThe Great Wall was constructed over several centuries, with the first versions being built as ","need_clear_history":false,"usage":{"prompt_tokens":5,"completion_tokens":0,"total_tokens":5}}
data: {"id":"as-2m3nh3th6b","object":"chat.completion","created":1702551874,"sentence_id":1,"is_end":false,"is_truncated":false,"result":"early as the 7th century BC. It was continuously expanded and fortified over time, with the most famous and well-preserved sections being built during the Ming Dynasty (1368-1644).\n\nThe Great Wall is not only an engineering marvel but also a testament to the ingenuity and determination of the Chinese people. It's a popular tourist destination, with many visitors each year walking or hiking along its historic paths.\n\nIt's important to ","need_clear_history":false,"usage":{"prompt_tokens":5,"completion_tokens":0,"total_tokens":5}}
data: {"id":"as-2m3nh3th6b","object":"chat.completion","created":1702551880,"sentence_id":2,"is_end":true,"is_truncated":false,"result":"note that while the Great Wall is an incredible feat of engineering and history, it's not without controversy. Some sections of the wall have been damaged or destroyed over time, and there are concerns about the impact of tourism on the structure's preservation. Additionally, it's important to recognize the cultural and historical context of the wall, and to be respectful of the communities and traditions that it represents.","need_clear_history":false,"usage":{"prompt_tokens":5,"completion_tokens":276,"total_tokens":281}}