> ## 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.

# text_to_plotly

<Warning>
  `morph_lib.ai`パッケージはmorph-dataパッケージの軽量化に伴い、v0.1.5で廃止されました。

  今後、外部アダプターの形式で提供されることを予定しています。
</Warning>

プロンプトを受け取ってPlotlyのグラフを生成します。

<CodeGroup>
  ```python OpenAI theme={"dark"}
  # 📦 Package: morph_lib.ai.openai.code_generation
  # 🛠️ Function: text_to_plotly

  def text_to_plotly(
      prompt: str,
      api_key: str,
      table_names: List[str],
      model: Optional[str] = "gpt-4o",
  ) -> TextConversionResponse:
  ```

  ```python Anthropic theme={"dark"}
  # 📦 Package: morph_lib.ai.anthropic.code_generation
  # 🛠️ Function: text_to_plotly

  def text_to_plotly(
      prompt: str,
      api_key: str,
      table_names: List[str],
      model: Optional[str] = "claude-3-5-haiku-latest",
      max_tokens: Optional[int] = 1024,
  ) -> TextConversionResponse:
  ```

  ```python Azure theme={"dark"}
  # 📦 Package: morph_lib.ai.azure.code_generation
  # 🛠️ Function: text_to_plotly

  def text_to_plotly(
      prompt: str,
      api_key: str,
      table_names: List[str],
      azure_endpoint: str,
      deployment_name: Optional[str] = "gpt4",
      api_version: Optional[str] = "2024-10-01-preview",
  ) -> TextConversionResponse:
  ```

  ```python Groq theme={"dark"}
  # 📦 Package: morph_lib.ai.groq.code_generation
  # 🛠️ Function: text_to_plotly

  def text_to_plotly(
      prompt: str,
      api_key: str,
      table_names: List[str],
      model: Optional[str] = "llama-3.1-70b-versatile",
  ) -> TextConversionResponse:
  ```
</CodeGroup>

### Parameters

OpenAIの場合のパラメータです。上記の関数定義から適宜他のモデルの場合の認証パラメータを設定してください。

<ParamField body="prompt" type="string" required>
  プロンプト
</ParamField>

<ParamField body="api_key" type="string" required>
  LLMのモデルを使用するためのAPIキー
</ParamField>

<ParamField body="table_names" type="list" required>
  生成するために使用するテーブル名のリスト
</ParamField>

<ParamField body="model" type="string" optional>
  使用するLLMのモデル
</ParamField>

### Example

```python theme={"dark"}
from morph_lib.ai.openai.code_generation import text_to_plotly
import os

@morph.func
def func_name(context):
    prompt = context.vars["prompt"]
	fig = text_to_plotly(
		prompt,
		os.environ["OPENAI_API_KEY"],
		["user"],
		"gpt-4o",
	)
	code = fig.code
	print(code)

	return fig.content
```
