Skip to content
Merged
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
13 changes: 9 additions & 4 deletions ballerina/llm_client_default.bal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
string accessToken;
|};

type ChatCompletionResponse record {
string[] content?;
};

# Default Ballerina model chat completion client.
public isolated distinct client class DefaultBallerinaModel {
*Model;
Expand Down Expand Up @@ -55,10 +59,11 @@
return error(string `LLM call failed: ${check chatResponse.getTextPayload()}`);
}

string|error resp = check chatResponse.getTextPayload();
if resp is error {
return error("Failed to retrieve completion message", resp);
ChatCompletionResponse chatCompleteResponse = check (check chatResponse.getJsonPayload()).cloneWithType();
string[]? content = chatCompleteResponse?.content;

Check warning on line 63 in ballerina/llm_client_default.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/llm_client_default.bal#L63

Added line #L63 was not covered by tests
if content is () {
return error("No completion message");

Check warning on line 65 in ballerina/llm_client_default.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/llm_client_default.bal#L65

Added line #L65 was not covered by tests
}
return parseResponseAsJson(resp);
return parseResponseAsJson(content[0]);

Check warning on line 67 in ballerina/llm_client_default.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/llm_client_default.bal#L67

Added line #L67 was not covered by tests
}
}
Loading