On this page:
define-by-prompt!
8.15.0.2

2 LLM Compile-time Metaprogramming🔗ℹ

 (require llm/define) package: llm-lib

syntax

(define-by-prompt! id strs ...)

(define-by-prompt! id #:output-file file-str strs ...)
#:contracts
([id identifier?] [str string?])
Defines the id by requesting the Racket definition of this value using the prompt strs. The prompt is sent during phase 1, and the response is converted to syntax is using datum->syntax and the lexical context information of the input to this form, and used to generate a definition of the identifier id. The prompt must be string literal.

Optionally specifies an output file file-str, as a string-path literal, to write the definition to. This is useful if you may need to modify the result. This file provides a second level of caching, if the backend is already caching responses.

Requires a backend imported for-syntax

NOTE: This will compile unknown code, from the internet, directly into program, leaving no trace of an LLM invokation at run time. This is not advisable. You should probably sandbox the result or something.

Examples:
> (require llm llm/define (for-syntax llm/ollama/phi3))
> (define-by-prompt! my-identity "Define the Racket function `my-identity`, which simply returns its input")
> (my-identity 5)

5