I had been planning to write a similar library myself (for encyclopaedic article generation) and was pleasantly surprised when I saw that you guys had beaten me to it.
I'm looking through the code now -- with the intention of contributing code for my specific purposes -- I have a bunch of questions, which I'm documenting here and attempting to answer for myself as I go through them, but help would be appreciated on the unanswered ones!
Function
There seem to be multiple ways to call a chain, e.g. _call, run, apply, predict, generate. What's the difference between them?
OK I see: __call__ (the method Python calls by default when you try to use a Python class as a function) is defined at the Chain level, so all chains have the same implementation -- but it depends on _call, which is defined differently for each subclass.
apply is just __call__ applied pointwise to a list of inputs. run just removes the dict wrapping from the output of __call__.
generate and predict are specifically methods for LLMchains. generate operates on lists and returns an object of type LLMResult, which can contain metadata in addition to the result. predict is the straightforward version.
Conventions for providing examples in prompts -- I recall that Prompt was configured to admit examples as an option, but e.g. the stuff chain has it built-into EXAMPLE_PROMPT ... ?
Style
Any reason why everything is defined as a class variable? It makes sense to me for things like 'input_key and output_key but e.g. StuffDocumentsChain.llm_chain, document_variable_name are only provided type hints and not assigned values at the class level, so aren't they better thought of as instance variables?
Dev Tools & Setting up
I'm having trouble using Poetry on Codespaces. The instructions don't seem to help.
This I figured out -- the virtual environment isn't activated by default. Codespaces has Poetry installed by default, so you just need to run source .venv/bin/activate.
Pylint and Pylance give errors on the existing code -- e.g. import errors (although everything is actually imported, and can be used in runtime).
I had been planning to write a similar library myself (for encyclopaedic article generation) and was pleasantly surprised when I saw that you guys had beaten me to it.
I'm looking through the code now -- with the intention of contributing code for my specific purposes -- I have a bunch of questions, which I'm documenting here and attempting to answer for myself as I go through them, but help would be appreciated on the unanswered ones!
Function
OK I see:
__call__
(the method Python calls by default when you try to use a Python class as a function) is defined at theChain
level, so all chains have the same implementation -- but it depends on_call
, which is defined differently for each subclass.apply
is just__call__
applied pointwise to a list of inputs.run
just removes the dict wrapping from the output of__call__
.generate
andpredict
are specifically methods for LLMchains.generate
operates on lists and returns an object of typeLLMResult
, which can contain metadata in addition to the result.predict
is the straightforward version.Style
Dev Tools & Setting up
This I figured out -- the virtual environment isn't activated by default. Codespaces has Poetry installed by default, so you just need to run
source .venv/bin/activate
.