phi

Phi-2:微軟研究院開發的 2.7B 語言模型,展現卓越的推理和語言理解能力。

2.7b

480.3K 13 months ago

說明文件

Phi-2 是一個小型語言模型,能夠進行常識推理和語言理解。 它展現了參數少於 130 億的語言模型中的「最先進效能」。

範例提示

預設情況下,phi 包含一個專為多輪對話設計的聊天提示範本

% ollama run phi
>>> Hello, can you help me find my way to Toronto?
 Certainly! What is the exact location in Toronto that you are looking for?

>>> Yonge & Bloor
 Sure, Yonge and Bloor is a busy intersection in downtown Toronto. Would you like to take public transportation or drive there?

>>> Public transportation
 Great! The easiest way to get there is by taking the TTC subway. You can take Line 1, which runs along Yonge Street and passes through downtown Toronto.

使用 Ollama 的 API

curl https://127.0.0.1:11434/api/chat -d '{
  "model": "phi",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}'

範例提示(原始模式)

當在 Ollama 的 API 中使用原始模式時,Phi 對於各種提示格式也能良好回應,這會繞過所有預設的提示範本

指示

curl https://127.0.0.1:11434/api/generate -d '{
  "model": "phi",
  "prompt": "Instruct: Write a detailed analogy between mathematics and a lighthouse.\nOutput:",
  "options": {
    "stop": ["Instruct:", "Output:"]
  },
  "raw": true,
  "stream": false
}'

程式碼完成

curl https://127.0.0.1:11434/api/generate -d '{
  "model": "phi",
  "prompt": "def print_prime(n):\n  ",
  "raw": true,
  "stream": false
}'

文字完成

curl https://127.0.0.1:11434/api/generate -d '{
  "model": "phi",
  "prompt": "There once was a mouse named",
  "raw": true,
  "stream": false
}'

參考文獻

HuggingFace

部落格文章