{"id":18883389,"url":"https://github.com/dottxt-ai/outlines-core","last_synced_at":"2025-05-15T00:09:17.057Z","repository":{"id":259471544,"uuid":"842172054","full_name":"dottxt-ai/outlines-core","owner":"dottxt-ai","description":"Faster structured generation","archived":false,"fork":false,"pushed_at":"2025-05-08T19:28:56.000Z","size":5106,"stargazers_count":213,"open_issues_count":40,"forks_count":36,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-11T20:44:30.840Z","etag":null,"topics":["fsm","json-schema","llms","regex","structured-generation"],"latest_commit_sha":null,"homepage":"https://docs.rs/outlines-core","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dottxt-ai.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,"zenodo":null}},"created_at":"2024-08-13T20:21:41.000Z","updated_at":"2025-05-09T10:41:56.000Z","dependencies_parsed_at":"2024-10-25T20:08:58.017Z","dependency_job_id":"7efea649-e0a2-4451-a38b-640fdecb65ae","html_url":"https://github.com/dottxt-ai/outlines-core","commit_stats":null,"previous_names":["dottxt-ai/outlines-core","outlines-dev/outlines-core"],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dottxt-ai%2Foutlines-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dottxt-ai%2Foutlines-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dottxt-ai%2Foutlines-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dottxt-ai%2Foutlines-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dottxt-ai","download_url":"https://codeload.github.com/dottxt-ai/outlines-core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253805851,"owners_count":21967052,"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":["fsm","json-schema","llms","regex","structured-generation"],"created_at":"2024-11-08T07:01:57.599Z","updated_at":"2025-05-15T00:09:12.048Z","avatar_url":"https://github.com/dottxt-ai.png","language":"Rust","funding_links":[],"categories":["Python","Rust","NLP"],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"margin-bottom: 1em;\"\u003e\n\n\u003cimg src=\"./docs/assets/images/logo.png\" alt=\"Outlines-core Logo\" width=500\u003e\u003c/img\u003e\n\n[![Latest Version]][crates.io] [![License]][github] ![MSRV][version]\n\n[Latest Version]: https://img.shields.io/crates/v/outlines-core.svg\n[crates.io]: https://crates.io/crates/outlines-core\n[License]: https://img.shields.io/github/license/dottxt-ai/outlines-core.svg?color=blue\u0026cachedrop\n[github]: https://github.com/dottxt-ai/outlines-core/blob/main/LICENSE\n[MSRV]: MSRV\n[version]: https://img.shields.io/crates/msrv/outlines-core.svg?label=msrv\u0026color=lightgrayy\n\n*Structured generation (in Rust).*\n\n\u003c/div\u003e\n\n## Outlines-core\n\nThis package provides the core functionality for structured generation, formerly implemented in [Outlines][outlines],\nwith a focus on performance and portability, it offers a convenient way to:\n\n- build regular expressions from JSON schemas\n\n- construct an `Index` object by combining a `Vocabulary` and regular expression to efficiently map tokens from a given vocabulary to state transitions in a finite-state automation\n\n### Example\n\nBasic example of how it all fits together.\n\n```rust\nuse outlines_core::prelude::*;\n\n// Define a JSON schema\nlet schema = r#\"{\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": { \"type\": \"string\" },\n        \"age\": { \"type\": \"integer\" }\n    },\n    \"required\": [\"name\", \"age\"]\n}\"#;\n\n// Generate a regular expression from it\nlet regex = json_schema::regex_from_str(\u0026schema, None)?;\n\n// Create `Vocabulary` from pretrained large language model (but manually is also possible)\nlet vocabulary = Vocabulary::from_pretrained(\"openai-community/gpt2\", None)?;\n\n// Create new `Index` from regex and a given `Vocabulary`\nlet index = Index::new(\u0026regex, \u0026vocabulary)?;\n\nlet initial_state = index.initial_state();\nlet allowed_tokens = index.allowed_tokens(\u0026initial_state).expect(\"Some allowed token ids\");\nlet token_id = allowed_tokens.first().expect(\"First token id\");\nlet next_state = index.next_state(\u0026initial_state, token_id);\nlet final_states = index.final_states();\n```\n\n## Python Bindings\n\nAdditionally, project provides interfaces to integrate the crate's functionality with Python.\n\n``` python\nimport json\n\nfrom outlines_core.json_schema import build_regex_from_schema\nfrom outlines_core.guide import Guide, Index, Vocabulary\n\nschema =  {\n  \"title\": \"Foo\",\n  \"type\": \"object\",\n  \"properties\": {\"date\": {\"type\": \"string\", \"format\": \"date\"}}\n}\nregex = build_regex_from_schema(json.dumps(schema))\n\nvocabulary = Vocabulary.from_pretrained(\"openai-community/gpt2\")\nindex = Index(regex, vocabulary)\nguide = Guide(index)\n\n# Get current state of the Guide:\ncurrent_state = guide.get_state()\n\n# Get allowed tokens for the current state of the Guide:\nallowed_tokens = guide.get_tokens()\n\n# Advance Guide to the next state via some token_id and return allowed tokens for that new state:\nnext_allowed_tokens = guide.advance(allowed_tokens[-1])\n\n# To check if Guide is finished:\nguide.is_finished()\n\n# If it's finished then this assertion holds:\nassert guide.get_tokens() == [vocabulary.get_eos_token_id()]\n```\n\n## How to contribute?\n\n### Setup\n\nFork the repository on GitHub and clone the fork locally:\n\n```bash\ngit clone git@github.com/YourUserName/outlines-core.git\ncd outlines-core\n```\n\nCreate a new virtual environment and install the dependencies in editable mode:\n\n``` bash\npython -m venv .venv\nsource .venv/bin/activate\npip install -e \".[test]\"\npre-commit install\n```\n\n### Before pushing your code\n\nIf working with Python bindings don't forget to build Rust extension before testing, for example, in debug mode:\n\n```bash\nmake build-extension-debug\n```\n\nRun Python tests:\n\n``` bash\npytest\n```\n\nRun Rust tests:\n\n``` bash\ncargo test\n```\n\nOr alternatively using Makefile for both:\n\n``` bash\nmake test\n```\n\nFinally, run the code style checks:\n\n``` bash\npre-commit run --all-files\n```\n\nOr using Makefile:\n\n``` bash\nmake pcc\n```\n\nIf necessary you can run benchmarks locally:\n\n``` bash\nmake pybench\n```\n\n## Join us\n\n- 💡 **Have an idea?** Come chat with us on [Discord][discord]\n-  **Found a bug?** Open an [issue](https://github.com/dottxt-ai/outlines-core/issues)\n\n[outlines]: https://github.com/dottxt-ai/outlines\n[discord]: https://discord.gg/R9DSu34mGd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdottxt-ai%2Foutlines-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdottxt-ai%2Foutlines-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdottxt-ai%2Foutlines-core/lists"}