> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morph-data.io/llms.txt
> Use this file to discover all available pages before exploring further.

# <LLM />

<Frame caption="layout='chat'">
  <img src="https://mintcdn.com/queue-4c50ebb3/_HQi-05AKdEsS8di/assets/images/pages/llm-component.jpg?fit=max&auto=format&n=_HQi-05AKdEsS8di&q=85&s=7d8824a0724d7b24e0dfb5f29dffdd61" width="1280" height="720" data-path="assets/images/pages/llm-component.jpg" />
</Frame>

The `<LLM />` component is a component for streaming processes using Open AI and Anthropic APIs.

```tsx theme={"dark"}
<LLM
  postData="ai-chat"
  layout="chat"
  height={300}
/>
```

`<LLM />` components can be used for the following functions.

* AI chat ... Chat between user and AI can be realised. It can start and end threads, display AI replies, etc.

* Content generation ... AI generates content in response to text entered by the user. For example, this can be used when the AI generates a document in response to text entered by the user.

* Side-by-side ... Displays user and AI chat and content generation side by side.

Translated with DeepL.com (free version)

## Data specification for `<LLM />`.

The `<LLM />` component sends the following data by default to the Python function specified in `postData`.

* `prompt`: text entered by the user.

* `thread_id`: thread ID of the conversation with the AI, updated to a new value, e.g. when the user presses the ‘Start new thread’ button.

* `is_new_conversation`: whether a new conversation has started. Updated to `true`, e.g. when the user presses the ‘Start new thread’ button.

Use the `vars` property if you want to send additional data to these or override the default data.

Translated with DeepL.com (free version)

## Props

<ParamField path="postData" type="string" required>
  Python function or SQL file name
</ParamField>

<ParamField path="varialbes" type="{ [key: string]: any }">
  Variables to pass to the Python function or SQL file. Declare using the `defineState()` function.
</ParamField>

<ParamField path="height" type="number">
  Height of the component. Unit is px.
</ParamField>

<ParamField path="layout" type="'chat' | 'single' | 'side-by-side'">
  UI layout. ‘chat’ for the chat UI, ‘single’ for the content generation UI and ‘side-by-side’ for the side-by-side UI.
</ParamField>

<ParamField path="inputType" type="'default' | 'button'">
  Input form type. 'default' for the default input form, 'button' for only the button.
</ParamField>

## Example

### Side-by-side layout

By using a side-by-side layout, the user and AI chat and the artifact can be displayed at the same time.

Use the `create_chunk` function. The first argument is the content of the chat and the second argument is the content of the artifact. The artifact can be HTML or markdown.

<CodeGroup>
  ```python src/python/ai-chat-with-html.py theme={"dark"}
  # src/python/ai-chat-with-html.py
  from langchain_core.messages import HumanMessage
  from langchain_openai import ChatOpenAI
  from morph_lib.stream import create_chunk

  import morph
  from morph import MorphGlobalContext

  @morph.func
  def langchain_chat(context: MorphGlobalContext):
      llm = ChatOpenAI(model="gpt-4o")
      messages = [HumanMessage(context.vars["prompt"])]
      for token in llm.stream(messages):
          yield create_chunk(f"{token.content}")
      yield create_chunk(f"", f"<html><body><h1>Hey! It's Canvas</h1></body></html>")
  ```

  ```tsx src/pages/index.mdx theme={"dark"}
  # AI App 🦜

  <LLM postData="langchain_chat" height={400} layout="side-by-side" />
  ```
</CodeGroup>
