訪問 watsonx.ai LLM 的使用者經常遇到的一個問題是「我們如何設定採樣參數?」 !
其實很簡單。
您可以更改設定的LLM(之前使用的或預設設定的)。
介面將提供3種參數的程式碼嵌入實作; Curl、Node.js 和 Python 如下範例。
curl "https://us-south.ml.cloud.ibm.com/ml/v1/text/generation?version=2023-05-29" \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -H "Authorization: Bearer ${YOUR_ACCESS_TOKEN}" \ -d '{ "input": "<|start_of_role|>system<|end_of_role|>You are Granite, an AI language model developed by IBM in 2024. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior.<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>", "parameters": { "decoding_method": "sample", "max_new_tokens": 200, "min_new_tokens": 100, "random_seed": 42, "stop_sequences": [], "temperature": 0.7, "top_k": 50, "top_p": 1, "repetition_penalty": 1 }, "model_id": "ibm/granite-3-8b-instruct", "project_id": "the one you get" }'
export const generateText = async () => { const url = "https://us-south.ml.cloud.ibm.com/ml/v1/text/generation?version=2023-05-29"; const headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer YOUR_ACCESS_TOKEN" }; const body = { input: "<|start_of_role|>system<|end_of_role|>You are Granite, an AI language model developed by IBM in 2024. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior.<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>", parameters: { decoding_method: "sample", max_new_tokens: 200, min_new_tokens: 100, random_seed: 42, stop_sequences: [], temperature: 0.7, top_k: 50, top_p: 1, repetition_penalty: 1 }, model_id: "ibm/granite-3-8b-instruct", project_id: "the-one-you-get" }; const response = await fetch(url, { headers, method: "POST", body: JSON.stringify(body) }); if (!response.ok) { throw new Error("Non-200 response"); } return await response.json(); }
import requests url = "https://us-south.ml.cloud.ibm.com/ml/v1/text/generation?version=2023-05-29" body = { "input": """<|start_of_role|>system<|end_of_role|>You are Granite, an AI language model developed by IBM in 2024. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior.<|end_of_text|> <|start_of_role|>assistant<|end_of_role|>""", "parameters": { "decoding_method": "sample", "max_new_tokens": 200, "min_new_tokens": 100, "random_seed": 42, "temperature": 0.7, "top_k": 50, "top_p": 1, "repetition_penalty": 1 }, "model_id": "ibm/granite-3-8b-instruct", "project_id": "the-one-you-get" } headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer YOUR_ACCESS_TOKEN" } response = requests.post( url, headers=headers, json=body ) if response.status_code != 200: raise Exception("Non-200 response: " + str(response.text)) data = response.json()
開發者唯一應該調整的資訊是存取權杖。
瞧?
watsonx.ai 平台讓應用程式開發人員可以非常輕鬆地調整 LLM 採樣參數集。
以上是如何簡單地為使用 watsonx 的應用程式設定所有「採樣參數」或「生成參數」?的詳細內容。更多資訊請關注PHP中文網其他相關文章!