ChatGLM3 是由智譜AI訓(xùn)練的第三代大型語(yǔ)言模型,它不僅能理解和生成人類語(yǔ)言,還能執(zhí)行代碼、調(diào)用工具,并以 markdown 格式進(jìn)行響應(yīng)。為了提高用戶體驗(yàn),同時(shí)避免用戶輸入的注入攻擊,ChatGLM3 采用了全新的對(duì)話格式。下載智譜清言體驗(yàn)ChatGLM3最新的能力。
GitHub代碼倉(cāng)庫(kù):GitHub - THUDM/ChatGLM3
ChatGLM3 對(duì)話格式
ChatGLM3 對(duì)話的格式由若干對(duì)話組成,其中每個(gè)對(duì)話包含對(duì)話頭和內(nèi)容。對(duì)話頭占完整的一行,格式為 `<|role|>{metadata}`,其中 `<|role|>` 部分使用 special token 表示,無(wú)法從文本形式被 tokenizer 編碼以防止注入。metadata 部分采用純文本表示,為可選內(nèi)容。
對(duì)話格式的角色包括:
- `<|system|>`:系統(tǒng)信息,設(shè)計(jì)上可穿插于對(duì)話中,但目前規(guī)定僅可以出現(xiàn)在開頭
- `<|user|>`:用戶,不會(huì)連續(xù)出現(xiàn)多個(gè)來(lái)自 `<|user|>` 的信息
- `<|assistant|>`:AI 助手,在出現(xiàn)之前必須有一個(gè)來(lái)自 `<|user|>` 的信息
- `<|observation|>`:外部的返回結(jié)果,必須在 `<|assistant|>` 的信息之后
使用場(chǎng)景
多輪對(duì)話
在多輪對(duì)話中,有且僅有 `<|user|>`、`<|assistant|>`、`<|system|>` 三種角色。例如:
<|system|>
You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.
<|user|>
Hello
<|assistant|>
Hello, I'm ChatGLM3. What can I assist you today?
工具調(diào)用
在工具調(diào)用場(chǎng)景中,AI 助手可以接收用戶的請(qǐng)求,調(diào)用相應(yīng)的工具,并返回查詢結(jié)果。例如:
<|system|>
Answer the following questions as best as you can. You have access to the following tools:
[
? ? {
? ? ? ? "name": "get_current_weather",
? ? ? ? "description": "Get the current weather in a given location",
? ? ? ? "parameters": {
? ? ? ? ? ? "type": "object",
? ? ? ? ? ? "properties": {
? ? ? ? ? ? ? ? "location": {
? ? ? ? ? ? ? ? ? ? "type": "string",
? ? ? ? ? ? ? ? ? ? "description": "The city and state, e.g. San Francisco, CA",
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? "unit": {"type": "string"},
? ? ? ? ? ? },
? ? ? ? ? ? "required": ["location"],
? ? ? ? },
? ? }
]
<|user|>
查查巴黎的天氣怎么樣?
<|assistant|>
我需要調(diào)用天氣預(yù)報(bào)工具來(lái)獲取巴黎的天氣信息
<|assistant|>get_current_weather
```python
tool_call(location="巴黎", unit="celsius")
```
<|observation|>
{"temperature": 12}
<|assistant|>
根據(jù)查詢結(jié)果,巴黎現(xiàn)在的氣溫為 12?攝氏度。
代碼執(zhí)行
<|system|>
你是一位智能AI助手,你叫ChatGLM3,你連接著一臺(tái)電腦,但請(qǐng)注意不能聯(lián)網(wǎng)。在使用Python解決任務(wù)時(shí),你可以運(yùn)行代碼并得到結(jié)果,如果運(yùn)行結(jié)果有錯(cuò)誤,你需要盡可能對(duì)代碼進(jìn)行改進(jìn)。你可以處理用戶上傳到電腦上的文件,文件默認(rèn)存儲(chǔ)路徑是/mnt/data/。
<|user|>
#File: /mnt/data/metadata.jsonl
#Size: 35380
#File uploaded
文件中是否存在缺失值或異常值?
<|assistant|>
首先,我將讀取您提供的文件,并查看其內(nèi)容以確定是否存在缺失值或異常值。我們從加載文件開始:
<|assistant|>interpreter
```python
import json# Load the uploaded file
data = []
with open("/mnt/data/metadata.jsonl", 'r') as file:
? ? for line in file:
? ? ? ? data.append(json.loads(line))# Display the first few records to get a sense of the data
data[:5]
```
<|observation|>
```result
[{'file_name': 'aceinthehole.png',
? 'name': 'Ace in the Hole',
? 'type': 'survivor',
? 'description': 'Lady Luck always seems to be throwing something good your way.'},
?{'file_name': 'adrenaline.png',
? 'name': 'Adrenaline',
? 'type': 'survivor',
? 'description': 'You are fuelled by unexpected energy when on the verge of escape.'},
?{'file_name': 'aftercare.png',
? 'name': 'Aftercare',
? 'type': 'survivor',
? 'description': "Unlocks potential in one's aura reading ability."},
?{'file_name': 'agitation.png',
? 'name': 'Agitation',
? 'type': 'killer',
? 'description': 'You get excited in anticipation of hooking your prey.'},
?{'file_name': 'alert.png',
? 'name': 'Alert',
? 'type': 'survivor',
? 'description': 'Your acute senses are on high alert.'}]
```
<|assistant|>
該文件看起來(lái)包含有關(guān)某些條目的元數(shù)據(jù),每個(gè)條目有以下字段:
- `file_name`: 文件名稱
- `name`: 名稱
- `type`: 類型(例如 "survivor" 或 "killer")
- `description`: 描述接下來(lái),我將檢查這些字段是否存在缺失值。
<|assistant|>interpreter
```python
# Check for missing values in each column
missing_values = {key: sum(1 for item in data if key not in item) for key in data[0].keys()}missing_values
```
<|observation|>
```result
{'file_name': 0, 'name': 0, 'type': 0, 'description': 0}
```
<|assistant|>
每個(gè)字段都沒有缺失值。這意味著每個(gè)條目都完整。接下來(lái),我們可以檢查是否存在任何潛在的異常值。這通常需要更深入的分析和對(duì)數(shù)據(jù)的了解,但我可以從一些基本的統(tǒng)計(jì)和分布開始進(jìn)行檢查。為了這樣做,我們可以查看“type”字段的值分布,看看是否有任何意外的類別。
<|assistant|>interpreter
```python
# Check the distribution of values in the 'type' column
type_distribution = {key: sum(1 for item in data if item['type'] == key) for key in set(item['type'] for item in data)}type_distribution
```
<|observation|>
```result
{'survivor': 116, 'killer': 103}
```
<|assistant|>
“type”字段有兩個(gè)值:“survivor”和“killer”。其中,“survivor”有116個(gè)條目,而“killer”有103個(gè)條目。從這個(gè)初步的檢查中,我們沒有發(fā)現(xiàn)任何明顯的異常值。
如果您有任何特定的標(biāo)準(zhǔn)或其他字段需要檢查,我可以為您提供更詳細(xì)的分析。您還希望我檢查什么呢?
<|user|>
幫我畫一個(gè)愛心
<|assistant|>interpreter
```python
import numpy as np
import matplotlib.pyplot as plt# 愛心形狀的參數(shù)方程
def heart(t):
? ? x = 16 * np.sin(t) ** 3
? ? y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
? ? return x, yt = np.linspace(0, 2 * np.pi, 1000)
x, y = heart(t)plt.figure(figsize=(6, 6))
plt.plot(x, y, color='red')
plt.axis('equal')
plt.axis('off')
plt.show()
```
<|observation|>
```result
[Image]
```
<|assistant|>
這是一個(gè)愛心形狀。我使用了參數(shù)方程來(lái)描述這個(gè)形狀,并使用matplotlib進(jìn)行了繪制。如果您有任何其他需求或問題,請(qǐng)隨時(shí)告訴我。
<|user|> ?# End
````
ChatGLM3 的對(duì)話格式設(shè)計(jì)使得它能夠以更清晰、更安全的方式進(jìn)行多輪對(duì)話、工具調(diào)用和代碼執(zhí)行。無(wú)論是查看天氣、分析數(shù)據(jù),還是創(chuàng)建圖形,ChatGLM3 都能提供高效、準(zhǔn)確的幫助。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-760242.html
總的來(lái)說,ChatGLM3 是一款強(qiáng)大的 AI 助手,它的出現(xiàn)將為我們的生活和工作帶來(lái)更多可能性。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-760242.html
到了這里,關(guān)于ChatGLM3:打造更智能、更安全的代碼解釋器和工具使用體驗(yàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!