Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
[langserve-invoke] Support non map response in /invoke (LangStream#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli authored Nov 4, 2023
1 parent 0776bfb commit 4d6b821
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ private Object parseResponseBody(String body, boolean streaming) {
Map<String, Object> map =
mapper.readValue(body, new TypeReference<Map<String, Object>>() {});
if (!streaming) {
map = (Map<String, Object>) map.get("output");
Object output = map.get("output");
if (output == null || output instanceof String) {
return output;
} else if (output instanceof Map) {
map = (Map<String, Object>) output;
}
}
if (options.contentField.isEmpty()) {
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ void testInvokeJSONMap(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception
testInvoke(wireMockRuntimeInfo, response);
}

@Test
void testInvokeJSONMapWithoutContent(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
String response =
"""
{"output":"Why don't cats play poker in the wild? Too many cheetahs!"}
""";
testInvoke(wireMockRuntimeInfo, response);
}

@Test
void testInvokeJSONString(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception {
String response =
Expand Down

0 comments on commit 4d6b821

Please sign in to comment.