Skip to content

Commit

Permalink
Merge pull request #2010 from Agenta-AI/hotfix/-refactor-getStringOrJson
Browse files Browse the repository at this point in the history
fix(frontend): Refactor getStringOrJson function to simplify value handling
  • Loading branch information
jp-agenta authored Aug 21, 2024
2 parents 7f2a0fd + 1e0b1ab commit 736ebb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions agenta-web/src/components/Playground/Views/TestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ const App: React.FC<TestViewProps> = ({
// String, FuncResponse or BaseResponse
if (typeof result === "string") {
res = {version: "2.0", data: result} as BaseResponse
setResultForIndex(getStringOrJson(res), index)
setResultForIndex(getStringOrJson(res.data), index)
} else if (isFuncResponse(result)) {
res = {version: "2.0", data: result.message} as BaseResponse
setResultForIndex(getStringOrJson(res), index)
setResultForIndex(getStringOrJson(res.data), index)

const {message, cost, latency, usage} = result
setAdditionalDataList((prev) => {
Expand All @@ -581,7 +581,7 @@ const App: React.FC<TestViewProps> = ({
})
} else if (isBaseResponse(result)) {
res = result as BaseResponse
setResultForIndex(getStringOrJson(res), index)
setResultForIndex(getStringOrJson(res.data), index)

const {data, trace} = result
setAdditionalDataList((prev) => {
Expand Down
6 changes: 1 addition & 5 deletions agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,7 @@ export const getInitials = (str: string, limit = 2) => {
}

export const getStringOrJson = (value: any) => {
return typeof value === "string"
? value
: typeof value?.data === "string"
? value?.data
: JSON.stringify(value.data, null, 2)
return typeof value === "string" ? value : JSON.stringify(value, null, 2)
}

export const filterVariantParameters = ({
Expand Down

0 comments on commit 736ebb2

Please sign in to comment.