mirror of
https://github.com/hwchase17/langchain
synced 2024-11-11 19:11:02 +00:00
3b07c0cf3d
- Description: This PR adds a new chain `rl_chain.PickBest` for learned prompt variable injection, detailed description and usage can be found in the example notebook added. It essentially adds a [VowpalWabbit](https://github.com/VowpalWabbit/vowpal_wabbit) layer before the llm call in order to learn or personalize prompt variable selections. Most of the code is to make the API simple and provide lots of defaults and data wrangling that is needed to use Vowpal Wabbit, so that the user of the chain doesn't have to worry about it. - Dependencies: [vowpal-wabbit-next](https://pypi.org/project/vowpal-wabbit-next/), - sentence-transformers (already a dep) - numpy (already a dep) - tagging @ataymano who contributed to this chain - Tag maintainer: @baskaryan - Twitter handle: @olgavrou Added example notebook and unit tests
16 lines
447 B
Python
16 lines
447 B
Python
from typing import Any, List
|
|
|
|
|
|
class MockEncoder:
|
|
def encode(self, to_encode: str) -> str:
|
|
return "[encoded]" + to_encode
|
|
|
|
|
|
class MockEncoderReturnsList:
|
|
def encode(self, to_encode: Any) -> List:
|
|
if isinstance(to_encode, str):
|
|
return [1.0, 2.0]
|
|
elif isinstance(to_encode, List):
|
|
return [[1.0, 2.0] for _ in range(len(to_encode))]
|
|
raise ValueError("Invalid input type for unit test")
|