Persoalan yang sering timbul untuk pengguna yang mengakses watsonx.ai LLM ialah "bagaimana kita menetapkan parameter pensampelan?" !
Sebenarnya, ia agak mudah.
Anda boleh menukar LLM yang ditetapkan (yang digunakan sebelum ini atau yang ditetapkan secara lalai).
Antara muka akan menyediakan 3 jenis pelaksanaan pembenaman kod parameter; Curl, Node.js dan Python seperti contoh di bawah.
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()
Satu-satunya maklumat yang perlu dilaraskan oleh pembangun ialah token akses.
Et voilà ?
Platform watsonx.ai memudahkan pembangun aplikasi melaraskan set parameter pensampelan LLM.
Atas ialah kandungan terperinci Bagaimana untuk menetapkan hanya semua 'parameter pensampelan' atau 'parameter penjanaan' untuk aplikasi menggunakan watsonx?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!