fanyi icon indicating copy to clipboard operation
fanyi copied to clipboard

To-do: Return the translated content gracefully.

Open MitsuhaMiyamizu opened this issue 1 year ago • 1 comments

It's frustrated to hardcode the exact position where the translated content located in returned format each time we adapt to the API of specific platform, i.e., lots of platform adopt JSON format the way like OpenAI (see: https://platform.openai.com/docs/api-reference/making-requests).

This is sort of good and it really reduces time developers spent on wrangling with the JSON output and work on other problems using the rest of their time. HOWEVER, some platform just don't, see: https://github.com/YuLab-SMU/fanyi/blob/50213559ae91de8102857cae7a22cee5d225a4dd/R/chatglm.r#L79

This is extremely FRUSTRATING! We shouldn't hardcode this in our code, instead, we should adopt more self-adaptive and graceful method. Think JSON as a tree structure, basically we should iterate this recursively to find all the leaves on the tree, see if it contains contents.

MitsuhaMiyamizu avatar Jun 06 '24 09:06 MitsuhaMiyamizu

Somehow we can unify the get_translate_text() function with this idea. https://github.com/search?q=repo%3AYuLab-SMU%2Ffanyi%20get_translate_text&type=code

GuangchuangYu avatar Aug 12 '24 03:08 GuangchuangYu