Human#
If you want to get the user to participate in chain logic, or to substitute in for an LLM, you can do so using the Human LLM class:
[1]:
from langchain_contrib.llms.human import Human
llm = Human()
llm("Enter something: ")
Enter something: Something
[1]:
'Something'
By default, the LLM returns the very first thing the user enters. If you want multiline output from the human, you can enforce stops:
[5]:
human_response = llm("Write me a Python script\n\n```\n", stop=["\n```"])
print(f"The human entered in:\n\n{human_response}")
Write me a Python script
```
#!/usr/bin/env python3
print('Hi')
```
The human entered in:
#!/usr/bin/env python3
print('Hi')
BaseHuman#
The basic Human commandline input functionality is provided by the BaseHuman class. You can override its _call function to customize how the input is handled.
For example, Human itself overrides BaseHuman._call to present a menu when encountering prompts from ChoicePromptTemplate. To check this functionality out, run the following snippet in your terminal:
from langchain_contrib.llms.human import Human
from langchain_contrib.prompts import ChoicePromptTemplate
llm = Human()
choice = ChoicePromptTemplate.from_template(
"""
The colors available are: {choices}
Pick a color: """.lstrip(),
choices=["Red", "Orange", "Blue"],
)
llm(choice.format())
(this can’t be run in the notebook due to a lack of /dev/tty)