use Proc::ZMQed; use JavaScript::D3; use Image::Markup::Utilities; use Data::Reshapers; use Text::Plot; #% javascript require.config({ paths: { d3: 'https://d3js.org/d3.v7.min' }}); require(['d3'], function(d3) { console.log(d3); }); use Proc::ZMQed::Mathematica; my Proc::ZMQed::Mathematica $wlProc .= new(url => 'tcp://127.0.0.1', port => '5550'); $wlProc.start-proc():!proclaim; my $cmd = 'Needs["Wolfram`Chess`"]'; my $wlRes = $wlProc.evaluate($cmd); sub wl-chess-image(Str $fen, :$proc is copy = Whatever) { if $proc.isa(Whatever) { $proc = $wlProc; } die "The value option 'proc' is expected to be Whatever or an object of type Proc::ZMQed::Mathematica." unless $proc ~~ Proc::ZMQed::Mathematica; my $cmd2 = Q:c:to/END/; b = Chessboard["{$fen}"]; Export["/tmp/wlimg.png",b["Graphics"]] END my $wlRes2 = $wlProc.evaluate($cmd2); return image-import("/tmp/wlimg.png"); } #% markdown my $imgChess = wl-chess-image('rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2'); llm-vision-synthesize('Describe the positions of the white heavy chess figures.', $imgChess) llm-vision-synthesize('Describe the chess position. Only mention the pieces that are not in their starting positions.', $imgChess) #%md my $url3 = 'https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MarkdownDocuments/Diagrams/AI-vision-via-WL/0iyello2xfyfo.png'; my $imgBarChart = image-import($url3) my &fst = llm-vision-function({"For the given image answer the query: $_ . Be as concise as possible in your answers."}, $imgBarChart, e => llm-configuration('ChatGPT', max-tokens => 900)) #% html my @questions = [ 'How many years are present in the image?', 'How many groups are present in the image?', 'Why 2023 is marked with a "*"?' ]; my @answers = @questions.map({ %( question => $_, answer => &fst($_) ) }); @answers ==> data-translation(field-names=>, table-attributes => 'text-align = "left"') &fst('Give the bar sizes for each group Thanksgiving Day, Black Friday, and Cyber Monday. Put your result in JSON format.') llm-prompt('NothingElse')('JSON') my &fjs = llm-vision-function( {"How many $^a per $^b?" ~ llm-prompt('NothingElse')('JSON')}, $imgBarChart, form => sub-parser('JSON'):drop, max-tokens => 900, temperature => 0.3 ) my $res = &fjs("money", "shopping day") my %data = $res.Hash.deepmap({ $_.substr(1,*-1).Numeric }) #% html my @data2 = %data.kv.map(-> $k, %v { %v.map({ %( group => $k, variable => $_.key, value => $_.value) }) }).&flatten(1); my @data3 = @data2.sort({ %('Thanksgiving Day' => 1, 'Black Friday' => 2, 'Cyber Monday' => 3){$_} ~ $_ }); @data3 ==> to-html() #%js js-d3-bar-chart(@data3, background=>'none', :grid-lines, :900width, :450height) #% markdown $imgBarChart my %data4 = %data.map({ $_.key => $_.value.kv.rotor(2).deepmap(*.subst('*').Numeric) }); text-list-plot( %data4.values, title => "\n" ~ (%data4.keys »~» ' : ' Z~ <□ * ▽> ).join("\n"), point-char => <□ * ▽>, y-label => 'billion $', y-limit => (0, 12) )