openvino_genai.ChatHistory#
- class openvino_genai.ChatHistory#
Bases:
pybind11_objectChatHistory stores conversation messages and optional metadata for chat templates.
Manages: - Message history (array of message objects) - Optional tools definitions array (for function calling) - Optional extra context object (for custom template variables)
Messages are stored as JSON-like structures but accessed as Python dicts. Use get_messages() to retrieve the list of all messages, modify them, and set_messages() to update the history.
- Example:
```python history = ChatHistory() history.append({“role”: “user”, “content”: “Hello”})
# Modify messages messages = history.get_messages() messages[0][“content”] = “Updated” history.set_messages(messages) ```
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: openvino_genai.py_openvino_genai.ChatHistory) -> None
Create an empty chat history.
__init__(self: openvino_genai.py_openvino_genai.ChatHistory, messages: list) -> None
Create chat history from a list of message dicts.
Methods
__bool__(self)__delattr__(name, /)Implement delattr(self, name).
__dir__()Default dir() implementation.
__eq__(value, /)Return self==value.
__format__(format_spec, /)Default object formatter.
__ge__(value, /)Return self>=value.
__getattribute__(name, /)Return getattr(self, name).
Helper for pickle.
__gt__(value, /)Return self>value.
__hash__()Return hash(self).
__init__(*args, **kwargs)Overloaded function.
This method is called when a class is subclassed.
__le__(value, /)Return self<=value.
__len__(self)__lt__(value, /)Return self<value.
__ne__(value, /)Return self!=value.
__new__(**kwargs)Helper for pickle.
__reduce_ex__(protocol, /)Helper for pickle.
__repr__()Return repr(self).
__setattr__(name, value, /)Implement setattr(self, name, value).
Size of object in memory, in bytes.
__str__()Return str(self).
Abstract classes can override this to customize issubclass().
append(self, message)Add a message to the end of chat history.
clear(self)get_extra_context(self)Get the extra context object.
get_messages(self)Get all messages as a list of dicts (deep copy).
get_tools(self)Get the tools definitions array.
pop(self)Remove and return the last message.
set_extra_context(self, extra_context)Set the extra context object.
set_messages(self, messages)Replace all messages with a new list.
set_tools(self, tools)Set the tools definitions array.
Attributes
- __annotations__ = {}#
- __bool__(self: openvino_genai.py_openvino_genai.ChatHistory) bool#
- __class__#
alias of
pybind11_type
- __delattr__(name, /)#
Implement delattr(self, name).
- __dir__()#
Default dir() implementation.
- __eq__(value, /)#
Return self==value.
- __format__(format_spec, /)#
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
- __ge__(value, /)#
Return self>=value.
- __getattribute__(name, /)#
Return getattr(self, name).
- __getstate__()#
Helper for pickle.
- __gt__(value, /)#
Return self>value.
- __hash__()#
Return hash(self).
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: openvino_genai.py_openvino_genai.ChatHistory) -> None
Create an empty chat history.
__init__(self: openvino_genai.py_openvino_genai.ChatHistory, messages: list) -> None
Create chat history from a list of message dicts.
- __init_subclass__()#
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __le__(value, /)#
Return self<=value.
- __len__(self: openvino_genai.py_openvino_genai.ChatHistory) int#
- __lt__(value, /)#
Return self<value.
- __ne__(value, /)#
Return self!=value.
- __new__(**kwargs)#
- __reduce__()#
Helper for pickle.
- __reduce_ex__(protocol, /)#
Helper for pickle.
- __repr__()#
Return repr(self).
- __setattr__(name, value, /)#
Implement setattr(self, name, value).
- __sizeof__()#
Size of object in memory, in bytes.
- __str__()#
Return str(self).
- __subclasshook__()#
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- _pybind11_conduit_v1_()#
- append(self: openvino_genai.py_openvino_genai.ChatHistory, message: dict) None#
Add a message to the end of chat history.
- clear(self: openvino_genai.py_openvino_genai.ChatHistory) None#
- get_extra_context(self: openvino_genai.py_openvino_genai.ChatHistory) dict#
Get the extra context object.
- get_messages(self: openvino_genai.py_openvino_genai.ChatHistory) list#
Get all messages as a list of dicts (deep copy).
- get_tools(self: openvino_genai.py_openvino_genai.ChatHistory) list#
Get the tools definitions array.
- pop(self: openvino_genai.py_openvino_genai.ChatHistory) dict#
Remove and return the last message.
- set_extra_context(self: openvino_genai.py_openvino_genai.ChatHistory, extra_context: dict) None#
Set the extra context object.
- set_messages(self: openvino_genai.py_openvino_genai.ChatHistory, messages: list) None#
Replace all messages with a new list.
- set_tools(self: openvino_genai.py_openvino_genai.ChatHistory, tools: list) None#
Set the tools definitions array.