shell_gpt
shell_gpt copied to clipboard
Fix unicode exception
When I use Chinese, sometimes the following happens
# sgpt "Mac Python脚本配置PATH"
"\u5c24\u5176\u662f\u5728Mac\u4e0a\u5b89\u88c5Python\u540e\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u8bbe\u7f6ePython\u811a\u672c\u7684PATH\u3002\u4f8b\u5982\uff0c\u914d\u7f6ePATH\u6307\u5b9a\u201c/usr/local/bin\u201d\uff0c\u5219Python\u811a\u672c\u53ef\u4ee5\u901a\u8fc7\u201c/usr/local/bin/python\u201d\u5411Mac\u6307\u793a \u8981\u4f7f\u7528Python\u3002
It works in my terminal without any changes:
🦄 sgpt "Mac Python脚本配置PATH"
使用Mac上的Python脚本配置PATH的方法如下:
1.在终端中键入以下命令以创建或修改.bash_profile:
$ vim ~/.bash_profile
2.添加下面一行,其中'/path/to/bin/'是您要添加到搜索路径中的文件夹路径:
export PATH="/path/to/bin/:$PATH"
3.保存文件并关闭编辑器。
4.运行以下命令使更改立即生效:
source ~/.bash_profile
I think it's pretty random to happen.
def openai_request():
...
open('/root/a', 'w').write(json.dumps(response.json(), indent=2, ensure_ascii=False))
...
A
# sgpt "Linux 脚本配置PATH"
Linux \u811a\u672c\u914d\u7f6e PATH \u7684\u65b9\u6cd5\u662f\uff1a
1. \u6253\u5f00 \u300c\u7cfb\u7edf\u914d\u7f6e\u300d\u3002
2. \u9009\u62e9 \u300c\u7528\u6237\u300d \u81f3 \u300c\u7cfb\u7edf\u50a8\u5b58\u300d \u3001\u300c\u7528\u6237\u50a8\u5b58\u300d \u6216 \u300c\u7cfb\u7edf\u6c60\u300d \u4e2d\u7684\u4e00\u4e2a\u9009\u9879\u3002
3. \u627e\u5230 \u201c\u77e5\u8bc6\u5e93\u201d \u9996\u9009\u9879\u3002
4. \u9009\u62e9 \u201c\u7cfb\u7edf\u53d8\u91cf\u201d \u5206\u7c7b\uff0c\u5207\u6362\u5230\u201c\u53ef\u7528\u53d8\u91cf\u201d\u9009\u9879\u4e2d\u3002
5. \u9009\u62e9 \u300c \u811a\u672c \u8d44\u6e90 \u76ee\u5f55 \u300d \u4e2d\u7684\u884c\uff0c\u5728\u6b64\u884c\u4e2d\u7f16\u8f91\u811a\u672c\u8d44\u6e90\u76ee\u5f55\u3002
6. \u767b\u51fa \u7cfb\u7edf\uff0c\u91cd\u65b0\u542f\u52a8\u7cfb\u7edf\uff0c\u914d\u7f6e\u5c06\u751f\u6548\u3002
Response:
{
"id": "cmpl-6k0P2Zkx8au3Y08LTc96jttYfBvl6",
"object": "text_completion",
"created": 1676422656,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nLinux \\u811a\\u672c\\u914d\\u7f6e PATH \\u7684\\u65b9\\u6cd5\\u662f\\uff1a\n\n1. \\u6253\\u5f00 \\u300c\\u7cfb\\u7edf\\u914d\\u7f6e\\u300d\\u3002\n\n2. \\u9009\\u62e9 \\u300c\\u7528\\u6237\\u300d \\u81f3 \\u300c\\u7cfb\\u7edf\\u50a8\\u5b58\\u300d \\u3001\\u300c\\u7528\\u6237\\u50a8\\u5b58\\u300d \\u6216 \\u300c\\u7cfb\\u7edf\\u6c60\\u300d \\u4e2d\\u7684\\u4e00\\u4e2a\\u9009\\u9879\\u3002\n\n3. \\u627e\\u5230 \\u201c\\u77e5\\u8bc6\\u5e93\\u201d \\u9996\\u9009\\u9879\\u3002\n\n4. \\u9009\\u62e9 \\u201c\\u7cfb\\u7edf\\u53d8\\u91cf\\u201d \\u5206\\u7c7b\\uff0c\\u5207\\u6362\\u5230\\u201c\\u53ef\\u7528\\u53d8\\u91cf\\u201d\\u9009\\u9879\\u4e2d\\u3002\n\n5. \\u9009\\u62e9 \\u300c \\u811a\\u672c \\u8d44\\u6e90 \\u76ee\\u5f55 \\u300d \\u4e2d\\u7684\\u884c\\uff0c\\u5728\\u6b64\\u884c\\u4e2d\\u7f16\\u8f91\\u811a\\u672c\\u8d44\\u6e90\\u76ee\\u5f55\\u3002\n\n6. \\u767b\\u51fa \\u7cfb\\u7edf\\uff0c\\u91cd\\u65b0\\u542f\\u52a8\\u7cfb\\u7edf\\uff0c\\u914d\\u7f6e\\u5c06\\u751f\\u6548\\u3002",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 619,
"total_tokens": 643
}
}
B
# sgpt "Linux 脚本配置PATH"
Linux 中设置 PATH 的常用方法有两种:一种是临时设置,只在当前shell有效;另一种是永久设置,全局有效。
1. 临时设置PATH:
在当前shell中使用export命令临时增加PATH,例如:
export PATH="$PATH:/usr/local/bin:/opt/myapp/bin"
2. 永久设置PATH:
(1) 在bash shell中,修改~/.bash_profile文件,文件末尾添加PATH,示例如下:
PATH="$PATH:/usr/local/bin:/opt/myapp/bin"
(2) 在zsh shell中,修改~/.zshrc文件,文件末尾添加PATH,示例如下:
PATH="$PATH:/usr/local/bin:/opt/myapp/bin"
修改完成之后,需要重新读取配置文件生效,在bash中使用source命令,在zsh中使用. 命令,例如:
source ~/.bash_profile
. ~/.zshrc
Response:
{
"id": "cmpl-6k0ReipGxHArzOk2tbfTAvu84bA73",
"object": "text_completion",
"created": 1676422818,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nLinux 中设置 PATH 的常用方法有两种:一种是临时设置,只在当前shell有效;另一种是永久设置,全局有效。\n\n1. 临时设置PATH:\n\n在当前shell中使用export命令临时增加PATH,例如:\n\nexport PATH=\"$PATH:/usr/local/bin:/opt/myapp/bin\"\n\n2. 永久设置PATH:\n\n(1) 在bash shell中,修改~/.bash_profile文件,文件末尾添加PATH,示例如下:\n\nPATH=\"$PATH:/usr/local/bin:/opt/myapp/bin\"\n\n(2) 在zsh shell中,修改~/.zshrc文件,文件末尾添加PATH,示例如下:\n\nPATH=\"$PATH:/usr/local/bin:/opt/myapp/bin\"\n\n修改完成之后,需要重新读取配置文件生效,在bash中使用source命令,在zsh中使用. 命令,例如:\n\nsource ~/.bash_profile\n. ~/.zshrc",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 456,
"total_tokens": 480
}
}
I'm working on updates comming by the end of the week, where I will tweak temperature
and top_p
parameters for OpenAI requests, and it should provide us more accurate outputs for shell prompts, which potentially could fix this issue.
OK
@twfb I just released a new patch, could you please try it with new updates? pip install shell-gpt --upgrade
I tested it fine