microsoft / Excel-Labs

MIT License
79 stars 20 forks source link

Just a Link to ChatGPT? #7

Closed PHWiest closed 1 year ago

PHWiest commented 1 year ago

Hi,

I am looking for any documentation or impressive demonstrations or techniques using LABS.GENERATIVEAI( ) .

Is this function just a "link" from within a sheet to OpenAI? Is there more to it than this? Thanks for your help!

jack-williams commented 1 year ago

LABS.GENERATIVEAI is just a function that calls the OpenAI text completion API (https://platform.openai.com/docs/api-reference/completions).

The function is low-level, but can be used for some interesting things when combined with prompts and wrapper functions. For example:

=LET(
    result, LABS.GENERATIVEAI(
        "Extract all the animals from the text (between <text> tags) and return as a JSON list. The text is <text>" &
            I11 & "</text>"
    ),
    elements, TEXTSPLIT(TEXTBEFORE(TEXTAFTER(result, "["), "]", -1), ","),
    cleaned, MAP(
        elements,
        LAMBDA(element, TEXTBEFORE(TEXTAFTER(TRIM(element), """"), """", -1))
    ),
    cleaned
)

image

You can also use it for translation, parsing text, sentiment analysis, and so on.

PHWiest commented 1 year ago

Thank YOU!

Phil

From: Jack Williams @.> Sent: Wednesday, June 14, 2023 10:47 AM To: microsoft/Excel-Labs @.> Cc: Philip Wiest @.>; Author @.> Subject: Re: [microsoft/Excel-Labs] Just a Link to ChatGPT? (Issue #7)

LABS.GENERATIVEAI is just a function that calls the OpenAI text completion API (https://platform.openai.com/docs/api-reference/completions).

The function is low-level, but can be used for some interesting things when combined with prompts and wrapper functions. For example:

=LET( result, LABS.GENERATIVEAI( "Extract all the animals from the text (between tags) and return as a JSON list. The text is " & I11 & "" ), elements, TEXTSPLIT(TEXTBEFORE(TEXTAFTER(result, "["), "]", -1), ","), cleaned, MAP( elements, LAMBDA(element, TEXTBEFORE(TEXTAFTER(TRIM(element), """"), """", -1)) ), cleaned )

https://user-images.githubusercontent.com/4489219/245888634-0cda12d8-c1a8-4678-b3c2-2c311e431c07.png

You can also use it for translation, parsing text, sentiment analysis, and so on.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/Excel-Labs/issues/7#issuecomment-1591730783 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJC4WZLCK3FYZPSQTTEOP3XLH2KNANCNFSM6AAAAAAZC3LURA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEJC4W5G4AZM4CRLBNRCDXTXLH2KNA5CNFSM6AAAAAAZC3LURCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS637RF6.gif Message ID: @. @.> >