Generate code programmatically:
In[9]:=
LLMSynthesize[{LLMPrompt["CodeWriterX"],"Simulate a random walk"}]
Out[9]=
```wolframn = 1000;steps = RandomChoice[{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, n];walk = Accumulate[steps];Graphics[Line[Prepend[walk, {0, 0}]]]```
Generate code programmatically with the "target" language being Python:
In[11]:=
LLMSynthesize[{LLMPrompt["CodeWriterX"]["Python"],"Simulate a random walk"}]
Out[11]=
```pythonimport numpy as npimport randomdef simulate_random_walk(num_steps: int) -> np.ndarray: position = np.array([0, 0]) path = np.zeros((num_steps + 1, 2), dtype=int) path[0] = position steps = [ np.array([1, 0]), np.array([-1, 0]), np.array([0, 1]), np.array([0, -1]) ] for i in range(1, num_steps + 1): random_step = random.choice(steps) position += random_step path[i] = position return path```
Neat Examples
Neat Examples
In[26]:=
conf=LLMConfiguration["Model"-><|"Service"->"OpenAI","Name"->"gpt-5.4-mini"|>];
In[28]:=
ResourceFunction["GridTableForm"]@Dataset@Table[<|"Language"->lang,"Code"->LLMSynthesize[{LLMPrompt["CodeWriterX"][lang],"Find all words in a list that adhere to the Raku regex /:i class \d ** 1..3 /"},LLMEvaluator->conf]|>,{lang,{"WL","Python","R","Raku"}}]
Out[28]=
# | Language | Code |
1 | WL | Select[words, StringContainsQ[RegularExpression["(?i)class\\s\\d{1,3}"]]] |
2 | Python | import redef find_words(words): pattern = re.compile(r'class\s+\d{1,3}', re.IGNORECASE) return [word for word in words if pattern.search(word)] |
3 | R | words <- function(x) x[grepl("(?i)class\\s\\d{1,3}", x, perl = TRUE)] |
4 | Raku | my @words = <class class1 Class12 CLASS123 class1234 foo CLASS999 bar>;.say for @words.grep: { /:i class \d ** 1..3 / }; |