https://github.com/eyurtsev/kor Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. {{ message }} eyurtsev / kor Public * Notifications * Fork 52 * Star 843 LLM() eyurtsev.github.io/kor/ License MIT license 843 stars 52 forks Star Notifications * Code * Issues 13 * Pull requests 4 * Discussions * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights eyurtsev/kor This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 4 branches 15 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/e] Use Git or checkout with SVN using the web URL. [gh repo clone eyurts] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @Seb0 Seb0 fix(docs): typo (#167) ... 7a617c3 May 26, 2023 fix(docs): typo (#167) tiniest PR record attempt, jk, great project ;) 7a617c3 Git stats * 195 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Add minimal HTML processing (#123) April 6, 2023 22:29 docs fix(docs): typo (#167) May 26, 2023 10:25 kor Add boolean type (#165) May 24, 2023 18:14 tests Add boolean type (#165) May 24, 2023 18:14 .gitignore Update February 19, 2023 10:08 CONTRIBUTING.md Update CONTRIBUTING.md (#134) April 22, 2023 15:24 LICENSE Update February 16, 2023 14:46 README.md More doc updates (#160) May 16, 2023 22:14 poetry.lock Add boolean type (#165) May 24, 2023 18:14 pyproject.toml Version 0.10.0 (#166) May 25, 2023 11:26 View code [ ] Kor Kor style schema Pydantic style schema Compatibility Installation Ideas Prototype What does Kor excel at? Limitations Got Ideas? Why the name? Contributing Other packages README.md [?] WARNING: Prototype with unstable API. Unit Tests Test Docs Kor This is a half-baked prototype that "helps" you extract structured data from text using LLMs . Specify the schema of what should be extracted and provide some examples. Kor will generate a prompt, send it to the specified LLM and parse out the output. You might even get results back. So yes - it's just another wrapper on top of LLMs with its own flavor of abstractions. See documentation. Integrated with the LangChain framework . Kor style schema from langchain.chat_models import ChatOpenAI from kor import create_extraction_chain, Object, Text llm = ChatOpenAI( model_name="gpt-3.5-turbo", temperature=0, max_tokens=2000, frequency_penalty=0, presence_penalty=0, top_p=1.0, ) schema = Object( id="player", description=( "User is controlling a music player to select songs, pause or start them or play" " music by a particular artist." ), attributes=[ Text( id="song", description="User wants to play this song", examples=[], many=True, ), Text( id="album", description="User wants to play this album", examples=[], many=True, ), Text( id="artist", description="Music by the given artist", examples=[("Songs by paul simon", "paul simon")], many=True, ), Text( id="action", description="Action to take one of: `play`, `stop`, `next`, `previous`.", examples=[ ("Please stop the music", "stop"), ("play something", "play"), ("play a song", "play"), ("next song", "next"), ], ), ], many=False, ) chain = create_extraction_chain(llm, schema, encoder_or_encoder_class='json') chain.predict_and_parse(text="play songs by paul simon and led zeppelin and the doors")['data'] {'player': {'artist': ['paul simon', 'led zeppelin', 'the doors']}} Pydantic style schema * See documentation here pydantic. class Action(enum.Enum): play = "play" stop = "stop" previous = "previous" next_ = "next" class MusicRequest(BaseModel): song: Optional[List[str]] = Field( description="The song(s) that the user would like to be played." ) album: Optional[List[str]] = Field( description="The album(s) that the user would like to be played." ) artist: Optional[List[str]] = Field( description="The artist(s) whose music the user would like to hear.", examples=[("Songs by paul simon", "paul simon")], ) action: Optional[Action] = Field( description="The action that should be taken; one of `play`, `stop`, `next`, `previous`", examples=[ ("Please stop the music", "stop"), ("play something", "play"), ("play a song", "play"), ("next song", "next"), ], ) schema, validator = from_pydantic(MusicRequest) chain = create_extraction_chain( llm, schema, encoder_or_encoder_class="json", validator=validator ) chain.predict_and_parse(text="stop the music now")["validated_data"] MusicRequest(song=None, album=None, artist=None, action=) Compatibility Kor is tested against python 3.8, 3.9, 3.10, 3.11. Installation pip install kor Ideas Ideas of some things that could be done with Kor. * Extract data from text that matches an extraction schema. * Power an AI assistant with skills by precisely understanding a user request. * Provide natural language access to an existing API. Prototype Prototype! So the API is not expected to be stable! What does Kor excel at? * Making mistakes! Plenty of them! * Slow! It uses large prompts with examples, and works best with the larger slower LLMs. * Crashing for long enough pieces of text! Context length window could become limiting when working with large forms or long text inputs. The expectation is that as LLMs improve some of these issues will be mitigated. Limitations Kor has no limitations. (Just kidding.) Take a look at the section above and at the compatibility section. Got Ideas? Open an issue, and let's discuss! Why the name? Fast to type and sufficiently unique. Contributing If you have any ideas or feature requests, please open an issue and share! See CONTRIBUTING.md for more information. Other packages Probabilistically speaking this package is unlikely to work for your use case. So here are some great alternatives: * Promptify * MiniChain About LLM() eyurtsev.github.io/kor/ Topics natural-language-processing natural-language information-extraction natural-language-understanding llm Resources Readme License MIT license Stars 843 stars Watchers 11 watching Forks 52 forks Report repository Releases 15 Version 0.10.0 Latest May 25, 2023 + 14 releases Packages 0 No packages published Used by 42 * @yoenoo * @fenago * @sujanMidatani7 * @dongbln * @AnMol12499 * @nipdep * @chris-lovejoy * @rlancemartin + 34 Contributors 6 * @eyurtsev * @tomdyson * @Seb0 * @hwchase17 * @vbarda * @rishabhjain1198 Languages * Python 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.