Spaces:
Sleeping
Sleeping
Update extract_app.py
Browse files- extract_app.py +4 -19
extract_app.py
CHANGED
@@ -9,9 +9,9 @@ from pydantic import BaseModel, Field
|
|
9 |
|
10 |
from langchain.chains.openai_functions.extraction import create_extraction_chain_pydantic
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
-
from langchain.prompts import ChatPromptTemplate
|
13 |
from langchain.pydantic_v1 import BaseModel
|
14 |
-
from langchain.utils.openai_functions import convert_pydantic_to_openai_function
|
15 |
|
16 |
from dotenv import load_dotenv
|
17 |
load_dotenv()
|
@@ -26,26 +26,11 @@ class Person(BaseModel):
|
|
26 |
"""Information about people to extract."""
|
27 |
|
28 |
name: str
|
29 |
-
age: Optional[int]
|
30 |
|
31 |
# Main function to extract information
|
32 |
def extract_information():
|
33 |
# Make sure to use a recent model that supports tools
|
34 |
llm = ChatOpenAI(model="gpt-3.5-turbo-1106")
|
35 |
|
36 |
-
return create_extraction_chain_pydantic(Person, llm)
|
37 |
-
|
38 |
-
|
39 |
-
if __name__ == "__main__":
|
40 |
-
text = "My name is John and I am 20 years old. My name is sally and I am 30 years old."
|
41 |
-
chain = extract_information()
|
42 |
-
print(chain.invoke({"input": text})["text"])
|
43 |
-
|
44 |
-
async def extract_information_async(message: str):
|
45 |
-
return chain.invoke({"input": message})["text"]
|
46 |
-
|
47 |
-
async def main():
|
48 |
-
res = await extract_information_async(text)
|
49 |
-
print(res)
|
50 |
-
|
51 |
-
asyncio.run(main())
|
|
|
9 |
|
10 |
from langchain.chains.openai_functions.extraction import create_extraction_chain_pydantic
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
+
# from langchain.prompts import ChatPromptTemplate
|
13 |
from langchain.pydantic_v1 import BaseModel
|
14 |
+
# from langchain.utils.openai_functions import convert_pydantic_to_openai_function
|
15 |
|
16 |
from dotenv import load_dotenv
|
17 |
load_dotenv()
|
|
|
26 |
"""Information about people to extract."""
|
27 |
|
28 |
name: str
|
29 |
+
age: Optional[int]
|
30 |
|
31 |
# Main function to extract information
|
32 |
def extract_information():
|
33 |
# Make sure to use a recent model that supports tools
|
34 |
llm = ChatOpenAI(model="gpt-3.5-turbo-1106")
|
35 |
|
36 |
+
return create_extraction_chain_pydantic(Person, llm)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|