# CometCallbackHandler

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler)

Callback Handler that logs to Comet.

## Signature

```python
CometCallbackHandler(
    self,
    task_type: Optional[str] = 'inference',
    workspace: Optional[str] = None,
    project_name: Optional[str] = None,
    tags: Optional[Sequence] = None,
    name: Optional[str] = None,
    visualizations: Optional[List[str]] = None,
    complexity_metrics: bool = False,
    custom_metrics: Optional[Callable] = None,
    stream_logs: bool = True,
)
```

## Description

This handler will utilize the associated callback method and formats
the input of each callback function with metadata regarding the state of LLM run,
and adds the response to the list of records for both the {method}_records and
action. It then logs the response to Comet.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `job_type` | `str` | Yes | The type of comet_ml task such as "inference", "testing" or "qc" |
| `project_name` | `str` | No | The comet_ml project name (default: `None`) |
| `tags` | `list` | No | Tags to add to the task (default: `None`) |
| `task_name` | `str` | Yes | Name of the comet_ml task |
| `visualize` | `bool` | Yes | Whether to visualize the run. |
| `complexity_metrics` | `bool` | No | Whether to log complexity metrics (default: `False`) |
| `stream_logs` | `bool` | No | Whether to stream callback actions to Comet (default: `True`) |

## Extends

- `BaseMetadataCallbackHandler`
- `BaseCallbackHandler`

## Constructors

```python
__init__(
    self,
    task_type: Optional[str] = 'inference',
    workspace: Optional[str] = None,
    project_name: Optional[str] = None,
    tags: Optional[Sequence] = None,
    name: Optional[str] = None,
    visualizations: Optional[List[str]] = None,
    complexity_metrics: bool = False,
    custom_metrics: Optional[Callable] = None,
    stream_logs: bool = True,
) -> None
```

| Name | Type |
|------|------|
| `task_type` | `Optional[str]` |
| `workspace` | `Optional[str]` |
| `project_name` | `Optional[str]` |
| `tags` | `Optional[Sequence]` |
| `name` | `Optional[str]` |
| `visualizations` | `Optional[List[str]]` |
| `complexity_metrics` | `bool` |
| `custom_metrics` | `Optional[Callable]` |
| `stream_logs` | `bool` |


## Properties

- `comet_ml`
- `task_type`
- `workspace`
- `project_name`
- `tags`
- `visualizations`
- `complexity_metrics`
- `custom_metrics`
- `stream_logs`
- `temp_dir`
- `experiment`
- `name`
- `callback_columns`
- `action_records`
- `nlp`

## Methods

- [`on_llm_start()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_llm_start)
- [`on_llm_new_token()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_llm_new_token)
- [`on_llm_end()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_llm_end)
- [`on_llm_error()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_llm_error)
- [`on_chain_start()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_chain_start)
- [`on_chain_end()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_chain_end)
- [`on_chain_error()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_chain_error)
- [`on_tool_start()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_tool_start)
- [`on_tool_end()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_tool_end)
- [`on_tool_error()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_tool_error)
- [`on_text()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_text)
- [`on_agent_finish()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_agent_finish)
- [`on_agent_action()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/on_agent_action)
- [`flush_tracker()`](https://reference.langchain.com/python/langchain-community/callbacks/comet_ml_callback/CometCallbackHandler/flush_tracker)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/d5ea8358933260ad48dd31f7f8076555c7b4885a/libs/community/langchain_community/callbacks/comet_ml_callback.py#L72)