(raw string)
| 1026 | } |
| 1027 | |
| 1028 | func parseResponsesRequest(raw string) { |
| 1029 | input := gjson.Get(raw,"input") |
| 1030 | if !input.Exists() || !input.IsArray() { |
| 1031 | printTruncated(raw, 500) |
| 1032 | return |
| 1033 | } |
| 1034 | arr := input.Array() |
| 1035 | start := len(arr) - 3 |
| 1036 | if start < 0 { |
| 1037 | start = 0 |
| 1038 | } |
| 1039 | for _, item := range arr[start:] { |
| 1040 | itemType := item.Get("type").String() |
| 1041 | role := item.Get("role").String() |
| 1042 | if role == "" { |
| 1043 | role = itemType |
| 1044 | } |
| 1045 | content := item.Get("content").String() |
| 1046 | if content == "" { |
| 1047 | // content may be an array |
| 1048 | contentArr := item.Get("content") |
| 1049 | if contentArr.IsArray() { |
| 1050 | for _, c := range contentArr.Array() { |
| 1051 | cType := c.Get("type").String() |
| 1052 | text := c.Get("text").String() |
| 1053 | if text != "" { |
| 1054 | fmt.Printf(" \033[36m%s:\033[0m %s\n", role, truncate(text, 200)) |
| 1055 | } else { |
| 1056 | fmt.Printf(" \033[36m%s [%s]\033[0m %s\n", role, cType, truncate(c.Raw, 100)) |
| 1057 | } |
| 1058 | } |
| 1059 | continue |
| 1060 | } |
| 1061 | } |
| 1062 | fmt.Printf(" \033[36m%s:\033[0m %s\n", role, truncate(content, 200)) |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | func parseResponsesResponse(raw string) { |
| 1067 | output := gjson.Get(raw,"output") |
no test coverage detected