TASK_LM

Knowledgebase

TASK_LM

Function Overview

TASK_LM is a powerful custom function in Sheet Workflows that enables you to run language model prompts directly from your Google Sheet. It integrates AI-generated content into your workflows by leveraging data from cells, URLs, Google Docs, and dictionary lookups while supporting multiple output formats.

Uses

  1. Generate content using data from your spreadsheet.
  2. Summarize documents stored in Google Drive.
  3. Analyze web content by referencing URLs.
  4. Create structured data from various inputs.
  5. Generate Google Docs with AI-powered content.
  6. Create dropdown lists of AI-generated options.
  7. Process multiple input sources in a single prompt.

Syntax and Parameters

=TASK_LM(prompt, model, output_mode, max_tokens, temperature, output_doc_name, celladdress, image_url)

Parameter Data Type Required Description
prompt

string

Required The input prompt or template for the language model. Supports cell references, URLs, Google Docs, and dictionary lookups.
model

string

Required The model name in the format

provider/model_name

(e.g.,

"Gemini/gemini-1.5-pro"

).
output_mode

string

Optional The format for returning results. Defaults to text output in a single cell. Options:

"list"

,

"hlist"

,

"dropdown"

.
max_tokens

number

Optional The maximum number of tokens the model can generate. Defaults vary by model (e.g.,

500

).
temperature

number

Optional Controls output randomness (range: 0.0 to 1.0). Lower values yield more deterministic results; the default is usually

0.7

.
output_doc_name

string

Optional Name for the Google Doc created with the result. A hyperlink to the document is placed in the output cell.
celladdress

string

Optional The cell address where the result should be placed (e.g.,

"C1"

).
image_url

string

Optional URL of an image to include with the prompt. Only used with models that support vision capabilities.

Advanced Options

Template References

You can incorporate dynamic content into the prompt using template references:

  • Use cell references (e.g.,

    Write a product description for {A2} with price {B2}

    ) to pull data from specific cells.
  • Use current row references (e.g.,

    Summarize feedback from {Name} who said: {Feedback}

    ) when your sheet contains matching column headers.
  • Include URLs with format specifications (e.g.,

    Analyze this webpage: {https://www.example.com|markdown}

    ).
  • Reference Google Docs directly (e.g.,

    Summarize this report: {1d-oC-6Whej0jjdknMqw6r2WmqfdSLijS}

    ).
  • Create dictionary lookups (e.g.,

    Create a response for customer {A2} based on details: {A1:A5,B1:B5}

    ).

Output Modes

TASK_LM supports multiple output formats:

  • List mode: Returns results as a vertical list.

      =TASK_LM("Generate 5 creative project names for a mobile app about pet care", "Gemini/gemini-1.5-pro", "list")

  • Horizontal list mode: Returns results as a horizontal list.

      =TASK_LM("Generate 5 days of the week in French", "Gemini/gemini-1.5-pro", "hlist")

  • Dropdown mode: Creates a dropdown list with AI-generated options.

      =TASK_LM("Generate 10 possible job titles for a marketing professional", "Gemini/gemini-1.5-pro", "dropdown")

Creating Google Docs

Generate content that is automatically placed in a new Google Doc:

=TASK_LM("Write a 500-word short story about a detective who solves crimes using AI", "Gemini/gemini-1.5-pro", , 1000, 0.8, "Detective Story")

This call generates the story, creates a new Google Doc named "Detective Story", and places a hyperlink to the document in the output cell.

Vision Models

Use image analysis by including an image URL in your prompt:

=TASK_LM("Describe what is in this image in detail", "Gemini/gemini-1.5-pro", , , , , , "https://example.com/image.jpg")

This sends both the text prompt and the image to the model for integrated processing.

Examples

Example 1: Basic Text Generation

Write a professional email announcing a new product called "WorkflowPro".

=TASK_LM("Write a professional email announcing a new product called 'WorkflowPro'", "Gemini/gemini-1.5-pro")

Example 2: Personalized Content Using Cell References

Generate a birthday message using data from specific cells.

=TASK_LM("Write a birthday message for {A2} who is turning {B2} and enjoys {C2}", "OpenAI/gpt-3.5-turbo")

Example 3: Generate a List With Output Formatting

List 5 key strategies for improving customer retention as a vertical list.

=TASK_LM("List 5 key strategies for improving customer retention", "Gemini/gemini-1.5-pro", "list")

Example 4: Create a Document With Lower Temperature for Factual Content

Generate a detailed report on renewable energy sources with a lower temperature to ensure factual accuracy.

=TASK_LM("Write a detailed report on renewable energy sources and their benefits", "Anthropic/claude-3-opus-20240229", , 2000, 0.2, "Renewable Energy Report")

Example 5: Analyze Content From Multiple Sources

Compare and contrast information from a Google Doc with data on a webpage.

=TASK_LM("Compare and contrast the information from this document {A3} with the data in this webpage {https://www.example.com|markdown}", "OpenAI/gpt-4")

Example 6: Image Analysis With Vision Models

Analyze a product image and suggest presentation improvements.

=TASK_LM("What are the key elements visible in this product image and how could the presentation be improved?", "Gemini/gemini-1.5-pro", , , , , , "https://example.com/product.jpg")

Example 7: Create a Dropdown of Options

Generate 10 possible categories for classifying customer feedback and display them as a dropdown list.

=TASK_LM("Generate 10 possible categories for classifying customer feedback", "Gemini/gemini-1.5-pro", "dropdown")

Best Practices

  • Be specific in your prompts by including details about format, length, tone, and purpose.
  • Reference the correct data using accurate cell references.
  • Adjust the temperature parameter to achieve the desired balance between creativity and coherence.
  • Consider token limits and simplify prompts if the results are truncated.
  • Organize related data in adjacent cells or columns.
  • Create reusable templates to maintain consistency.
  • Test prompts progressively before adding complexity.
  • Combine TASK_LM with other Sheet Workflows functions for advanced automations.

Troubleshooting

Error: Invalid Function Type

Ensure that the function name is spelled correctly as

TASK_LM

and that all required parameters are provided.

Error Processing Prompt Template

Verify that cell references, URLs, and Doc IDs are formatted correctly and that the referenced cells contain valid data.

Error: Failed to Get Response From [Provider]

Check that your API key is configured correctly for the chosen provider and that you have sufficient API quota.

Invalid Cell Address

Confirm that the

celladdress

parameter uses proper A1 notation (e.g.,

"C1"

) and refers to a valid cell in your sheet.

Results Are Truncated

Increase the

max_tokens

parameter or simplify your prompt to ensure the full output is generated.

Model Takes Too Long to Respond

Consider using a faster model, simplifying your prompt, or reducing the

max_tokens

parameter for quicker responses.

Field Not Found in Dictionary Lookups

Ensure that the dictionary ranges are valid and that the keys exist within the referenced data.

FAQ

Which Models Are Supported by TASK_LM?

TASK_LM supports a wide range of models from providers such as Gemini, OpenAI, Anthropic, and Groq. Use the

TASK_MODELS

function to view available options.

Is There a Cost to Using TASK_LM?

While the Sheet Workflows add-on may require a subscription, using TASK_LM also depends on API usage from language model providers, some of which may incur charges.

How Do I Set Up API Keys for Language Models?

API keys are configured in the Sheet Workflows sidebar under the Configuration tab. Enter your API keys for the desired providers.

How Much Data Can I Include in a Prompt?

The data limit depends on the model's context window, generally ranging from 4,000 to 32,000 tokens. Ensure your prompt fits within these limits.

Can I Use TASK_LM in a Formula?

TASK_LM returns a JSON string that must be executed using the "Run" button in the sidebar. It is not designed to be nested within other formulas.

Can I Include Multiple Images in a Prompt?

Currently, TASK_LM supports only one image per prompt via the

image_url

parameter.

Do I Need to Include All Parameters?

No, only the

prompt

and

model

parameters are required. The remaining parameters are optional.

What Is the Difference Between TASK_LM and the Regular LM Function?

TASK_LM offers enhanced template capabilities, multiple output options, and the ability to create Google Docs, making it more powerful for complex workflows.

Can I Use TASK_LM in Automated Triggers or Scheduled Executions?

Yes, TASK_LM can be integrated into automated workflows using the automation features of Sheet Workflows.

Can I Nest Template References?

Yes, if a cell reference points to another reference (such as a URL or a Google Doc), TASK_LM will process them recursively.

How Do I Reference a Range of Cells in the Prompt?

Use dictionary syntax (e.g.,

{A1:A5,B1:B5}

) where the first range provides keys and the second provides corresponding values.

What Happens If I Reference Empty Cells?

Empty cells are ignored when processing the template.

Can I Format the Output as a Table?

While there is no direct table format option, you can prompt the model to return data in a table-like format suitable for rendering in a Google Doc.

If I Use output_doc_name, Will the Result Still Appear in the Sheet?

Yes, a hyperlink to the newly created Google Doc is placed in the output cell.

elisha

5 months ago

Activity
Elisha changed status to Knowledgebase

1 month ago

Elisha changed status to New

1 month ago

Categories
Features