Skip to content

Commit 6e29a81

Browse files
Merge pull request #31 from SasinduDilshara/fix-copilot-connection
Update the default client backend call
2 parents 2ad2b15 + aea2bc0 commit 6e29a81

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ballerina/llm_client_default.bal

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public type DefaultBallerinaModelConfig record {|
2626
string accessToken;
2727
|};
2828

29+
type ChatCompletionResponse record {
30+
string[] content?;
31+
};
32+
2933
# Default Ballerina model chat completion client.
3034
public isolated distinct client class DefaultBallerinaModel {
3135
*Model;
@@ -55,10 +59,11 @@ public isolated distinct client class DefaultBallerinaModel {
5559
return error(string `LLM call failed: ${check chatResponse.getTextPayload()}`);
5660
}
5761

58-
string|error resp = check chatResponse.getTextPayload();
59-
if resp is error {
60-
return error("Failed to retrieve completion message", resp);
62+
ChatCompletionResponse chatCompleteResponse = check (check chatResponse.getJsonPayload()).cloneWithType();
63+
string[]? content = chatCompleteResponse?.content;
64+
if content is () {
65+
return error("No completion message");
6166
}
62-
return parseResponseAsJson(resp);
67+
return parseResponseAsJson(content[0]);
6368
}
6469
}

0 commit comments

Comments
 (0)