將watsonx Code Assistant individual 與本地IBM Granite模型結合使用

watsonx Code Assistant個人

對於個人用戶,watsonx Code Assistant 可以透過 Ollama 存取本地模型,Ollama 是廣泛使用的大型語言模型本地推理引擎。 Ollama 包裝了底層模型服務項目 llama.cpp

為了提升您的組織的效能和全套功能,請在IBM Cloud上設定watsonx Code Assistant的試用版。 有關更多信息,請參閱 在IBM Cloud中設定watsonx Code Assistant服務

安裝 watsonx Code Assistant 擴充套件

您可以設定 Ollama 以在 Microsoft Visual Studio Code中使用。

Eclipse IDE 外掛程式無法使用此設定。 它只適用於 Visual Studio Code 延伸。

  1. 開啟 watsonx Code Assistant 頁面。

  2. 按一下「市場」頁面上的 「安裝」

  3. 在Visual Studio Code中,按一下擴充功能上的 「安裝」

  4. 在擴充設定中,將 Wca: Backend Provider 設定為 ollama

    IBM 員工請注意:如果您是 IBM 或 Red Hat 員工,並使用 WCA@IBM 內部擴充套件,則變更後端供應商總是會回復到 wcaCore。 要啟用變更後端提供者:

    • 在 WCA@IBM 擴充設定中,清除為 watsonx Code Assistant 啟用 WCA@IBM 模式
    • 另一個選擇是停用 WCA@IBM 延伸功能

安裝奧拉馬

啟動 Ollama 推理伺服器

在控制台視窗中,運行:

ollama serve

使用 Ollama 時,請保持該視窗開啟。

如果您收到訊息 Error: listen tcp 127.0.0.1:11434: bind: address already in use,則 Ollama 伺服器已啟動。

安裝IBM Granite代碼模型

首先安裝 Ollama 庫 中提供的 granite-code:8b 模型。

  1. 開啟新的主控台視窗。

  2. 在命令列中,輸入 ollama run granite-code:8b 以下載並部署模型。 您會看到類似於下列範例的輸出:

    pulling manifest
    pulling 8718ec280572... 100% ▕███████████████████████ 4.6 GB
    pulling e50df8490144... 100% ▕███████████████████████ ▏  123 B
    pulling 58d1e17ffe51... 100% ▕███████████████████████▏  11 KB
    pulling 9893bb2c2917... 100% ▕███████████████████████▏  108 B
    pulling 0e851433eda0... 100% ▕███████████████████████▏  485 B
    verifying sha256 digest
    writing manifest
    removing any unused layers
    success
    >>>
    
  3. >>> 後鍵入 /bye 可退出 Ollama 指令 shell。

  4. 輸入以下命令來嘗試模型:

    ollama run granite-code:8b "How do I create a python class?"
    
  5. 您應該會看到類似的回應:

    To create a Python class, you can define a new class using the "class" keyword followed by the name of the class and a colon. Inside the class definition, you can specify the methods and attributes that the class will have. Here is an example: ...
    

配置 Ollama 主機

預設情況下,Ollama 伺服器的 IP 位址為 127.0.0.1,連接埠為 11434,通訊協定為 http。 如果您變更 Ollama 可用的 IP 位址或連接埠:

  1. 在Visual Studio Code中,開啟watsonx Code Assistant的擴充設定。

  2. Wca > 本機:API 主機中,新增主機 IP 和連接埠。

配置要使用的Granite模型

預設情況下,watsonx Code Assistant使用 granite-code:8b 模型進行聊天和程式碼完成。 如果您的環境有足夠的容量,請安裝 granite-code:8b-base 模型。

要使用不同的模型:

  1. 安裝 granite-code:8b-base 模型。 請參閱 安裝IBM Granite代碼模型

  2. 在Visual Studio Code中,開啟watsonx Code Assistant的擴充設定。

  3. Wca > 本地:代碼生成模型中,輸入 granite-code:8b-base

保護您的設置

預設情況下,Ollama 伺服器在本機裝置上運行在 IP 位址127.0.0.1、連接埠 11434 上,使用 http 作為協定。 若要使用 https 或透過代理伺服器,請參閱 Ollama 文件

從本地模型切換到IBM Cloud

您可能決定從本機模型切換到使用IBM Cloud上的服務實例。 然後,您可以設定Visual Studio Code從本機模型切換到IBM Cloud。

有關更多信息,請參閱 在IBM Cloud中設定watsonx Code Assistant服務

要更新Visual Studio Code編輯器以使用IBM Cloud而不是 Ollama:

  1. 退出 Visual Studio Code。

  2. 退出 Ollama 應用程式。

  3. 啟動Visual Studio Code,然後開啟watsonx Code Assistant。 您應該會看到訊息 Ollama is not running in your IDE.

  4. 按一下 Switch to watsonx Code Assistant on IBM Cloud

對於替代方法,您可以變更擴充設定:

  1. 在Visual Studio Code中,開啟watsonx Code Assistant的擴充設定。

  2. Wca: Backend Provider 中,從 ollama 切換到 wcaCore

  3. 重新啟動擴充功能以應用變更。