Tony20100/langchain_full huggingface dataset:
langchain_community.chat_models.litellm.ChatLiteLLM¶
class langchain_community.chat_models.litellm.ChatLiteLLM[source]¶
Bases: BaseChatModel
Chat model that uses the LiteLLM API.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param anthropic_api_key: Optional[str] = None¶
param api_base: Optional[str] = None¶
param azure_api_key: Optional[str] = None¶
param cache: Union[BaseCache, bool, None] = None¶
Whether to cache the response.
If true, will use the global cache.
If false, will not use a cache
If None, will use the global cache if it’s set, otherwise no cache.
If instance of BaseCache, will use the provided cache.
Caching is not currently supported for streaming methods of models.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Callback manager to add to the run trace.
param callbacks: Callbacks = None¶
Callbacks to add to the run trace.
param cohere_api_key: Optional[str] = None¶
param custom_get_token_ids: Optional[Callable[[str], List[int]]] = None¶
Optional encoder to use for counting tokens.
param custom_llm_provider: Optional[str] = None¶
param max_retries: int = 6¶
param max_tokens: int = 256¶
param metadata: Optional[Dict[str, Any]] = None¶
Metadata to add to the run trace.
param model: str = 'gpt-3.5-turbo'¶
param model_kwargs: Dict[str, Any] [Optional]¶
Run inference with this temperature. Must by in the closed
Run inference with this temperature. Must by in the closed
interval [0.0, 1.0].
param model_name: Optional[str] = None¶
Model name to use.
param n: int = 1¶
Number of chat completions to generate for each prompt. Note that the API may
not return the full n completions if duplicates are generated.
param openai_api_key: Optional[str] = None¶
param openrouter_api_key: Optional[str] = None¶
param organization: Optional[str] = None¶
param replicate_api_key: Optional[str] = None¶
param request_timeout: Optional[Union[float, Tuple[float, float]]] = None¶
param streaming: bool = False¶
param tags: Optional[List[str]] = None¶
Tags to add to the run trace.
param temperature: Optional[float] = 1¶
param top_k: Optional[int] = None¶
Decode using top-k sampling: consider the set of top_k most probable tokens.
Must be positive.
param top_p: Optional[float] = None¶
Decode using nucleus sampling: consider the smallest set of tokens whose
probability sum is at least top_p. Must be in the closed interval [0.0, 1.0].
param verbose: bool [Optional]¶
Whether to print out response text.
__call__(messages: List[BaseMessage], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → BaseMessage¶
[Deprecated]
Notes
Deprecated since version langchain-core==0.1.7: Use invoke instead.
Parameters
messages (List[BaseMessage]) – 
stop (Optional[List[str]]) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) –
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
kwargs (Any) – 
Return type
BaseMessage
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode.
Parameters
inputs (List[Input]) – 
config (Optional[Union[RunnableConfig, List[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
List[Output]
async abatch_as_completed(inputs: Sequence[Input], config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → AsyncIterator[Tuple[int, Union[Output, Exception]]]¶
Run ainvoke in parallel on a list of inputs,
yielding results as they complete.
Parameters
inputs (Sequence[Input]) – 
config (Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
AsyncIterator[Tuple[int, Union[Output, Exception]]]
kwargs (Any) – 
Return type
Runnable[LanguageModelInput, BaseMessage]
call_as_llm(message: str, stop: Optional[List[str]] = None, **kwargs: Any) → str¶
[Deprecated]
Notes
Deprecated since version langchain-core==0.1.7: Use invoke instead.
Parameters
message (str) – 
stop (Optional[List[str]]) – 
kwargs (Any) – 
Return type
str
completion_with_retry(run_manager: Optional[CallbackManagerForLLMRun] = None, **kwargs: Any) → Any[source]¶
Use tenacity to retry the completion call.
Parameters
run_manager (Optional[CallbackManagerForLLMRun]) – 
kwargs (Any) – 
Return type
Any
config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶
The type of config this runnable accepts specified as a pydantic model.
To mark a field as configurable, see the configurable_fields
and configurable_alternatives methods.
Parameters
include (Optional[Sequence[str]]) – A list of fields to include in the config schema.
Returns
A pydantic model that can be used to validate config.
Return type
Type[BaseModel]
configurable_alternatives(which: ConfigurableField, *, default_key: str = 'default', prefix_keys: bool = False, **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶
Configure alternatives for runnables that can be set at runtime.
from langchain_anthropic import ChatAnthropic
from langchain_core.runnables.utils import ConfigurableField
from langchain_openai import ChatOpenAI
model = ChatAnthropic(
Not implemented on this class.
Parameters
schema (Union[Dict, Type[BaseModel]]) – 
kwargs (Any) – 
Return type
Runnable[Union[PromptValue, str, Sequence[Union[BaseMessage, List[str], Tuple[str, str], str, Dict[str, Any]]]], Union[Dict, BaseModel]]
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.
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: TypeAlias¶
Get the input type for this runnable.
property OutputType: Any¶
Get the output type for this runnable.
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_schema: Type[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.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using ChatLiteLLM¶
ChatLiteLLM
langchain.chat_models.base.init_chat_model¶
langchain.chat_models.base.init_chat_model(model: str, *, model_provider: Optional[str] = None, **kwargs: Any) → BaseChatModel[source]¶
[Beta] Initialize a ChatModel from the model name and provider.
Must have the integration package corresponding to the model provider installed.
Parameters
model (str) – The name of the model, e.g. “gpt-4o”, “claude-3-opus-20240229”.
model_provider (Optional[str]) – The model provider. Supported model_provider values and the
corresponding integration package:
openai (langchain-openai)
anthropic (langchain-anthropic)
azure_openai (langchain-openai)
google_vertexai (langchain-google-vertexai)
google_genai (langchain-google-genai)
bedrock (langchain-aws)
cohere (langchain-cohere)
fireworks (langchain-fireworks)
together (langchain-together)
mistralai (langchain-mistralai)
huggingface (langchain-huggingface)
groq (langchain-groq)
ollama (langchain-community)
Will attempt to infer model_provider from model if not specified. The
following providers will be inferred based on these model prefixes:
gpt-3… or gpt-4… -> openai
claude… -> anthropic
amazon…. -> bedrock
gemini… -> google_vertexai
command… -> cohere
accounts/fireworks… -> fireworks
kwargs (Any) – Additional keyword args to pass to
<<selected ChatModel>>.__init__(model=model_name, **kwargs).
Returns
The BaseChatModel corresponding to the model_name and model_provider specified.
Raises
ValueError – If model_provider cannot be inferred or isn’t supported.
Raises
ValueError – If model_provider cannot be inferred or isn’t supported.
ImportError – If the model provider integration package is not installed.
Return type
BaseChatModel
Example
from langchain.chat_models import init_chat_model
gpt_4o = init_chat_model("gpt-4o", model_provider="openai", temperature=0)
claude_opus = init_chat_model("claude-3-opus-20240229", model_provider="anthropic", temperature=0)
gemini_15 = init_chat_model("gemini-1.5-pro", model_provider="google_vertexai", temperature=0)
gpt_4o.invoke("what's your name")
claude_opus.invoke("what's your name")
gemini_15.invoke("what's your name")
Notes
langchain_community.chat_models.baichuan.ChatBaichuan¶
class langchain_community.chat_models.baichuan.ChatBaichuan[source]¶
Bases: BaseChatModel
Baichuan chat models API by Baichuan Intelligent Technology.
For more information, see https://platform.baichuan-ai.com/docs/api
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param baichuan_api_base: str = 'https://api.baichuan-ai.com/v1/chat/completions'¶
Baichuan custom endpoints
param baichuan_api_key: Optional[SecretStr] = None (alias 'api_key')¶
Baichuan API Key
Constraints
type = string
writeOnly = True
format = password
param baichuan_secret_key: Optional[SecretStr] = None¶
[DEPRECATED, keeping it for for backward compatibility] Baichuan Secret Key
Constraints
type = string
writeOnly = True
format = password
param cache: Union[BaseCache, bool, None] = None¶
Whether to cache the response.
If true, will use the global cache.
If false, will not use a cache
If None, will use the global cache if it’s set, otherwise no cache.
If instance of BaseCache, will use the provided cache.
Caching is not currently supported for streaming methods of models.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Callback manager to add to the run trace.
param callbacks: Callbacks = None¶
Callbacks to add to the run trace.
param custom_get_token_ids: Optional[Callable[[str], List[int]]] = None¶
Optional encoder to use for counting tokens.
param metadata: Optional[Dict[str, Any]] = None¶
param metadata: Optional[Dict[str, Any]] = None¶
Metadata to add to the run trace.
param model = 'Baichuan2-Turbo-192K'¶
model name of Baichuan, default is Baichuan2-Turbo-192K,
other options include Baichuan2-Turbo
param model_kwargs: Dict[str, Any] [Optional]¶
Holds any model parameters valid for API call not explicitly specified.
param request_timeout: int = 60 (alias 'timeout')¶
request timeout for chat http requests
param streaming: bool = False¶
Whether to stream the results or not.
param tags: Optional[List[str]] = None¶
Tags to add to the run trace.
param temperature: Optional[float] = 0.3¶
What sampling temperature to use.
param top_k: int = 5¶
What search sampling control to use.
param top_p: float = 0.85¶
What probability mass to use.
param verbose: bool [Optional]¶
Whether to print out response text.
param with_search_enhance: bool = False¶
Whether to use search enhance, default is False.
__call__(messages: List[BaseMessage], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → BaseMessage¶
[Deprecated]
Notes
Deprecated since version langchain-core==0.1.7: Use invoke instead.
Parameters
messages (List[BaseMessage]) – 
stop (Optional[List[str]]) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
kwargs (Any) – 
Return type
BaseMessage
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: TypeAlias¶
Get the input type for this runnable.
property OutputType: Any¶
Get the output type for this runnable.
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_schema: Type[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.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool¶
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using ChatBaichuan¶
Baichuan
Chat with Baichuan-192K
langchain_community.chat_models.openai.acompletion_with_retry¶
async langchain_community.chat_models.openai.acompletion_with_retry(llm: ChatOpenAI, run_manager: Optional[AsyncCallbackManagerForLLMRun] = None, **kwargs: Any) → Any[source]¶
Use tenacity to retry the async completion call.
Parameters
llm (ChatOpenAI) – 
run_manager (Optional[AsyncCallbackManagerForLLMRun]) – 
kwargs (Any) – 
Return type
Any
langchain_community.chat_models.kinetica.ChatKinetica¶
class langchain_community.chat_models.kinetica.ChatKinetica[source]¶
Bases: BaseChatModel
Kinetica LLM Chat Model API.
Prerequisites for using this API:
The gpudb and typeguard packages installed.
A Kinetica DB instance.
Kinetica host specified in KINETICA_URL
Kinetica login specified KINETICA_USER, and KINETICA_PASSWD.
An LLM context that specifies the tables and samples to use for inferencing.
This API is intended to interact with the Kinetica SqlAssist LLM that supports
generation of SQL from natural language.
In the Kinetica LLM workflow you create an LLM context in the database that provides
information needed for infefencing that includes tables, annotations, rules, and
samples. Invoking load_messages_from_context() will retrieve the contxt
information from the database so that it can be used to create a chat prompt.
The chat prompt consists of a SystemMessage and pairs of
HumanMessage/AIMessage that contain the samples which are question/SQL
pairs. You can append pairs samples to this list but it is not intended to
facilitate a typical natural language conversation.
When you create a chain from the chat prompt and execute it, the Kinetica LLM will
generate SQL from the input. Optionally you can use KineticaSqlOutputParser to
execute the SQL and return the result as a dataframe.
The following example creates an LLM using the environment variables for the
Kinetica connection. This will fail if the API is unable to connect to the database.
Example
from langchain_community.chat_models.kinetica import KineticaChatLLM
kinetica_llm = KineticaChatLLM()
kinetica_llm = KineticaChatLLM()
If you prefer to pass connection information directly then you can create a
connection using KineticaUtil.create_kdbc().
Example
from langchain_community.chat_models.kinetica import (
    KineticaChatLLM, KineticaUtil)
kdbc = KineticaUtil._create_kdbc(url=url, user=user, passwd=passwd)
kinetica_llm = KineticaChatLLM(kdbc=kdbc)
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param cache: Union[BaseCache, bool, None] = None¶
Whether to cache the response.
If true, will use the global cache.
If false, will not use a cache
If None, will use the global cache if it’s set, otherwise no cache.
If instance of BaseCache, will use the provided cache.
Caching is not currently supported for streaming methods of models.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Callback manager to add to the run trace.
param callbacks: Callbacks = None¶
Callbacks to add to the run trace.
param custom_get_token_ids: Optional[Callable[[str], List[int]]] = None¶
Optional encoder to use for counting tokens.
param kdbc: Any = None¶
Kinetica DB connection.
param metadata: Optional[Dict[str, Any]] = None¶
Metadata to add to the run trace.
param tags: Optional[List[str]] = None¶
Tags to add to the run trace.
param verbose: bool [Optional]¶
Whether to print out response text.
Return type
BaseMessage
classmethod is_lc_serializable() → bool¶
Is this class serializable?
Return type
bool
json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
by_alias (bool) – 
skip_defaults (Optional[bool]) – 
exclude_unset (bool) – 
exclude_defaults (bool) – 
exclude_none (bool) – 
encoder (Optional[Callable[[Any], Any]]) – 
models_as_dict (bool) – 
dumps_kwargs (Any) – 
Return type
unicode
classmethod lc_id() → List[str]¶
A unique identifier for this class for serialization purposes.
The unique identifier is a list of strings that describes the path
to the object.
Return type
List[str]
load_messages_from_context(context_name: str) → List[source]¶
Load a lanchain prompt from a Kinetica context.
A Kinetica Context is an object created with the Kinetica Workbench UI or with
A Kinetica Context is an object created with the Kinetica Workbench UI or with
SQL syntax. This function will convert the data in the context to a list of
messages that can be used as a prompt. The messages will contain a
SystemMessage followed by pairs of HumanMessage/AIMessage that
contain the samples.
Parameters
context_name (str) – The name of an LLM context in the database.
Returns
A list of messages containing the information from the context.
Return type
List
classmethod load_messages_from_datafile(sa_datafile: Path) → List[BaseMessage][source]¶
Load a lanchain prompt from a Kinetica context datafile.
Parameters
sa_datafile (Path) – 
Return type
List[BaseMessage]
map() → Runnable[List[Input], List[Output]]¶
Return a new Runnable that maps a list of inputs to a list of outputs,
by calling invoke() with each input.
Example
from langchain_core.runnables import RunnableLambda
def _lambda(x: int) -> int:
    return x + 1
runnable = RunnableLambda(_lambda)
print(runnable.map().invoke([1, 2, 3])) # [2, 3, 4]
Return type
Runnable[List[Input], List[Output]]
classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
path (Union[str, Path]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
classmethod parse_obj(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using ChatKinetica¶
Kinetica
Kinetica SqlAssist LLM Demo
langchain_community.chat_models.gpt_router.completion_with_retry¶
langchain_community.chat_models.gpt_router.completion_with_retry(llm: GPTRouter, models_priority_list: List[GPTRouterModel], run_manager: Optional[CallbackManagerForLLMRun] = None, **kwargs: Any) → Union[GenerationResponse, Generator[ChunkedGenerationResponse, None, None]][source]¶
Use tenacity to retry the completion call.
Parameters
llm (GPTRouter) – 
models_priority_list (List[GPTRouterModel]) – 
run_manager (Optional[CallbackManagerForLLMRun]) – 
kwargs (Any) – 
Return type
Union[GenerationResponse, Generator[ChunkedGenerationResponse, None, None]]
langchain_community.chat_models.mlflow_ai_gateway.ChatParams¶
class langchain_community.chat_models.mlflow_ai_gateway.ChatParams[source]¶
Bases: BaseModel
Parameters for the MLflow AI Gateway LLM.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param candidate_count: int = 1¶
The number of candidates to return.
param max_tokens: Optional[int] = None¶
param stop: Optional[List[str]] = None¶
param temperature: float = 0.0¶
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
Parameters
_fields_set (Optional[SetStr]) – 
values (Any) – 
Return type
Model
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 (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
langchain_huggingface.chat_models.huggingface.ChatHuggingFace¶
class langchain_huggingface.chat_models.huggingface.ChatHuggingFace[source]¶
Bases: BaseChatModel
Wrapper for using Hugging Face LLM’s as ChatModels.
Works with HuggingFaceTextGenInference, HuggingFaceEndpoint,
and HuggingFaceHub LLMs.
Upon instantiating this class, the model_id is resolved from the url
provided to the LLM, and the appropriate tokenizer is loaded from
the HuggingFace Hub.
Adapted from: https://python.langchain.com/docs/integrations/chat/llama2_chat
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param cache: Union[BaseCache, bool, None] = None¶
Whether to cache the response.
If true, will use the global cache.
If false, will not use a cache
If None, will use the global cache if it’s set, otherwise no cache.
If instance of BaseCache, will use the provided cache.
Caching is not currently supported for streaming methods of models.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Callback manager to add to the run trace.
param callbacks: Callbacks = None¶
Callbacks to add to the run trace.
param custom_get_token_ids: Optional[Callable[[str], List[int]]] = None¶
Optional encoder to use for counting tokens.
param llm: Any = None¶
LLM, must be of type HuggingFaceTextGenInference, HuggingFaceEndpoint,
HuggingFaceHub, or HuggingFacePipeline.
param metadata: Optional[Dict[str, Any]] = None¶
Metadata to add to the run trace.