Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eyurtsev/kor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.0
Choose a base ref
...
head repository: eyurtsev/kor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on Sep 16, 2024

  1. upgrade to langchain-core 0.3 (#317)

    Upgrade to pydantic >= 2, langchain 0.3
    eyurtsev authored Sep 16, 2024
    Copy the full SHA
    bb7c5f6 View commit details
  2. Release 3.0.0 (#318)

    Works with langchain-core 0.3
    eyurtsev authored Sep 16, 2024
    Copy the full SHA
    920fb01 View commit details

Commits on Nov 25, 2024

  1. Update README.md (#323)

    eyurtsev authored Nov 25, 2024
    Copy the full SHA
    f6dc655 View commit details
Showing with 54 additions and 397 deletions.
  1. +0 −82 .github/workflows/_pydantic_compatibility.yml
  2. +0 −8 .github/workflows/test.yml
  3. +9 −0 README.md
  4. +6 −6 kor/extraction/parser.py
  5. +9 −16 kor/prompts.py
  6. +21 −268 poetry.lock
  7. +4 −5 pyproject.toml
  8. +5 −12 tests/utils.py
82 changes: 0 additions & 82 deletions .github/workflows/_pydantic_compatibility.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
@@ -43,10 +42,3 @@ jobs:
- name: Run unit tests
run: |
poetry run poe test
pydantic-compatibility:
uses:
./.github/workflows/_pydantic_compatibility.yml
with:
working-directory: .
secrets: inherit
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,15 @@
[![Open Issues](https://img.shields.io/github/issues-raw/eyurtsev/kor)](https://github.com/eyurtsev/kor/issues)
[![](https://dcbadge.vercel.app/api/server/6adMQxSpJS?compact=true&style=flat)](https://discord.com/channels/1038097195422978059/1170024642245832774)

> [!WARNING]
> If you're using a chat model that supports a tool calling API, you should probably be using the chat models' tool calling API instead of Kor!
>
> Kor is best suited for old style LLMs that did not have a chat interface and did not support tool calling.
>
> Read the [tool calling guide](https://python.langchain.com/docs/concepts/tool_calling/) in LangChain for more details.
>
> Please refer to the [chat model integration table](https://python.langchain.com/docs/integrations/chat/#featured-providers) for a list of chat models that support native tool calling.

# Kor

12 changes: 6 additions & 6 deletions kor/extraction/parser.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from typing import List, Optional

from langchain_core.output_parsers import BaseOutputParser
from pydantic import Extra
from pydantic import ConfigDict

from kor.encoders import Encoder
from kor.exceptions import ParseError
@@ -22,6 +22,7 @@ class KorParser(BaseOutputParser[Extraction]):
encoder: Encoder
schema_: Object
validator: Optional[Validator] = None
model_config = ConfigDict(arbitrary_types_allowed=True)

@property
def _type(self) -> str:
@@ -66,8 +67,7 @@ def parse(self, text: str) -> Extraction:
"validated_data": validated_data,
}

class Config:
"""Configuration for this pydantic object."""

extra = Extra.forbid
arbitrary_types_allowed = True
model_config = ConfigDict(
extra="forbid",
arbitrary_types_allowed=True,
)
25 changes: 9 additions & 16 deletions kor/prompts.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage
from langchain_core.prompt_values import PromptValue
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
from pydantic import ConfigDict

from kor.encoders import Encoder
from kor.encoders.encode import InputFormatter, encode_examples, format_text
@@ -14,12 +15,6 @@
from kor.nodes import Object
from kor.type_descriptors import TypeDescriptor

try:
# Use pydantic v1 namespace since working with langchain
from pydantic.v1 import Extra # type: ignore[assignment]
except ImportError:
from pydantic import Extra # type: ignore[assignment]

from .validators import Validator

DEFAULT_INSTRUCTION_TEMPLATE = PromptTemplate(
@@ -41,11 +36,10 @@ class ExtractionPromptValue(PromptValue):
string: str
messages: List[BaseMessage]

class Config:
"""Configuration for this pydantic object."""

extra = Extra.forbid
arbitrary_types_allowed = True
model_config = ConfigDict(
extra="forbid",
arbitrary_types_allowed=True,
)

def to_string(self) -> str:
"""Format the prompt to a string."""
@@ -65,11 +59,10 @@ class ExtractionPromptTemplate(BasePromptTemplate):
input_formatter: InputFormatter
instruction_template: PromptTemplate

class Config:
"""Configuration for this pydantic object."""

extra = Extra.forbid
arbitrary_types_allowed = True
model_config = ConfigDict(
extra="forbid",
arbitrary_types_allowed=True,
)

def format_prompt( # type: ignore[override]
self,
Loading