update code example for text-generation pipeline
Browse files- src/components/ModelCode.tsx +12 -3
src/components/ModelCode.tsx
CHANGED
|
@@ -59,7 +59,16 @@ const ModelCode = ({ isCodeModalOpen, setIsCodeModalOpen }: ModelCodeProps) => {
|
|
| 59 |
break
|
| 60 |
case 'text-generation':
|
| 61 |
classType = 'generator'
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
config = {
|
| 64 |
max_length: 50,
|
| 65 |
do_sample: true,
|
|
@@ -99,7 +108,7 @@ const ${classType} = pipeline('${pipeline}', '${modelInfo.name}', {
|
|
| 99 |
dtype: '${selectedQuantization}',
|
| 100 |
device: 'webgpu' // 'wasm'
|
| 101 |
});
|
| 102 |
-
const result = await ${classType}(
|
| 103 |
console.log(result);
|
| 104 |
`
|
| 105 |
|
|
@@ -113,7 +122,7 @@ console.log(result);
|
|
| 113 |
const pythonCode = `from transformers import pipeline
|
| 114 |
|
| 115 |
${classType} = pipeline("${pipeline}", model="${modelInfo.name}")
|
| 116 |
-
result = ${classType}(
|
| 117 |
print(result)
|
| 118 |
`
|
| 119 |
|
|
|
|
| 59 |
break
|
| 60 |
case 'text-generation':
|
| 61 |
classType = 'generator'
|
| 62 |
+
if (modelInfo.hasChatTemplate) {
|
| 63 |
+
exampleData = JSON.stringify([
|
| 64 |
+
{
|
| 65 |
+
role: 'user',
|
| 66 |
+
content: 'Hello!'
|
| 67 |
+
}
|
| 68 |
+
])
|
| 69 |
+
} else {
|
| 70 |
+
exampleData = 'Once upon a time, there was'
|
| 71 |
+
}
|
| 72 |
config = {
|
| 73 |
max_length: 50,
|
| 74 |
do_sample: true,
|
|
|
|
| 108 |
dtype: '${selectedQuantization}',
|
| 109 |
device: 'webgpu' // 'wasm'
|
| 110 |
});
|
| 111 |
+
const result = await ${classType}(${modelInfo.hasChatTemplate ? exampleData : "'" + exampleData + "'"}, ${JSON.stringify(config, null, 2)});
|
| 112 |
console.log(result);
|
| 113 |
`
|
| 114 |
|
|
|
|
| 122 |
const pythonCode = `from transformers import pipeline
|
| 123 |
|
| 124 |
${classType} = pipeline("${pipeline}", model="${modelInfo.name}")
|
| 125 |
+
result = ${classType}(${modelInfo.hasChatTemplate ? exampleData : '"' + exampleData + '"'}, ${configPython})
|
| 126 |
print(result)
|
| 127 |
`
|
| 128 |
|