Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.12.0"
distribution-version = "2201.12.7"

[[package]]
org = "ballerina"
name = "ai"
version = "1.1.0"
version = "1.1.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "data.jsondata"},
Expand Down
118 changes: 118 additions & 0 deletions ballerina/tests/test_utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ isolated function getExpectedParameterSchema(string message) returns map<json> {
};
}

if message.startsWith("Give me a random joke about cricketers") {
return expectedParameterSchemaForRecUnionBasicType;
}

if message.startsWith("Give me a random joke") {
return {"type":"object","properties":{"result":{"anyOf":[{"type":"string"},{"type":"null"}]}}};
}

if message.startsWith("Name a random world class cricketer in India") {
return expectedParameterSchemaForRecUnionNull;
}

if message.startsWith("Name 10 world class cricketers in India") {
return expectedParameterSchemaForArrayOnly;
}

if message.startsWith("Name 10 world class cricketers as string") {
return expectedParameterSchemaForArrayUnionBasicType;
}

if message.startsWith("Name top 10 world class cricketers") {
return expectedParameterSchemaForArrayUnionRec;
}

if message.startsWith("Name a random world class cricketer") {
return expectedParameterSchemaForArrayUnionRec;
}

if message.startsWith("Name 10 world class cricketers") {
return expectedParamSchemaForArrayUnionNull;
}

return {};
}

Expand Down Expand Up @@ -167,6 +199,52 @@ isolated function getTheMockLLMResult(string message) returns map<json> {
}
}

if message.startsWith("Name a random world class cricketer in India") {
return {"result": {"name": "Sanga"}};
}

if message.startsWith("Name a random world class cricketer") {
return {"result": {"name": "Sanga"}};
}

if message.startsWith("Name 10 world class cricketers") {
return {
"result": [
{"name": "Virat Kohli"},
{"name": "Joe Root"},
{"name": "Steve Smith"},
{"name": "Kane Williamson"},
{"name": "Babar Azam"},
{"name": "Ben Stokes"},
{"name": "Jasprit Bumrah"},
{"name": "Pat Cummins"},
{"name": "Shaheen Afridi"},
{"name": "Rashid Khan"}
]
};
}

if message.startsWith("Name top 10 world class cricketers") {
return {
"result": [
{"name": "Virat Kohli"},
{"name": "Joe Root"},
{"name": "Steve Smith"},
{"name": "Kane Williamson"},
{"name": "Babar Azam"},
{"name": "Ben Stokes"},
{"name": "Jasprit Bumrah"},
{"name": "Pat Cummins"},
{"name": "Shaheen Afridi"},
{"name": "Rashid Khan"}
]
};
}

if message.startsWith("Give me a random joke") {
return {"result": "This is a random joke"};
}

return {};
}

Expand Down Expand Up @@ -246,5 +324,45 @@ isolated function getExpectedPrompt(string message) returns string {
their name?`;
}

if message.startsWith("Name 10 world class cricketers in India") {
return "Name 10 world class cricketers in India\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Name 10 world class cricketers as string") {
return "Name 10 world class cricketers as string\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Name 10 world class cricketers") {
return "Name 10 world class cricketers\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Name top 10 world class cricketers") {
return "Name top 10 world class cricketers\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Name a random world class cricketer in India") {
return "Name a random world class cricketer in India\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Name a random world class cricketer") {
return "Name a random world class cricketer\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Give me a random joke about cricketers") {
return "Give me a random joke about cricketers\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

if message.startsWith("Give me a random joke") {
return "Give me a random joke\nYou must call the `getResults`" +
" tool to obtain the correct answer.";
}

return "INVALID";
}
165 changes: 165 additions & 0 deletions ballerina/tests/test_values.bal
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,168 @@ const expectedParamterSchemaStringForBalProgram =

const expectedParamterSchemaStringForCountry =
{"type": "object", "properties": {"result": {"type": "string"}}};



const expectedParamSchemaForArrayUnionNull =
{
"type": "object",
"properties": {
"result": {
"anyOf": [
{
"type": "array",
"items": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
{
"type": "null"
}
]
}
}
};

const expectedParameterSchemaForArrayUnionRec =
{
"type": "object",
"properties": {
"result": {
"anyOf": [
{
"type": "array",
"items": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
{
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
]
}
}
};

const expectedParameterSchemaForArrayUnionBasicType =
{
"type": "object",
"properties": {
"result": {
"anyOf": [
{
"type": "array",
"items": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
{
"type": "string"
}
]
}
}
};

const expectedParameterSchemaForArrayOnly =
{
"type": "object",
"properties": {
"result": {
"type": "array",
"items": {
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
};

const expectedParameterSchemaForRecUnionBasicType =
{
"type": "object",
"properties": {
"result": {
"anyOf": [
{
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
{
"type": "string"
}
]
}
}
};

const expectedParameterSchemaForRecUnionNull =
{
"type": "object",
"properties": {
"result": {
"anyOf": [
{
"required": [
"name"
],
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
{
"type": "null"
}
]
}
}
};
Loading
Loading