viruPVS/langchain-docs huggingface dataset:
To mark a field as configurable, see the configurable_fields
and configurable_alternatives methods.
Parameters
include – A list of fields to include in the config schema.
Returns
A pydantic model that can be used to validate config.
configurable_alternatives(which: ConfigurableField, *, default_key: str = 'default', prefix_keys: bool = False, **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶
configurable_fields(**kwargs: Union[ConfigurableField, ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]) → RunnableSerializable[Input, Output]¶
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep – set to True to make a deep copy of the model
Returns
new model instance
deactivate_selection_scorer() → None¶
Returns
new model instance
deactivate_selection_scorer() → None¶
Deactivates the selection scorer, meaning that the chain will no longer attempt to use the selection scorer to score responses.
dict(**kwargs: Any) → Dict¶
Dictionary representation of chain.
Expects Chain._chain_type property to be implemented and for memory to benull.
Parameters
**kwargs – Keyword arguments passed to default pydantic.BaseModel.dict
method.
Returns
A dictionary representation of the chain.
Example
chain.dict(exclude_unset=True)
# -> {"_type": "foo", "verbose": False, ...}
classmethod from_llm(llm: ~langchain_core.language_models.base.BaseLanguageModel, prompt: ~langchain_core.prompts.base.BasePromptTemplate, selection_scorer: ~typing.Union[~langchain_experimental.rl_chain.base.AutoSelectionScorer, object] = <object object>, **kwargs: ~typing.Any) → PickBest[source]¶
classmethod from_orm(obj: Any) → Model¶
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
context = "Weather report for Boise, Idaho on 07/03/23..."
chain.run(question=question, context=context)
# -> "The temperature in Boise is..."
save(file_path: Union[Path, str]) → None¶
Save the chain.
Expects Chain._chain_type property to be implemented and for memory to benull.
Parameters
file_path – Path to file to save the chain to.
Example
chain.save(file_path="path/chain.yaml")
save_progress() → None¶
This function should be called to save the state of the learned policy model.
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
stream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of stream, which calls invoke.
Subclasses should override this method if they support streaming output.
to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶
to_json_not_implemented() → SerializedNotImplemented¶
transform(input: Iterator[Input], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of transform, which buffers input and then calls stream.
Subclasses should override this method if they can start producing output while
input is still being generated.
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
update_with_delayed_score(score: float, chain_response: Dict[str, Any], force_score: bool = False) → None¶
Updates the learned policy with the score provided.
Updates the learned policy with the score provided.
Will raise an error if selection_scorer is set, and force_score=True was not provided during the method call
classmethod validate(value: Any) → Model¶
with_config(config: Optional[RunnableConfig] = None, **kwargs: Any) → Runnable[Input, Output]¶
Bind config to a Runnable, returning a new Runnable.
with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,)) → RunnableWithFallbacksT[Input, Output]¶
Add fallbacks to a runnable, returning a new Runnable.
Parameters
fallbacks – A sequence of runnables to try if the original runnable fails.
exceptions_to_handle – A tuple of exception types to handle.
Returns
A new Runnable that will try the original runnable, and then each
fallback in order, upon failures.
with_listeners(*, on_start: Optional[Listener] = None, on_end: Optional[Listener] = None, on_error: Optional[Listener] = None) → Runnable[Input, Output]¶
Bind lifecycle listeners to a Runnable, returning a new Runnable.
on_start: Called before the runnable starts running, with the Run object.
on_end: Called after the runnable finishes running, with the Run object.
on_error: Called if the runnable throws an error, with the Run object.
The Run object contains information about the run, including its id,
type, input, output, error, start_time, end_time, and any tags or metadata
added to the run.
added to the run.
with_retry(*, retry_if_exception_type: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,), wait_exponential_jitter: bool = True, stop_after_attempt: int = 3) → Runnable[Input, Output]¶
Create a new Runnable that retries the original runnable on exceptions.
Parameters
retry_if_exception_type – A tuple of exception types to retry on
wait_exponential_jitter – Whether to add jitter to the wait time
between retries
stop_after_attempt – The maximum number of attempts to make before giving up
Returns
A new Runnable that retries the original runnable on exceptions.
with_types(*, input_type: Optional[Type[Input]] = None, output_type: Optional[Type[Output]] = None) → Runnable[Input, Output]¶
Bind input and output types to a Runnable, returning a new Runnable.
property InputType: Type[langchain_core.runnables.utils.Input]¶
The type of input this runnable accepts specified as a type annotation.
property OutputType: Type[langchain_core.runnables.utils.Output]¶
The type of output this runnable produces specified as a type annotation.
property config_specs: List[langchain_core.runnables.utils.ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_keys: List[str]¶
Expect input key.
:meta private:
property input_schema: Type[pydantic.main.BaseModel]¶
The type of input this runnable accepts specified as a pydantic model.
property lc_attributes: Dict¶
List of attribute names that should be included in the serialized kwargs.
These attributes must be accepted by the constructor.
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
langchain_experimental.rl_chain.model_repository.ModelRepository¶
class langchain_experimental.rl_chain.model_repository.ModelRepository(folder: Union[str, PathLike], with_history: bool = True, reset: bool = False)[source]¶
Methods
__init__(folder[, with_history, reset])
get_tag()
has_history()
load(commandline)
save(workspace)
__init__(folder: Union[str, PathLike], with_history: bool = True, reset: bool = False)[source]¶
get_tag() → str[source]¶
has_history() → bool[source]¶
load(commandline: List[str]) → vw.Workspace[source]¶
save(workspace: vw.Workspace) → None[source]¶
langchain_experimental.rl_chain.pick_best_chain.PickBestFeatureEmbedder¶
class langchain_experimental.rl_chain.pick_best_chain.PickBestFeatureEmbedder(auto_embed: bool, model: Optional[Any] = None, *args: Any, **kwargs: Any)[source]¶
Text Embedder class that embeds the BasedOn and ToSelectFrom inputs into a format that can be used by the learning policy
model name
The type of embeddings to be used for feature representation. Defaults to BERT SentenceTransformer.
Type
Any, optional
Methods
__init__(auto_embed[, model])
format(event)
format_auto_embed_off(event)
Converts the BasedOn and ToSelectFrom into a format that can be used by VW
format_auto_embed_on(event)
get_context_and_action_embeddings(event)
get_indexed_dot_product(context_emb, action_embs)
get_label(event)
__init__(auto_embed: bool, model: Optional[Any] = None, *args: Any, **kwargs: Any)[source]¶
format(event: PickBestEvent) → str[source]¶
format_auto_embed_off(event: PickBestEvent) → str[source]¶
Converts the BasedOn and ToSelectFrom into a format that can be used by VW
format_auto_embed_on(event: PickBestEvent) → str[source]¶
get_context_and_action_embeddings(event: PickBestEvent) → tuple[source]¶
get_indexed_dot_product(context_emb: List, action_embs: List) → Dict[source]¶
get_label(event: PickBestEvent) → tuple[source]¶
langchain_experimental.rl_chain.pick_best_chain.PickBestRandomPolicy¶
class langchain_experimental.rl_chain.pick_best_chain.PickBestRandomPolicy(feature_embedder: Embedder, **kwargs: Any)[source]¶
Methods
__init__(feature_embedder, **kwargs)
learn(event)
log(event)
predict(event)
save()
__init__(feature_embedder: Embedder, **kwargs: Any)[source]¶
learn(event: PickBestEvent) → None[source]¶
log(event: PickBestEvent) → None[source]¶
predict(event: PickBestEvent) → List[Tuple[int, float]][source]¶
save() → None¶