From 461d98950c224b45b70d0e3fbb383efe0fe0710e Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 17:53:11 +0100 Subject: [PATCH 01/11] Add debug script to check inference snippets --- packages/tasks/package.json | 5 +- packages/tasks/pnpm-lock.yaml | 292 ++++++++++++++--------- packages/tasks/scripts/check-snippets.ts | 48 ++++ 3 files changed, 225 insertions(+), 120 deletions(-) create mode 100644 packages/tasks/scripts/check-snippets.ts diff --git a/packages/tasks/package.json b/packages/tasks/package.json index 556eb86f4b..61b20c084b 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -32,7 +32,8 @@ "check": "tsc", "inference-codegen": "tsx scripts/inference-codegen.ts && prettier --write src/tasks/*/inference.ts", "inference-tgi-import": "tsx scripts/inference-tgi-import.ts && prettier --write src/tasks/text-generation/spec/*.json && prettier --write src/tasks/chat-completion/spec/*.json", - "inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json" + "inference-tei-import": "tsx scripts/inference-tei-import.ts && prettier --write src/tasks/feature-extraction/spec/*.json", + "check-snippets": "tsx scripts/check-snippets.ts" }, "type": "module", "files": [ @@ -48,7 +49,9 @@ "author": "Hugging Face", "license": "MIT", "devDependencies": { + "@types/minimist": "^1.2.5", "@types/node": "^20.11.5", + "minimist": "^1.2.8", "quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz", "type-fest": "^3.13.1" }, diff --git a/packages/tasks/pnpm-lock.yaml b/packages/tasks/pnpm-lock.yaml index 2d5435a89a..ad2b0f15f1 100644 --- a/packages/tasks/pnpm-lock.yaml +++ b/packages/tasks/pnpm-lock.yaml @@ -1,102 +1,90 @@ -lockfileVersion: '6.0' +lockfileVersion: '9.0' settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - '@huggingface/gguf': - specifier: workspace:^ - version: link:../gguf - -devDependencies: - '@types/node': - specifier: ^20.11.5 - version: 20.11.5 - quicktype-core: - specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz - version: '@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz' - type-fest: - specifier: ^3.13.1 - version: 3.13.1 +importers: + + .: + dependencies: + '@huggingface/gguf': + specifier: workspace:^ + version: link:../gguf + devDependencies: + '@types/minimist': + specifier: ^1.2.5 + version: 1.2.5 + '@types/node': + specifier: ^20.11.5 + version: 20.11.5 + minimist: + specifier: ^1.2.8 + version: 1.2.8 + quicktype-core: + specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz + version: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz + type-fest: + specifier: ^3.13.1 + version: 3.13.1 packages: - /@glideapps/ts-necessities@2.1.3: + '@glideapps/ts-necessities@2.1.3': resolution: {integrity: sha512-q9U8v/n9qbkd2zDYjuX3qtlbl+OIyI9zF+zQhZjfYOE9VMDH7tfcUSJ9p0lXoY3lxmGFne09yi4iiNeQUwV7AA==} - dev: true - /@types/node@20.11.5: + '@types/minimist@1.2.5': + resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} + + '@types/node@20.11.5': resolution: {integrity: sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==} - dependencies: - undici-types: 5.26.5 - dev: true - /@types/urijs@1.19.25: + '@types/urijs@1.19.25': resolution: {integrity: sha512-XOfUup9r3Y06nFAZh3WvO0rBU4OtlfPB/vgxpjg+NRdGU6CN6djdc6OEiH+PcqHCY6eFLo9Ista73uarf4gnBg==} - dev: true - /abort-controller@3.0.0: + abort-controller@3.0.0: resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} engines: {node: '>=6.5'} - dependencies: - event-target-shim: 5.0.1 - dev: true - /base64-js@1.5.1: + base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - dev: true - /browser-or-node@2.1.1: + browser-or-node@2.1.1: resolution: {integrity: sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==} - dev: true - /buffer@6.0.3: + buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - dev: true - /collection-utils@1.0.1: + collection-utils@1.0.1: resolution: {integrity: sha512-LA2YTIlR7biSpXkKYwwuzGjwL5rjWEZVOSnvdUc7gObvWe4WkjxOpfrdhoP7Hs09YWDVfg0Mal9BpAqLfVEzQg==} - dev: true - /cross-fetch@4.0.0: + cross-fetch@4.0.0: resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - dev: true - /event-target-shim@5.0.1: + event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} - dev: true - /events@3.3.0: + events@3.3.0: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} - dev: true - /ieee754@1.2.1: + ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - dev: true - /is-url@1.2.4: + is-url@1.2.4: resolution: {integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==} - dev: true - /js-base64@3.7.6: + js-base64@3.7.6: resolution: {integrity: sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA==} - dev: true - /lodash@4.17.21: + lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - dev: true - /node-fetch@2.7.0: + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + + node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} peerDependencies: @@ -104,108 +92,130 @@ packages: peerDependenciesMeta: encoding: optional: true - dependencies: - whatwg-url: 5.0.0 - dev: true - /pako@0.2.9: + pako@0.2.9: resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==} - dev: true - /pako@1.0.11: + pako@1.0.11: resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} - dev: true - /pluralize@8.0.0: + pluralize@8.0.0: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} - dev: true - /process@0.11.10: + process@0.11.10: resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==} engines: {node: '>= 0.6.0'} - dev: true - /readable-stream@4.4.2: + quicktype-core@https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz: + resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz} + version: 18.0.17 + + readable-stream@4.4.2: resolution: {integrity: sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - dependencies: - abort-controller: 3.0.0 - buffer: 6.0.3 - events: 3.3.0 - process: 0.11.10 - string_decoder: 1.3.0 - dev: true - /safe-buffer@5.2.1: + safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - dev: true - /string_decoder@1.3.0: + string_decoder@1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} - dependencies: - safe-buffer: 5.2.1 - dev: true - /tiny-inflate@1.0.3: + tiny-inflate@1.0.3: resolution: {integrity: sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==} - dev: true - /tr46@0.0.3: + tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - dev: true - /type-fest@3.13.1: + type-fest@3.13.1: resolution: {integrity: sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==} engines: {node: '>=14.16'} - dev: true - /undici-types@5.26.5: + undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - dev: true - /unicode-properties@1.4.1: + unicode-properties@1.4.1: resolution: {integrity: sha512-CLjCCLQ6UuMxWnbIylkisbRj31qxHPAurvena/0iwSVbQ2G1VY5/HjV0IRabOEbDHlzZlRdCrD4NhB0JtU40Pg==} - dependencies: - base64-js: 1.5.1 - unicode-trie: 2.0.0 - dev: true - /unicode-trie@2.0.0: + unicode-trie@2.0.0: resolution: {integrity: sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==} - dependencies: - pako: 0.2.9 - tiny-inflate: 1.0.3 - dev: true - /urijs@1.19.11: + urijs@1.19.11: resolution: {integrity: sha512-HXgFDgDommxn5/bIv0cnQZsPhHDA90NPHD6+c/v21U5+Sx5hoP8+dP9IZXBU1gIfvdRfhG8cel9QNPeionfcCQ==} - dev: true - /webidl-conversions@3.0.1: + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - dev: true - /whatwg-url@5.0.0: + whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - dev: true - /wordwrap@1.0.0: + wordwrap@1.0.0: resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==} - dev: true - /yaml@2.3.4: + yaml@2.3.4: resolution: {integrity: sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==} engines: {node: '>= 14'} - dev: true - '@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz': - resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz} - name: quicktype-core - version: 18.0.17 +snapshots: + + '@glideapps/ts-necessities@2.1.3': {} + + '@types/minimist@1.2.5': {} + + '@types/node@20.11.5': + dependencies: + undici-types: 5.26.5 + + '@types/urijs@1.19.25': {} + + abort-controller@3.0.0: + dependencies: + event-target-shim: 5.0.1 + + base64-js@1.5.1: {} + + browser-or-node@2.1.1: {} + + buffer@6.0.3: + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + + collection-utils@1.0.1: {} + + cross-fetch@4.0.0: + dependencies: + node-fetch: 2.7.0 + transitivePeerDependencies: + - encoding + + event-target-shim@5.0.1: {} + + events@3.3.0: {} + + ieee754@1.2.1: {} + + is-url@1.2.4: {} + + js-base64@3.7.6: {} + + lodash@4.17.21: {} + + minimist@1.2.8: {} + + node-fetch@2.7.0: + dependencies: + whatwg-url: 5.0.0 + + pako@0.2.9: {} + + pako@1.0.11: {} + + pluralize@8.0.0: {} + + process@0.11.10: {} + + quicktype-core@https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz: dependencies: '@glideapps/ts-necessities': 2.1.3 '@types/urijs': 1.19.25 @@ -224,4 +234,48 @@ packages: yaml: 2.3.4 transitivePeerDependencies: - encoding - dev: true + + readable-stream@4.4.2: + dependencies: + abort-controller: 3.0.0 + buffer: 6.0.3 + events: 3.3.0 + process: 0.11.10 + string_decoder: 1.3.0 + + safe-buffer@5.2.1: {} + + string_decoder@1.3.0: + dependencies: + safe-buffer: 5.2.1 + + tiny-inflate@1.0.3: {} + + tr46@0.0.3: {} + + type-fest@3.13.1: {} + + undici-types@5.26.5: {} + + unicode-properties@1.4.1: + dependencies: + base64-js: 1.5.1 + unicode-trie: 2.0.0 + + unicode-trie@2.0.0: + dependencies: + pako: 0.2.9 + tiny-inflate: 1.0.3 + + urijs@1.19.11: {} + + webidl-conversions@3.0.1: {} + + whatwg-url@5.0.0: + dependencies: + tr46: 0.0.3 + webidl-conversions: 3.0.1 + + wordwrap@1.0.0: {} + + yaml@2.3.4: {} diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts new file mode 100644 index 0000000000..1241b32001 --- /dev/null +++ b/packages/tasks/scripts/check-snippets.ts @@ -0,0 +1,48 @@ +/* + * Generates inference snippets as they would be shown on the Hub for Curl, JS and Python. + * Snippets will only be printed to the terminal to make it easier to debug when making changes to the snippets. + * + * Usage: + * pnpm run check-snippets --pipeline-tag="text-generation" --tags="conversational" + * pnpm run check-snippets --pipeline-tag="image-text-to-text" --tags="conversational" + * pnpm run check-snippets --pipeline-tag="text-to-image" + * + * This script is meant only for debug purposes. + */ + +import { python, curl, js } from "../src/snippets/index"; +import type { InferenceSnippet, ModelDataMinimal } from "../src/snippets/types"; +import minimist from "minimist"; + +const args = minimist(process.argv.slice(2)); + +const accessToken = "hf_**********"; +const pipelineTag = args["pipeline-type"] || "text-generation"; +const tags = (args["tags"] || "").split(","); + +const modelMinimal: ModelDataMinimal = { + id: "llama-6-1720B-Instruct", + pipeline_tag: pipelineTag, + tags: tags, + inference: "****", +}; + +const printSnippets = (snippets: InferenceSnippet | InferenceSnippet[], language: string) => { + const snippetArray = Array.isArray(snippets) ? snippets : [snippets]; + snippetArray.forEach((snippet) => { + console.log(`\n\x1b[33m${language} ${snippet.client}\x1b[0m`); + console.log(`\n\`\`\`${language === "JS" ? "js" : language.toLowerCase()}\n${snippet.content}\n\`\`\`\n`); + }); +}; + +const generateAndPrintSnippets = ( + generator: (model: ModelDataMinimal, token: string) => InferenceSnippet | InferenceSnippet[], + language: string +) => { + const snippets = generator(modelMinimal, accessToken); + printSnippets(snippets, language); +}; + +generateAndPrintSnippets(curl.getCurlInferenceSnippet, "Curl"); +generateAndPrintSnippets(python.getPythonInferenceSnippet, "Python"); +generateAndPrintSnippets(js.getJsInferenceSnippet, "JS"); From e172a276c2584a96f291bb17c1388f7d3569e2ef Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:20:49 +0100 Subject: [PATCH 02/11] Add script to check inference snippet changes + update Python textToImage snippet --- .../workflows/inference-check-snippets.yml | 49 +++++++++++++++++++ packages/tasks/scripts/check-snippets.ts | 2 +- packages/tasks/src/snippets/python.ts | 27 ++++++++-- 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/inference-check-snippets.yml diff --git a/.github/workflows/inference-check-snippets.yml b/.github/workflows/inference-check-snippets.yml new file mode 100644 index 0000000000..0f72d053a3 --- /dev/null +++ b/.github/workflows/inference-check-snippets.yml @@ -0,0 +1,49 @@ +name: Inference check snippets +on: + pull_request: + paths: + - "packages/tasks/src/snippets/**" + - ".github/workflows/inference-check-snippets.yml" + +jobs: + check-snippets: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - run: corepack enable + + - uses: actions/setup-node@v3 + with: + node-version: "20" + cache: "pnpm" + cache-dependency-path: "**/pnpm-lock.yaml" + - run: | + cd packages/tasks + pnpm install --frozen-lockfile --filter . + pnpm install --frozen-lockfile --filter ...[${{ steps.since.outputs.SINCE }}]... + pnpm --filter ...[${{ steps.since.outputs.SINCE }}]... build + + # TODO: Find a way to run on all pipeline tags + # TODO: print snippet only if it has changed since the last commit on main (?) + # TODO: (even better: automated message on the PR with diff) + - name: Print text-to-image snippets + run: | + cd packages/tasks + pnpm run check-snippets --pipeline-tag="text-to-image" + + - name: Print simple text-generation snippets + run: | + cd packages/tasks + pnpm run check-snippets --pipeline-tag="text-generation" + + - name: Print conversational text-generation snippets + run: | + cd packages/tasks + pnpm run check-snippets --pipeline-tag="text-generation" --tags="conversational" + + - name: Print conversational image-text-to-text snippets + run: | + cd packages/tasks + pnpm run check-snippets --pipeline-tag="image-text-to-text" --tags="conversational" diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts index 1241b32001..2ea4b1465e 100644 --- a/packages/tasks/scripts/check-snippets.ts +++ b/packages/tasks/scripts/check-snippets.ts @@ -17,7 +17,7 @@ import minimist from "minimist"; const args = minimist(process.argv.slice(2)); const accessToken = "hf_**********"; -const pipelineTag = args["pipeline-type"] || "text-generation"; +const pipelineTag = args["pipeline-tag"] || "text-generation"; const tags = (args["tags"] || "").split(","); const modelMinimal: ModelDataMinimal = { diff --git a/packages/tasks/src/snippets/python.ts b/packages/tasks/src/snippets/python.ts index af8c658c30..b63ed63b72 100644 --- a/packages/tasks/src/snippets/python.ts +++ b/packages/tasks/src/snippets/python.ts @@ -4,6 +4,11 @@ import { stringifyGenerationConfig, stringifyMessages } from "./common.js"; import { getModelInputSnippet } from "./inputs.js"; import type { InferenceSnippet, ModelDataMinimal } from "./types.js"; +const snippetImportInferenceClient = (model: ModelDataMinimal, accessToken: string): string => + `from huggingface_hub import InferenceClient + +client = InferenceClient(${model.id}, token="${accessToken || "{API_TOKEN}"}")`; + export const snippetConversational = ( model: ModelDataMinimal, accessToken: string, @@ -184,10 +189,14 @@ export const snippetFile = (model: ModelDataMinimal): InferenceSnippet => ({ output = query(${getModelInputSnippet(model)})`, }); -export const snippetTextToImage = (model: ModelDataMinimal): InferenceSnippet => ({ - content: `def query(payload): +export const snippetTextToImage = (model: ModelDataMinimal, accessToken: string): InferenceSnippet[] => { + return [ + { + client: "requests", + content: `def query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.content + image_bytes = query({ "inputs": ${getModelInputSnippet(model)}, }) @@ -195,7 +204,16 @@ image_bytes = query({ import io from PIL import Image image = Image.open(io.BytesIO(image_bytes))`, -}); + }, + { + client: "huggingface_hub", + content: `${snippetImportInferenceClient(model, accessToken)} + +# output is a PIL.Image object +image = client.text_to_image(${getModelInputSnippet(model)})`, + }, + ]; +}; export const snippetTabular = (model: ModelDataMinimal): InferenceSnippet => ({ content: `def query(payload): @@ -300,6 +318,9 @@ export function getPythonInferenceSnippet( if (model.tags.includes("conversational")) { // Conversational model detected, so we display a code snippet that features the Messages API return snippetConversational(model, accessToken, opts); + } else if (model.pipeline_tag == "text-to-image") { + // TODO: factorize this logic + return snippetTextToImage(model, accessToken); } else { let snippets = model.pipeline_tag && model.pipeline_tag in pythonSnippets From 3772f292f344e6bd6394ccd7e7f86ad752f42ddf Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:28:57 +0100 Subject: [PATCH 03/11] revert --- packages/tasks/pnpm-lock.yaml | 292 ++++++++++++++-------------------- 1 file changed, 119 insertions(+), 173 deletions(-) diff --git a/packages/tasks/pnpm-lock.yaml b/packages/tasks/pnpm-lock.yaml index ad2b0f15f1..2d5435a89a 100644 --- a/packages/tasks/pnpm-lock.yaml +++ b/packages/tasks/pnpm-lock.yaml @@ -1,90 +1,102 @@ -lockfileVersion: '9.0' +lockfileVersion: '6.0' settings: autoInstallPeers: true excludeLinksFromLockfile: false -importers: - - .: - dependencies: - '@huggingface/gguf': - specifier: workspace:^ - version: link:../gguf - devDependencies: - '@types/minimist': - specifier: ^1.2.5 - version: 1.2.5 - '@types/node': - specifier: ^20.11.5 - version: 20.11.5 - minimist: - specifier: ^1.2.8 - version: 1.2.8 - quicktype-core: - specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz - version: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz - type-fest: - specifier: ^3.13.1 - version: 3.13.1 +dependencies: + '@huggingface/gguf': + specifier: workspace:^ + version: link:../gguf + +devDependencies: + '@types/node': + specifier: ^20.11.5 + version: 20.11.5 + quicktype-core: + specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz + version: '@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz' + type-fest: + specifier: ^3.13.1 + version: 3.13.1 packages: - '@glideapps/ts-necessities@2.1.3': + /@glideapps/ts-necessities@2.1.3: resolution: {integrity: sha512-q9U8v/n9qbkd2zDYjuX3qtlbl+OIyI9zF+zQhZjfYOE9VMDH7tfcUSJ9p0lXoY3lxmGFne09yi4iiNeQUwV7AA==} + dev: true - '@types/minimist@1.2.5': - resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} - - '@types/node@20.11.5': + /@types/node@20.11.5: resolution: {integrity: sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==} + dependencies: + undici-types: 5.26.5 + dev: true - '@types/urijs@1.19.25': + /@types/urijs@1.19.25: resolution: {integrity: sha512-XOfUup9r3Y06nFAZh3WvO0rBU4OtlfPB/vgxpjg+NRdGU6CN6djdc6OEiH+PcqHCY6eFLo9Ista73uarf4gnBg==} + dev: true - abort-controller@3.0.0: + /abort-controller@3.0.0: resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} engines: {node: '>=6.5'} + dependencies: + event-target-shim: 5.0.1 + dev: true - base64-js@1.5.1: + /base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: true - browser-or-node@2.1.1: + /browser-or-node@2.1.1: resolution: {integrity: sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==} + dev: true - buffer@6.0.3: + /buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: true - collection-utils@1.0.1: + /collection-utils@1.0.1: resolution: {integrity: sha512-LA2YTIlR7biSpXkKYwwuzGjwL5rjWEZVOSnvdUc7gObvWe4WkjxOpfrdhoP7Hs09YWDVfg0Mal9BpAqLfVEzQg==} + dev: true - cross-fetch@4.0.0: + /cross-fetch@4.0.0: resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} + dependencies: + node-fetch: 2.7.0 + transitivePeerDependencies: + - encoding + dev: true - event-target-shim@5.0.1: + /event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} + dev: true - events@3.3.0: + /events@3.3.0: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} + dev: true - ieee754@1.2.1: + /ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: true - is-url@1.2.4: + /is-url@1.2.4: resolution: {integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==} + dev: true - js-base64@3.7.6: + /js-base64@3.7.6: resolution: {integrity: sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA==} + dev: true - lodash@4.17.21: + /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + dev: true - minimist@1.2.8: - resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} - - node-fetch@2.7.0: + /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} peerDependencies: @@ -92,130 +104,108 @@ packages: peerDependenciesMeta: encoding: optional: true + dependencies: + whatwg-url: 5.0.0 + dev: true - pako@0.2.9: + /pako@0.2.9: resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==} + dev: true - pako@1.0.11: + /pako@1.0.11: resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} + dev: true - pluralize@8.0.0: + /pluralize@8.0.0: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} + dev: true - process@0.11.10: + /process@0.11.10: resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==} engines: {node: '>= 0.6.0'} + dev: true - quicktype-core@https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz: - resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz} - version: 18.0.17 - - readable-stream@4.4.2: + /readable-stream@4.4.2: resolution: {integrity: sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + abort-controller: 3.0.0 + buffer: 6.0.3 + events: 3.3.0 + process: 0.11.10 + string_decoder: 1.3.0 + dev: true - safe-buffer@5.2.1: + /safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: true - string_decoder@1.3.0: + /string_decoder@1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} + dependencies: + safe-buffer: 5.2.1 + dev: true - tiny-inflate@1.0.3: + /tiny-inflate@1.0.3: resolution: {integrity: sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==} + dev: true - tr46@0.0.3: + /tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} + dev: true - type-fest@3.13.1: + /type-fest@3.13.1: resolution: {integrity: sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==} engines: {node: '>=14.16'} + dev: true - undici-types@5.26.5: + /undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + dev: true - unicode-properties@1.4.1: + /unicode-properties@1.4.1: resolution: {integrity: sha512-CLjCCLQ6UuMxWnbIylkisbRj31qxHPAurvena/0iwSVbQ2G1VY5/HjV0IRabOEbDHlzZlRdCrD4NhB0JtU40Pg==} + dependencies: + base64-js: 1.5.1 + unicode-trie: 2.0.0 + dev: true - unicode-trie@2.0.0: + /unicode-trie@2.0.0: resolution: {integrity: sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==} + dependencies: + pako: 0.2.9 + tiny-inflate: 1.0.3 + dev: true - urijs@1.19.11: + /urijs@1.19.11: resolution: {integrity: sha512-HXgFDgDommxn5/bIv0cnQZsPhHDA90NPHD6+c/v21U5+Sx5hoP8+dP9IZXBU1gIfvdRfhG8cel9QNPeionfcCQ==} + dev: true - webidl-conversions@3.0.1: + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} + dev: true - whatwg-url@5.0.0: + /whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} + dependencies: + tr46: 0.0.3 + webidl-conversions: 3.0.1 + dev: true - wordwrap@1.0.0: + /wordwrap@1.0.0: resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==} + dev: true - yaml@2.3.4: + /yaml@2.3.4: resolution: {integrity: sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==} engines: {node: '>= 14'} + dev: true -snapshots: - - '@glideapps/ts-necessities@2.1.3': {} - - '@types/minimist@1.2.5': {} - - '@types/node@20.11.5': - dependencies: - undici-types: 5.26.5 - - '@types/urijs@1.19.25': {} - - abort-controller@3.0.0: - dependencies: - event-target-shim: 5.0.1 - - base64-js@1.5.1: {} - - browser-or-node@2.1.1: {} - - buffer@6.0.3: - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - - collection-utils@1.0.1: {} - - cross-fetch@4.0.0: - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - - event-target-shim@5.0.1: {} - - events@3.3.0: {} - - ieee754@1.2.1: {} - - is-url@1.2.4: {} - - js-base64@3.7.6: {} - - lodash@4.17.21: {} - - minimist@1.2.8: {} - - node-fetch@2.7.0: - dependencies: - whatwg-url: 5.0.0 - - pako@0.2.9: {} - - pako@1.0.11: {} - - pluralize@8.0.0: {} - - process@0.11.10: {} - - quicktype-core@https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz: + '@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz': + resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz} + name: quicktype-core + version: 18.0.17 dependencies: '@glideapps/ts-necessities': 2.1.3 '@types/urijs': 1.19.25 @@ -234,48 +224,4 @@ snapshots: yaml: 2.3.4 transitivePeerDependencies: - encoding - - readable-stream@4.4.2: - dependencies: - abort-controller: 3.0.0 - buffer: 6.0.3 - events: 3.3.0 - process: 0.11.10 - string_decoder: 1.3.0 - - safe-buffer@5.2.1: {} - - string_decoder@1.3.0: - dependencies: - safe-buffer: 5.2.1 - - tiny-inflate@1.0.3: {} - - tr46@0.0.3: {} - - type-fest@3.13.1: {} - - undici-types@5.26.5: {} - - unicode-properties@1.4.1: - dependencies: - base64-js: 1.5.1 - unicode-trie: 2.0.0 - - unicode-trie@2.0.0: - dependencies: - pako: 0.2.9 - tiny-inflate: 1.0.3 - - urijs@1.19.11: {} - - webidl-conversions@3.0.1: {} - - whatwg-url@5.0.0: - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - - wordwrap@1.0.0: {} - - yaml@2.3.4: {} + dev: true From b3deb60d9272ddc8bf5e02c6bba243c4c563dd0e Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:36:22 +0100 Subject: [PATCH 04/11] no new deps --- packages/tasks/scripts/check-snippets.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts index 2ea4b1465e..a197cf3f2b 100644 --- a/packages/tasks/scripts/check-snippets.ts +++ b/packages/tasks/scripts/check-snippets.ts @@ -9,15 +9,22 @@ * * This script is meant only for debug purposes. */ - import { python, curl, js } from "../src/snippets/index"; import type { InferenceSnippet, ModelDataMinimal } from "../src/snippets/types"; -import minimist from "minimist"; +import type { PipelineType } from "../src/pipelines"; -const args = minimist(process.argv.slice(2)); +// Parse command-line arguments +const args = process.argv.slice(2).reduce( + (acc, arg) => { + const [key, value] = arg.split("="); + acc[key.replace("--", "")] = value; + return acc; + }, + {} as { [key: string]: string } +); const accessToken = "hf_**********"; -const pipelineTag = args["pipeline-tag"] || "text-generation"; +const pipelineTag = (args["pipeline-tag"] || "text-generation") as PipelineType; const tags = (args["tags"] || "").split(","); const modelMinimal: ModelDataMinimal = { From 61d2e3360870e40320976cf9f06eca7d906a2365 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:38:41 +0100 Subject: [PATCH 05/11] forgot this one --- packages/tasks/package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/tasks/package.json b/packages/tasks/package.json index 61b20c084b..48c75b8027 100644 --- a/packages/tasks/package.json +++ b/packages/tasks/package.json @@ -49,9 +49,7 @@ "author": "Hugging Face", "license": "MIT", "devDependencies": { - "@types/minimist": "^1.2.5", "@types/node": "^20.11.5", - "minimist": "^1.2.8", "quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz", "type-fest": "^3.13.1" }, From 24793d859056e0ac8b816f015daf519ee69cf878 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:42:00 +0100 Subject: [PATCH 06/11] fix install --- .github/workflows/inference-check-snippets.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/inference-check-snippets.yml b/.github/workflows/inference-check-snippets.yml index 0f72d053a3..728ffe039f 100644 --- a/.github/workflows/inference-check-snippets.yml +++ b/.github/workflows/inference-check-snippets.yml @@ -21,9 +21,7 @@ jobs: cache-dependency-path: "**/pnpm-lock.yaml" - run: | cd packages/tasks - pnpm install --frozen-lockfile --filter . - pnpm install --frozen-lockfile --filter ...[${{ steps.since.outputs.SINCE }}]... - pnpm --filter ...[${{ steps.since.outputs.SINCE }}]... build + pnpm install --frozen-lockfile . # TODO: Find a way to run on all pipeline tags # TODO: print snippet only if it has changed since the last commit on main (?) From 06451a32abec48ffefa8ab9f41a2eaf34b8a6665 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:45:10 +0100 Subject: [PATCH 07/11] simple --- .github/workflows/inference-check-snippets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/inference-check-snippets.yml b/.github/workflows/inference-check-snippets.yml index 728ffe039f..06030cd287 100644 --- a/.github/workflows/inference-check-snippets.yml +++ b/.github/workflows/inference-check-snippets.yml @@ -21,7 +21,7 @@ jobs: cache-dependency-path: "**/pnpm-lock.yaml" - run: | cd packages/tasks - pnpm install --frozen-lockfile . + pnpm install # TODO: Find a way to run on all pipeline tags # TODO: print snippet only if it has changed since the last commit on main (?) From 79232a910704e333cb7f4e5b7e4387c0e135db9c Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 29 Oct 2024 18:52:46 +0100 Subject: [PATCH 08/11] not a fix --- .github/workflows/inference-check-snippets.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/inference-check-snippets.yml b/.github/workflows/inference-check-snippets.yml index 06030cd287..37e9843006 100644 --- a/.github/workflows/inference-check-snippets.yml +++ b/.github/workflows/inference-check-snippets.yml @@ -40,8 +40,3 @@ jobs: run: | cd packages/tasks pnpm run check-snippets --pipeline-tag="text-generation" --tags="conversational" - - - name: Print conversational image-text-to-text snippets - run: | - cd packages/tasks - pnpm run check-snippets --pipeline-tag="image-text-to-text" --tags="conversational" From 30d5d4d023e43d6ce63bf47a83e50fc456c822f8 Mon Sep 17 00:00:00 2001 From: Lucain Date: Wed, 30 Oct 2024 11:55:41 +0100 Subject: [PATCH 09/11] Update packages/tasks/scripts/check-snippets.ts Co-authored-by: Julien Chaumond --- packages/tasks/scripts/check-snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts index a197cf3f2b..fe14378668 100644 --- a/packages/tasks/scripts/check-snippets.ts +++ b/packages/tasks/scripts/check-snippets.ts @@ -38,7 +38,7 @@ const printSnippets = (snippets: InferenceSnippet | InferenceSnippet[], language const snippetArray = Array.isArray(snippets) ? snippets : [snippets]; snippetArray.forEach((snippet) => { console.log(`\n\x1b[33m${language} ${snippet.client}\x1b[0m`); - console.log(`\n\`\`\`${language === "JS" ? "js" : language.toLowerCase()}\n${snippet.content}\n\`\`\`\n`); + console.log(`\n\`\`\`${language.toLowerCase()}\n${snippet.content}\n\`\`\`\n`); }); }; From 251856d200ba6a82dde109f9c7f3d8b0be2a696b Mon Sep 17 00:00:00 2001 From: Lucain Date: Wed, 30 Oct 2024 11:55:51 +0100 Subject: [PATCH 10/11] Update packages/tasks/scripts/check-snippets.ts Co-authored-by: Julien Chaumond --- packages/tasks/scripts/check-snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts index fe14378668..4d73eef50d 100644 --- a/packages/tasks/scripts/check-snippets.ts +++ b/packages/tasks/scripts/check-snippets.ts @@ -25,7 +25,7 @@ const args = process.argv.slice(2).reduce( const accessToken = "hf_**********"; const pipelineTag = (args["pipeline-tag"] || "text-generation") as PipelineType; -const tags = (args["tags"] || "").split(","); +const tags = (args["tags"] ?? "").split(","); const modelMinimal: ModelDataMinimal = { id: "llama-6-1720B-Instruct", From b11f8758f7b2abe93bf48d18fe44816cec8e80be Mon Sep 17 00:00:00 2001 From: Wauplin Date: Wed, 30 Oct 2024 11:58:26 +0100 Subject: [PATCH 11/11] no need for that --- packages/tasks/scripts/check-snippets.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/tasks/scripts/check-snippets.ts b/packages/tasks/scripts/check-snippets.ts index 4d73eef50d..dc72282ac1 100644 --- a/packages/tasks/scripts/check-snippets.ts +++ b/packages/tasks/scripts/check-snippets.ts @@ -38,7 +38,7 @@ const printSnippets = (snippets: InferenceSnippet | InferenceSnippet[], language const snippetArray = Array.isArray(snippets) ? snippets : [snippets]; snippetArray.forEach((snippet) => { console.log(`\n\x1b[33m${language} ${snippet.client}\x1b[0m`); - console.log(`\n\`\`\`${language.toLowerCase()}\n${snippet.content}\n\`\`\`\n`); + console.log(`\n\`\`\`${language}\n${snippet.content}\n\`\`\`\n`); }); }; @@ -50,6 +50,6 @@ const generateAndPrintSnippets = ( printSnippets(snippets, language); }; -generateAndPrintSnippets(curl.getCurlInferenceSnippet, "Curl"); -generateAndPrintSnippets(python.getPythonInferenceSnippet, "Python"); -generateAndPrintSnippets(js.getJsInferenceSnippet, "JS"); +generateAndPrintSnippets(curl.getCurlInferenceSnippet, "curl"); +generateAndPrintSnippets(python.getPythonInferenceSnippet, "python"); +generateAndPrintSnippets(js.getJsInferenceSnippet, "js");