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

# Use AI Prompts in Jupyter

## Intro

Jupyter Workspaces allows you to write AI prompts within Notebooks. Jupyter uses the same prompts as in the Domo. AI Playground without navigating away from Jupyter.

Learn more about [Jupyter AI](https://domo-support.domo.com/s/article/000005291?language=en_US) and the [AI Playground](https://domo-support.domo.com/s/article/000005236?language=en_US).

***

## Required Grants

To access Jupyter, at least one of the following grants must be enabled for your role:

* **Create Jupyter Workspace —** Allows a user to create, edit, and delete Jupyter Workspaces to which they have access.
* **Manage Jupyter Workspace** (Jupyter Admin) **—** Allows a user to view, edit, and delete any Jupyter Workspaces in the instance. This grant is needed to enable workspace sharing for other users.

## Access Jupyter Workspaces

In the navigation header, select **Data** to open the Data Center.

In the left navigation, select <img src="https://mintcdn.com/domoinc/vdPgcKjrK8pRGiuw/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EM5w000005vXkP.png?fit=max&auto=format&n=vdPgcKjrK8pRGiuw&q=85&s=ce92ad9901610b503da876dfe9110813" style={{width: 20, height: 20, display: 'inline', verticalAlign: 'start', margin: '0'}} width="172" height="168" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EM5w000005vXkP.png" /> **More** (three horizontal dots icon) > **Jupyter Workspaces**.

<Frame>
  <img alt="jupyter workspaces.jpg" src="https://mintcdn.com/domoinc/kd5xNGWzPpi6KG1Z/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq0000040sfd.jpg?fit=max&auto=format&n=kd5xNGWzPpi6KG1Z&q=85&s=a6c18b4514fc3b36dcc287931a7162de" width="330" height="604" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq0000040sfd.jpg" />
</Frame>

Learn more about [creating a Workspace](/docs/s/article/36004740075#create-a-workspace).

## Use the Generate Text Prompt

The generate\_text prompt provides answers to questions. In the example, the prompt provided to the AI service is in the prompt\_template. It is given a limitation of \${words}, which is provided in the prompt\_parameters.

The output prompt is provided at the bottom.

<Frame>
  <img alt="Screenshot 2024-09-18 at 2.04.56 PM.png" src="https://mintcdn.com/domoinc/kd5xNGWzPpi6KG1Z/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002moSn.jpg?fit=max&auto=format&n=kd5xNGWzPpi6KG1Z&q=85&s=9bec3a10ef93acd095180ee22fa7aa2c" width="2726" height="332" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002moSn.jpg" />
</Frame>

When a prompt\_template is included, it will ignore the input\_str unless you include the placeholder `${input}` within your prompt template text. If you include the `${input}` placeholder, then the input\_str will automatically be inserted for that placeholder.

The following parameters are available in the generate\_text function. All of the parameters are optional except `input_str`.

```
def generate_text(input_str:str,  
          prompt_template: Optional[PromptTemplate] = None,  
          parameters: Optional[dict[str, str]] = None,  
          model: Optional[str] = None,  
          model_configuration: Optional[dict[str, object]] = None,  
          system: Optional[str] = None):  
  """      
  Generate text from String input  
    
  Parameters:          
    input_str (str): input string          
    prompt_template (PromptTemplate): prompt template          
    parameters (dict[str, str]): parameters          
    model (str): model name          
    model_configuration (dict[str, object]): model configuration          
    system (str): Optional override for the default system instructions included with the prompt to the model.  
      
  Returns:          
    response: generated text      
  """  
  text_generation_request = TextGenerationRequest(input_str, prompt_template, parameters, model,  
model_configuration, system)  
 text_response = _jupyterhub.generate_text(text_generation_request.to_json())  
text_ai_response = TextAIResponse(text_response['prompt'], text_response['choices'])  
return text_ai_response
```

## Use the Text-to-SQL Prompt

The text\_to\_sql prompt provides a SQL query based on the question asked. In the example, the prompt provided to the AI service is in the prompt\_template, and the specified column is in the prompt\_parameters.

The functional SQL query is provided in the output at the bottom.

<Frame>
  <img alt="text to sql.png" src="https://mintcdn.com/domoinc/vdPgcKjrK8pRGiuw/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002lNpd.jpg?fit=max&auto=format&n=vdPgcKjrK8pRGiuw&q=85&s=6fc0e29f5b1f1f8b371d364c5da8b193" width="936" height="372" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002lNpd.jpg" />
</Frame>

You can modify the standard text\_to\_sql template by providing a new DataSourceSchema and an input\_str that specifies what the AI prompt should write.

You can also provide the workspace\_data\_source\_alias for an existing DataSet attached to the workspace. Providing the workspace\_data\_source\_alias allows the workspace to use the schema when generating the column names for the SQL query.

The following parameters are available in the text\_to\_sql function. All of the parameters are optional except `input_str`.

```
def text_to_sql(input_str: str,                  
         prompt_template: Optional[PromptTemplate] = None,                  
         data_source_schemas: Optional[list[DataSourceSchema]] = None,                 
         parameters: Optional[dict[str, str]] = None,                  
         model: Optional[str] = None,                  
         model_configuration: Optional[dict[str, object]] = None,                  
         workspace_data_source_alias: Optional[str] = None,                  
         dataframe: Optional[pd.DataFrame] = None,                  
         system: Optional[str] = None                  
         ):     
   """      
   Convert text to SQL  
     
   Parameters:         
     input_str (str): input string          
     data_source_schemas (list[DataSourceSchema]): list of data source schemas          
     prompt_template (PromptTemplate): prompt template          
     parameters (dict[str, str]): parameters          
     model (str): model name          
     model_configuration (dict[str, object]): model configuration          
     workspace_data_source_alias (str): data source schema alias associated to workspace          
     dataframe (pd.DataFrame): Pandas dataframe          
     system (str): Optional override for the default system instructions included with the prompt to the model.  
     
   Returns:          
     text_ai_response: TextAiResponse      
   """   if workspace_data_source_alias is not None:         
      data_source_schemas = [              
        DataSourceSchema.from_optional_list(domojupyter.io.get_schema_from_datasource(workspace_data_source_alias).get('schema'),                  
          workspace_data_source_alias)]      
   elif dataframe is not None:          
      schema = domojupyter.io.get_schema_from_dataframe(dataframe)          
      data_source_schemas = [              
        DataSourceSchema.from_optional_list(schema,                  
          dataframe.name)]      
   text_to_sql_request = TextToSQLRequest(input_str, data_source_schemas, prompt_template, parameters, model,                                             
                         model_configuration, system)      
   sql_response = _jupyterhub.text_to_sql(text_to_sql_request.to_json())      
   text_ai_response = TextAIResponse(sql_response['prompt'], sql_response['choices'])      
   return text_ai_response
```

## Use the Text-to-Beast-Mode Prompt

The Text-to-Beast-Mode service provides a Beast Mode function based on the question asked. In the example, the prompt provided to the AI asks to add all of the value columns (data\_source\_schemas) together.

The Beast Mode function is provided in the output at the bottom.

<Frame>
  <img alt="text to beast mode.png" src="https://mintcdn.com/domoinc/vdPgcKjrK8pRGiuw/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002lQab.jpg?fit=max&auto=format&n=vdPgcKjrK8pRGiuw&q=85&s=45748a1d64b67065e4f8d16d44940f67" width="936" height="336" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002lQab.jpg" />
</Frame>

The following parameters are available in the text\_to\_beast\_mode function. All of the parameters are optional except `input_str`.

```
def text_to_beast_mode(input_str: str,  
         prompt_template: Optional[PromptTemplate] = None,                         
         data_source_schema: Optional[DataSourceSchema] = None,                         
         parameters: Optional[dict[str, str]] = None,                         
         model: Optional[str] = None,                         
         model_configuration: Optional[dict[str, object]] = None,                         
         system: Optional[str] = None):      
  """      
  Convert text to Beastmode  
      
  Parameters:         
      input_str (str): input string          
      data_source_schema (DataSourceSchema): data source schema          
      prompt_template (PromptTemplate): prompt          
      parameters (dict[str, str]): parameters          
      model (str): model name          
      model_configuration (dict[str, object]): model configuration          
      system (str): Optional override for the default system instructions included with the prompt to the model.  
      
  Returns:          
    sql: SQL string      
  """
```

## Use the Summarize Text Prompt

The summarize\_text prompt provides a text summary based on the question asked. In the example, the prompt provided to the AI service is in text\_summarization.

The output prompt is provided at the bottom.

<Frame>
  <img alt="Screenshot 2024-09-18 at 11.30.03 AM.png" src="https://mintcdn.com/domoinc/vdPgcKjrK8pRGiuw/images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002mmsQ.jpg?fit=max&auto=format&n=vdPgcKjrK8pRGiuw&q=85&s=45350dd05a815e7c4b3396f1cf6b00a5" width="972" height="486" data-path="images/kb/ka0Vq00000051WX-00N5w00000Ri7BU-0EMVq000002mmsQ.jpg" />
</Frame>

The following parameters are available in the summarize\_text function. All of the parameters are optional except `input_str`.

```
def summarize(input_str: str,                
       prompt_template: Optional[PromptTemplate] = None,                
       parameters: Optional[dict[str, str]] = None,                
       model: Optional[str] = None,                
       model_configuration: Optional[dict[str, object]] = None,                
       system: Optional[str] = None,                
       chunking_configuration: Optional[ChunkingConfiguration] = None,                
       output_style: Optional[SummarizationOutputStyle] = None,                
       output_word_length: Optional[SizeBoundary] = None):      
  """      
  Summarize text  
    
  Parameters:          
      input_str (str): Text information to be summarized. This attribute is mandatory.          
      prompt_template (PromptTemplate): prompt template          
      parameters (dict): A dictionary containing parameter-name and its corresponding value.              
        It's used for replacing the placeholders in the PromptTemplate.          
      model (str): Name/id of the language model to be used for summarization          
      model_configuration (dict): A dictionary with custom configuration parameters for a selected language model.          
      system (str): Optional override for the default system instructions included with the prompt to the model.          
      chunking_configuration (ChunkingConfiguration): Configuration for dividing the given text into smaller parts or chunks.          
      output_style (SummarizationOutputStyle): Determines the design, structuring and organization of the summarization's output.          
      output_word_length (SizeBoundary): Defines a size boundary to limit the length of the output summary, based on number of words.  
      
  Returns:          
    response: summarized text      
  """
```

<Note>**Note:** The parameter behavior described below should be confirmed against the current product. This content was submitted for PM review.</Note>

The `summarize()` function generates a summary from a long block of text using an AI model. It supports optional configurations that control the style, structure, and length of the summary. The only required parameter is `input_str`.

```python theme={"dark"}
summarize(input_str="Paste your text here...")
```

### Optional Parameters

#### prompt\_template

**`prompt_template` (Optional) —** The `PromptTemplate` class helps structure reusable prompt strings for AI tasks. In this implementation, it is lightweight, requiring only a single input: the full prompt text.

```python theme={"dark"}
from domojupyter.ai.models.PromptTemplate import PromptTemplate

template_text = "Summarize the following text:\n{text}"
prompt = PromptTemplate(template=template_text)
```

#### parameters

**`parameters` (Optional) —** A dictionary used to replace placeholders in the `prompt_template`.

```python theme={"dark"}
parameters = {
    "topic": "monthly sales report",
    "audience": "executive leadership"
}
```

#### model and model\_configuration

* **`model` (Optional) —** Name or ID of the language model to be used for summarization.
* **`model_configuration` (Optional) —** A dictionary with custom configuration parameters for a selected language model.

#### chunking\_configuration

**`chunking_configuration` (Optional) —** Use this when summarizing large blocks of text. It splits the text into smaller, manageable chunks before summarization.

```python theme={"dark"}
from domojupyter.ai.models.ChunkingConfiguration import ChunkingConfiguration
from domojupyter.ai.models.SeparatorType import SeparatorType

chunking_configuration = ChunkingConfiguration(
    max_chunk_size=1000,
    chunk_overlap=100,
    separators=["\n\n", "\n", " "],
    separator_type=SeparatorType.TEXT,
    disallow_intermediate_chunks=False
)
```

Available `SeparatorType` options: `CPP`, `GO`, `HTML`, `JAVA`, `JAVASCRIPT`, `LATEX`, `MARKDOWN`, `PROTO`, `PYTHON`, `RST`, `RUBY`, `SCALA`, `SOL`, `SWIFT`, `TEXT`.

#### output\_style

**`output_style` (Optional) —** Determines the design, structuring, and organization of the summarization's output.

```python theme={"dark"}
from domojupyter.ai.models.SummarizationOutputStyle import SummarizationOutputStyle

output_style = SummarizationOutputStyle.BULLETED  # Options: BULLETED, NUMBERED, PARAGRAPH
```

#### output\_word\_length

**`output_word_length` (Optional) —** Defines a size boundary to limit the length of the output summary, based on number of words.

```python theme={"dark"}
from domojupyter.ai.models.SizeBoundary import SizeBoundary

output_word_length = SizeBoundary(min_bound=75, max_bound=150)
```

### Example

The following example combines several optional parameters.

```python theme={"dark"}
from domojupyter.ai.models.ChunkingConfiguration import ChunkingConfiguration
from domojupyter.ai.models.SeparatorType import SeparatorType
from domojupyter.ai.models.SummarizationOutputStyle import SummarizationOutputStyle
from domojupyter.ai.models.SizeBoundary import SizeBoundary

summary = summarize(
    input_str=long_text,
    output_style=SummarizationOutputStyle.BULLETED,
    output_word_length=SizeBoundary(min_bound=75, max_bound=150),
    chunking_configuration=ChunkingConfiguration(
        max_chunk_size=1200,
        chunk_overlap=100,
        separators=["\n", ".", " "],
        separator_type=SeparatorType.MARKDOWN,
        disallow_intermediate_chunks=False
    )
)
```
