Created
July 30, 2023 00:24
-
-
Save hwchase17/852c3ef78c289f90913714472b832305 to your computer and use it in GitHub Desktop.
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
from langchain.chat_models import ChatAnthropic | |
from kor import create_extraction_chain, Object, Text | |
llm = ChatAnthropic( | |
model_name="claude-v2", | |
temperature=0, | |
max_tokens=2000, | |
) | |
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, | |
) | |
# specify encoder_or_encoder_class='xml' since Claude is very good at XML | |
chain = create_extraction_chain(llm, schema, encoder_or_encoder_class='xml') | |
chain.run("play songs by paul simon and led zeppelin and the doors")['data'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment