Expose LINQPad AI to scripts

LINQPad AI is great, please expose it to scripts via a supported API so scripts can use the configured provider/model/credentials without prompting/hardcoding or reflection.
Proposed minimal surface:
• Util.AI.ChatAsync(string user, string? system = null, CancellationToken ct = default)
• Uses LINQPad’s configured endpoint/model/key (secure storage)
• Optional overrides: model/temperature/maxTokens
• Optionally: structured result (content + usage + raw JSON), plus streaming later
Primary benefit: secure, repeatable automation inside scripts (summarize query results, classify rows, generate SQL/docs) with a stable API.

Comments

  • JoeAlbahari
    edited January 7

    This is a good idea.

    Are you looking to keep the AI loop self-contained within the results window or do you want to feed data back to LINQPad's coding agent? If you want the latter, there's already some basic support for this:

    var query =
        from word in "The quick brown fox jumps over the lazy dog".Split()
        orderby word.Length
        select word;
    
    query.Dump();
    
    Util.AI.NewInlineAgentLink ("Feed results to AI", Util.ToCsvString (query)).Dump();
    

    When you click "Feed results to AI", it will activate LINQPad's coding agent, pasting in the results. You can then add any instruction you want before submitting.

    Right now this requires that you call Util.AI.NewInlineAgentLink. There should probably be an option to do this directly from the tables in the Dump output.