{"id":17914414,"url":"https://github.com/lawvs/guesslang-worker","last_synced_at":"2026-05-09T09:53:46.486Z","repository":{"id":225374123,"uuid":"765805348","full_name":"lawvs/guesslang-worker","owner":"lawvs","description":"🤖 A worker that uses guesslang's ML model to detect source code languages","archived":false,"fork":false,"pushed_at":"2024-03-03T14:44:44.000Z","size":668,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T21:22:03.080Z","etag":null,"topics":["cloudflare-worker","deep-learning","guesslang","hono","languagedetection","tensorflow"],"latest_commit_sha":null,"homepage":"https://guesslang.waterwater.moe/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lawvs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-01T16:45:59.000Z","updated_at":"2024-10-30T12:40:55.000Z","dependencies_parsed_at":"2024-10-28T19:58:22.376Z","dependency_job_id":"e14bdd2a-7842-40e3-9190-b1990c2cd47d","html_url":"https://github.com/lawvs/guesslang-worker","commit_stats":null,"previous_names":["lawvs/guesslang-worker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fguesslang-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fguesslang-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fguesslang-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fguesslang-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lawvs","download_url":"https://codeload.github.com/lawvs/guesslang-worker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246961637,"owners_count":20861174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-worker","deep-learning","guesslang","hono","languagedetection","tensorflow"],"created_at":"2024-10-28T19:58:14.929Z","updated_at":"2026-05-09T09:53:46.425Z","avatar_url":"https://github.com/lawvs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎲 Guesslang Worker\n\n[![Build](https://github.com/lawvs/guesslang-worker/actions/workflows/build.yml/badge.svg)](https://github.com/lawvs/guesslang-worker/actions/workflows/build.yml)\n\n🤖 A worker that uses guesslang's ML model to detect source code languages\n\nPowered by [vscode-languagedetection](https://github.com/microsoft/vscode-languagedetection)!\n\n## Usage\n\nYou can access the worker at https://guesslang.waterwater.moe/guess?text=YOUR_CODE\n\nAlternatively, you can utilize the POST method to send a JSON object containing the `text` key.\n\n```ts\nconst resp = await fetch(\"https://guesslang.waterwater.moe/guess\", {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({\n    text: \"const root = ReactDOM.createRoot\",\n    // verbose: false, // Show more information about the detection. default: false\n  }),\n});\nconst data = await resp.json();\nconsole.log(data);\n// { languageId: 'js', languageName: 'JavaScript', confidence: 0.07452436648309231, reliable: false }\n```\n\n```sh\ncurl 'https://guesslang.waterwater.moe/guess' \\\n  -H 'content-type: application/json' \\\n  --data-raw '{ \"text\": \"const root = ReactDOM.createRoot\", \"verbose\": false }'\n```\n\n## Development\n\n```sh\npnpm install\npnpm run dev\n```\n\nTo run the tests, simply run `pnpm test`.\n\nTo deploy this worker, run `pnpm run deploy`\n\n## API\n\n### TypeScript Definitions\n\n```ts\nexport type DetectionOptions = {\n  /**\n   * Fine-tune the model results.\n   *\n   * Enabling this flag will increase the confidence of certain languages commonly used in VS Code and supported by the model.\n   *\n   * @default true\n   */\n  fineTune: boolean;\n  /**\n   * Show `modelResults` information in the response.\n   *\n   * @default false\n   */\n  verbose: boolean;\n  /**\n   * The expected relative confidence to consider a detection reliable.\n   *\n   * @default 0.2\n   */\n  expectedRelativeConfidence: number;\n};\n\nexport type DetectionResult = {\n  languageId: string;\n  languageName: string;\n  /**\n   * The relative confidence of the detection.\n   */\n  confidence: number;\n  /**\n   * Whether the detection is reliable.\n   *\n   * It will be `false` if the confidence is lower than `expectedRelativeConfidence`.\n   */\n  reliable: boolean;\n  /**\n   * Only available when `verbose` is `true`.\n   */\n  modelResults?: ModelResult[];\n};\n\nexport interface ModelResult {\n  languageId: string;\n  confidence: number;\n}\n```\n\n### `GET /guess`\n\n#### Query Parameters\n\n- `text` (required): The source code to detect the language of\n- `verbose` (optional): Show more information about the detection. default: false\n- `fineTune` (optional): Finetune the detection. default: false\n- `expectedRelativeConfidence` (optional): The expected relative confidence to consider a detection reliable. default: 0.2\n\n### `POST /guess`\n\n#### Request Body\n\n```json\n{\n  \"text\": \"YOUR_CODE\",\n  \"verbose\": false,\n  \"fineTune\": false,\n  \"expectedRelativeConfidence\": 0.2\n}\n```\n\n#### Example Response\n\n```json\n{\n  \"languageId\": \"js\",\n  \"languageName\": \"JavaScript\",\n  \"confidence\": 0.1,\n  \"reliable\": false\n}\n```\n\n## Credits\n\n- [guesslang](https://github.com/yoeo/guesslang)\n- [vscode-languagedetection](https://github.com/microsoft/vscode-languagedetection)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawvs%2Fguesslang-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flawvs%2Fguesslang-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawvs%2Fguesslang-worker/lists"}