Tony20100/langchain_full huggingface dataset:
langchain_core.messages.ai.UsageMetadata¶
class langchain_core.messages.ai.UsageMetadata[source]¶
Usage metadata for a message, such as token counts.
input_tokens¶
(int) count of input (or prompt) tokens
Type
int
output_tokens¶
(int) count of output (or completion) tokens
Type
int
total_tokens¶
(int) total token count
Type
int
Attributes
input_tokens
output_tokens
total_tokens
Methods
__init__(*args, **kwargs)
clear()
copy()
fromkeys([value])
Create a new dictionary with keys from iterable and values set to value.
get(key[, default])
Return the value for key if key is in the dictionary, else default.
items()
keys()
pop(k[,d])
If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()
Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])
Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)
If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k]
values()
__init__(*args, **kwargs)¶
clear() → None.  Remove all items from D.¶
copy() → a shallow copy of D¶
fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
get(key, default=None, /)¶
langchain_core.messages.function.FunctionMessage¶
class langchain_core.messages.function.FunctionMessage[source]¶
Bases: BaseMessage
Message for passing the result of executing a function back to a model.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: str [Required]¶
The name of the function that was executed.
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: Literal['function'] = 'function'¶
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
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using FunctionMessage¶
How to create a custom chat model class
langchain_core.messages.base.messages_to_dict¶
langchain_core.messages.base.messages_to_dict(messages: Sequence[BaseMessage]) → List[dict][source]¶
Convert a sequence of Messages to a list of dictionaries.
Parameters
messages (Sequence[BaseMessage]) – Sequence of messages (as BaseMessages) to convert.
Returns
List of messages as dicts.
Return type
List[dict]
langchain_core.messages.system.SystemMessage¶
class langchain_core.messages.system.SystemMessage[source]¶
Bases: BaseMessage
Message for priming AI behavior, usually passed in as the first of a sequence
of input messages.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: Literal['system'] = 'system'¶
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
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using SystemMessage¶
Activeloop Deep Memory
Build a Question/Answering system over SQL data
Build a Simple LLM Application
ChatAnyscale
ChatEverlyAI
ChatFireworks
ChatFriendli
ChatKonko
ChatOctoAI
ChatPremAI
ChatTongyi
ChatYandexGPT
Context
Exa Search
GigaChat
Google AI chat models
Google Cloud Vertex AI
How to add examples to the prompt for query analysis
How to compose prompts together
How to create a custom chat model class
How to migrate from legacy LangChain agents to LangGraph
How to use reference examples when doing extraction
Hugging Face
Javelin AI Gateway
Javelin AI Gateway Tutorial
JinaChat
LLMonitor
Label Studio
Llama2Chat
LlamaEdge
MLflow AI Gateway
MLflow Deployments for LLMs
MoonshotChat
PremAI
Robocorp
SQL Database
Trubrics
Yuan2.0
ZHIPU AI
solar.md
vLLM Chat
🦜️🏓 LangServe
langchain_core.messages.function.FunctionMessageChunk¶
class langchain_core.messages.function.FunctionMessageChunk[source]¶
Bases: FunctionMessage, BaseMessageChunk
Function Message chunk.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: str [Required]¶
The name of the function that was executed.
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: Literal['FunctionMessageChunk'] = 'FunctionMessageChunk'¶
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
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using FunctionMessageChunk¶
How to create a custom chat model class
langchain_core.messages.human.HumanMessageChunk¶
class langchain_core.messages.human.HumanMessageChunk[source]¶
Bases: HumanMessage, BaseMessageChunk
Human Message chunk.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param example: bool = False¶
Whether this Message is being passed in to the model as part of an example
conversation.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: Literal['HumanMessageChunk'] = 'HumanMessageChunk'¶
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¶
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using HumanMessageChunk¶
How to create a custom chat model class
langchain_core.messages.utils.convert_to_messages¶
langchain_core.messages.utils.convert_to_messages(messages: Sequence[Union[BaseMessage, List[str], Tuple[str, str], str, Dict[str, Any]]]) → List[BaseMessage][source]¶
Convert a sequence of messages to a list of messages.
Parameters
messages (Sequence[Union[BaseMessage, List[str], Tuple[str, str], str, Dict[str, Any]]]) – Sequence of messages to convert.
Returns
List of messages (BaseMessages).
Return type
List[BaseMessage]
langchain_core.messages.chat.ChatMessageChunk¶
class langchain_core.messages.chat.ChatMessageChunk[source]¶
Bases: ChatMessage, BaseMessageChunk
Chat Message chunk.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param role: str [Required]¶
The speaker / role of the Message.
param type: Literal['ChatMessageChunk'] = 'ChatMessageChunk'¶
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
langchain_core.messages.tool.InvalidToolCall¶
class langchain_core.messages.tool.InvalidToolCall[source]¶
Allowance for errors made by LLM.
Here we add an error key to surface errors made during generation
(e.g., invalid JSON arguments.)
Attributes
name
args
id
error
Methods
__init__(*args, **kwargs)
clear()
copy()
fromkeys([value])
Create a new dictionary with keys from iterable and values set to value.
get(key[, default])
Return the value for key if key is in the dictionary, else default.
items()
keys()
pop(k[,d])
If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()
Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])
Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)
If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k]
values()
__init__(*args, **kwargs)¶
clear() → None.  Remove all items from D.¶
copy() → a shallow copy of D¶
fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
items() → a set-like object providing a view on D's items¶
langchain_core.messages.base.BaseMessage¶
class langchain_core.messages.base.BaseMessage[source]¶
Bases: Serializable
Base abstract Message class.
Messages are the inputs and outputs of ChatModels.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: str [Required]¶
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
Get the namespace of the langchain object.
Return type
List[str]
classmethod is_lc_serializable() → bool[source]¶
Return whether this class is 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]
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
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
pretty_print() → None[source]¶
Return type
None
pretty_repr(html: bool = False) → str[source]¶
Parameters
html (bool) – 
Return type
str
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
dumps_kwargs (Any) – 
Return type
unicode
to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶
Return type
Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() → SerializedNotImplemented¶
Return type
SerializedNotImplemented
classmethod update_forward_refs(**localns: Any) → None¶
SerializedNotImplemented
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using BaseMessage¶
Chat Bot Feedback Template
Discord
How to add examples to the prompt for query analysis
How to attach callbacks to a runnable
How to create a custom chat model class
How to pass callbacks in at runtime
How to propagate callbacks  constructor
How to use reference examples when doing extraction
WeChat
langchain_core.messages.ai.AIMessage¶
class langchain_core.messages.ai.AIMessage[source]¶
Bases: BaseMessage
Message from an AI.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param example: bool = False¶
Whether this Message is being passed in to the model as part of an example
conversation.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param invalid_tool_calls: List[InvalidToolCall] = []¶
If provided, tool calls with parsing errors associated with the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param tool_calls: List[ToolCall] = []¶
If provided, tool calls associated with the message.
param type: Literal['ai'] = 'ai'¶
param usage_metadata: Optional[UsageMetadata] = None¶
If provided, usage metadata for a message, such as token counts.
This is a standard representation of token usage that is consistent across models.
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
by_alias (bool) – 
skip_defaults (Optional[bool]) – 
exclude_unset (bool) – 
exclude_defaults (bool) – 
exclude_none (bool) – 
Return type
DictStrAny
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod get_lc_namespace() → List[str][source]¶
Get the namespace of the langchain object.
Return type
List[str]
classmethod is_lc_serializable() → bool¶
Return whether this class is 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
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]
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
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
pretty_print() → None¶
Return type
None
pretty_repr(html: bool = False) → str[source]¶
Return a pretty representation of the message.
Parameters
html (bool) – 
Return type
str
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶