Skip to content

Commit

Permalink
fix(frontend): Refactor getStringOrJson function to simplify value ha…
Browse files Browse the repository at this point in the history
…ndling
  • Loading branch information
bekossy committed Aug 21, 2024
1 parent 6ebd073 commit 1e0b1ab
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 1e0b1ab

Please sign in to comment.