Skip to content

Commit

Permalink
test:Added Gemini tests for llm-function, llm-example-function, and l…
Browse files Browse the repository at this point in the history
…lm-chat.
  • Loading branch information
antononcube committed Mar 17, 2024
1 parent 2f2af4d commit c82c2c2
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
50 changes: 50 additions & 0 deletions xt/10-Gemini-basic-usage.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use v6.d;

use lib '.';
use lib './lib';

use LLM::Functions;
use Text::SubParsers;

use Test;

my $echo = False;

plan *;

## 1
ok llm-configuration('gemini');

## 2
my $prompt2 = "Make a recipe for the given phrase.";
#note llm-function($prompt2, llm-evaluator => llm-configuration('gemini'))("greek salad". :$echo);
ok llm-function($prompt2, llm-evaluator => llm-configuration('gemini'))("greek salad", :$echo);

## 3
isa-ok llm-function($prompt2, e => 'gemini')("greek salad", :$echo),
Str,
'greek salad';

## 4
my &prompt3 = { "How many $^a can fit inside one $^b?" };
#note llm-function(&prompt3, llm-evaluator => 'gemini')('basket balls', 'toyota corolla 2010');
is llm-function(&prompt3, llm-evaluator => 'gemini')('basket balls', 'toyota corolla 2010', :$echo).all ~~ Str,
True,
'basket balls in toyota corolla 2010';

## 5
my &prompt4 = -> :$dish, :$cuisine { "Give a recipe for $dish in the $cuisine cuisine." }
is llm-function(&prompt4, llm-evaluator => 'gemini')(dish => 'salad', cuisine => 'Russian', max-tokens => 300, :$echo).all ~~ Str,
True,
'recipe';

## 6
my &f6 = llm-function(
{ "What is the average speed of $_ ?" },
form => sub-parser(Numeric),
llm-evaluator => 'PaLM');

#note &f6('a car on a USA highway', :$echo);
isa-ok &f6('a car on a USA highway', :$echo), Positional;

done-testing;
38 changes: 38 additions & 0 deletions xt/11-llm-example-function-Gemini.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use v6.d;

use lib '.';
use lib './lib';

use LLM::Functions;

use Test;

plan *;

## 1
ok llm-example-function(<finger hand> => <hand arm>, llm-evaluator => 'Gemini')('foot');

## 2
isa-ok llm-example-function('<| A->3, 4->K1 |>' => '{ A:3, 4:K1 }')('<| 23->3, G->33, T -> R5|>', e => 'Gemini'), Str;

## 3
is-deeply
llm-example-function('<| A->3, 4->K1 |>' => '{ "A":3, "4":"K1" }', e => 'Gemini', form => 'JSON')('<| 23->3, G->33, T -> R5|>'),
${"23" => 3, :G(33), :T("R5")};

## 4
isa-ok llm-example-function({ "crocodile" => "grasshopper", "fox" => "cardinal" }, hint => 'animal colors', e => 'Gemini')('raccoon'),
Str;

## 5
# Relaxed test.
# PaLM produces more two 8s, e.g. 888 or 8888.
like llm-example-function(((1 .. 4) Z=> 11 «*« (1 .. 4)), e => 'Gemini')(8).trim, / 8 8+ /;

# This test gives: safetyFeedback rating category HARM_CATEGORY_TOXICITY
# is llm-example-function(((1 .. 4) Z=> 11 «*« (1 .. 4)), e => llm-configuration('Gemini', temperature => 0.01))(8).trim, '88';

## 6
is llm-example-function(((1 .. 4) Z=> 11 «*« (1 .. 4)), e => 'Gemini', form => { $_.trim.Int })(8), 88;

done-testing;
48 changes: 48 additions & 0 deletions xt/12-Gemini-chat.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use v6.d;

use lib '.';
use lib './lib';

use LLM::Functions;

use Test;

plan *;

## 1
my $prompt = 'You are a gem expert and you give concise answers.';
my $chat1 = llm-chat(chat-id => 'gem-expert-talk', conf => 'Gemini', :$prompt);

isa-ok $chat1.llm-evaluator, LLM::Functions::EvaluatorChat;

## 2
note $chat1.eval('What is the most transparent gem?', :echo);
ok $chat1.eval('What is the most transparent gem?');

## 3
my $msg3 = 'Ok. What are the second and third most transparent gems?';
ok $chat1.eval($msg3);

## 4
my $msg4 = 'Which country buys gems the most?';
ok $chat1.eval($msg4);

## 5
my $msg5 = 'Which country exports gems the most?';
ok $chat1.eval($msg5);

## 6
# For Gemini in order to specify context we use the pattern:
# [ user => <context-prompt>, model => 'Ok.', ...]
# Hence, we have two more messages.
is $chat1.messages.elems, 8 + 2;

## 7
is $chat1.messages.all ~~ Hash, True;

## 8
is-deeply
$chat1.messages[4, 6, 8].map({ $_<content> }).Array,
[$msg3, $msg4, $msg5];

done-testing;

0 comments on commit c82c2c2

Please sign in to comment.