-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Use run instead of predict_and_parse (#188)
Related issue #185 This PR set the KorParser as the OutputParser on the LLMChain. This is needed, since `predict_and_parse` on the LLMChain is deprecated and `run` should be used. For this minimum LangChain version is raised to 0.0.205. This PR includes - Needed changes to code - Needed change to documentation - A minimal integration test (needs OpenAI API key) to be sure, things are still working correct
- Loading branch information
1 parent
eebb05f
commit ba20aa1
Showing
8 changed files
with
684 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from langchain.chat_models import ChatOpenAI | ||
from pydantic import BaseModel, Field | ||
|
||
from kor.adapters import from_pydantic | ||
from kor.extraction import create_extraction_chain | ||
|
||
|
||
def test_pydantic() -> None: | ||
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0, max_tokens=2000) | ||
|
||
class Person(BaseModel): | ||
first_name: str = Field( | ||
description="The first name of a person.", | ||
) | ||
|
||
schema, v = from_pydantic( | ||
Person, | ||
description="Personal information", | ||
examples=[ | ||
( | ||
"Alice and Bob are friends", | ||
{"first_name": "Alice"}, | ||
) | ||
], | ||
many=True, | ||
) | ||
|
||
chain = create_extraction_chain(llm, schema) | ||
result = chain.run("My name is Bobby. My brother's name Joe.") # type: ignore | ||
data = result["data"] # type: ignore | ||
|
||
assert "person" in data # type: ignore | ||
assert len(data["person"]) == 2 # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters