chain.run(inp)
{'sentiment': 'enojado', 'aggressiveness': 1, 'language': 'Spanish'}
inp = "Weather is ok here, I can go outside without much more than a coat"
chain.run(inp)
{'sentiment': 'positive', 'aggressiveness': 0, 'language': 'English'}
More control#
By being smart about how we define our schema we can have more control over the model’s output. Specifically we can define:
possible values for each property
description to make sure that the model understands the property
required properties to be returned
Following is an example of how we can use enum, description and required to control for each of the previously mentioned aspects:
schema = {
      "properties": {
          "sentiment": {"type": "string", "enum": ["happy", "neutral", "sad"]}, 
          "aggressiveness": {"type": "integer", "enum": [1,2,3,4,5], "description": "describes how aggressive the statement is, the higher the number the more aggressive"},
          "language": {"type": "string", "enum": ["spanish", "english", "french", "german", "italian"]},
              },
        "required": ["language", "sentiment", "aggressiveness"]
    }
chain = create_tagging_chain(schema, llm)
Now the answers are much better!
inp = "Estoy increiblemente contento de haberte conocido! Creo que seremos muy buenos amigos!"
chain.run(inp)
{'sentiment': 'happy', 'aggressiveness': 0, 'language': 'spanish'}
inp = "Estoy muy enojado con vos! Te voy a dar tu merecido!"
chain.run(inp)
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/tagging.html