Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit c8533c1

Browse files
committed
fix&update: web search fatal & updated README file
1 parent 572c805 commit c8533c1

File tree

7 files changed

+57
-25
lines changed

7 files changed

+57
-25
lines changed

Doc.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
<details>
2+
3+
<summary>
4+
15
# 消息格式
6+
7+
</summary>
8+
9+
210
为了可能被需要的流式传播,我是用的和之前 [Claude-in-slack-api]() 用的是相同的方法:
311
通过 `WebSocket` 传输内容,可以说,所有消息 (包括网络搜索的,每个步骤) 每一个字符都会经过Websocket传输,就如 `EventStream` 一样
412

@@ -78,8 +86,17 @@ openassistant.init()
7886
startWSApp(openassistant.wsurl)
7987
```
8088

89+
</details>
90+
91+
92+
<details>
93+
94+
<summary>
95+
8196
# API
8297

98+
</summary>
99+
83100
## 登录
84101
```python
85102
import requests.sessions
@@ -161,3 +178,4 @@ cookies: requests.sessions.RequestsCookieJar = sign.loadCookies()
161178
#### removeConversation(index: int)
162179
删除对话
163180

181+
</details>

Doc_en.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
<details>
2+
3+
<summary>
4+
15
# Message format
6+
7+
</summary>
8+
29
For stream messages that may be needed, I am using the same method as before [Claude-in-slack-api]() :
310
Content is transmitted through the `WebSocket`, every messages(on or two characters), including every step of web search will be transmitted through the Websocket
411
## Connect to Websocket
@@ -75,9 +82,16 @@ openassistant = OpenAssistant(u, cookies=cookies, tranlater=Translater(), mysql=
7582
openassistant.init()
7683
startWSApp(openassistant.wsurl)
7784
```
85+
</details>
86+
87+
<details>
88+
89+
<summary>
7890

7991
# API
8092

93+
</summary>
94+
8195
## Login
8296
```python
8397
import requests.sessions
@@ -160,3 +174,5 @@ save `conversation_id` and `title` in to `self.conversations` and returns the ti
160174

161175
#### removeConversation(index: int)
162176
delete conversation
177+
178+
</details>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
下面的视频介绍了如何使用: https://www.bilibili.com/video/BV12h4y1G7Zc
2626

27+
或者查看 [介绍文档](./Doc.md)
28+
2729
## 有道翻译接口
2830

2931
由于使用的语言模型不会返回中文,即便模型有一定能力可以处理中文输入。所以为其加上了翻译来方便阅读
@@ -95,7 +97,7 @@ python main_cmd.py -u <邮箱> -p
9597

9698
| 命令 | |
9799
|------------|-------------------|
98-
| exit | 退出程序 |
100+
| exit/q | 退出程序 |
99101
| ls | 查看所有对话 |
100102
| cd <index> | 进入某个对话 |
101103
| web | 切换对话状态(普通/接入网络搜索) |

README_en.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
> For now, i can only provide terminal version. fastapi and web's version are not done yet since i'm quite busy these days.
44
> but the interfaces are the same.
55
6-
[//]: # ()
7-
[//]: # (> 2023.6.4-22:46: 今天为之后的大更新铺垫了很多,重新构建了整个框架,但是调整说明明天再说,这会太晚了)
8-
9-
[//]: # ()
10-
[//]: # (> 2023.6.6-00:30: 依旧,加的东西蛮多的,明个有时间再讲,还遇到了棘手的问题,不过暂时找到了缓解的方法)
11-
126
Leave a ⭐ if you like it🥺
137

148
## Instructions
@@ -17,6 +11,8 @@ Hugging-chat's web api. The current model is `OpenAssistant/oasst-sft-6-llama-30
1711

1812
This video shows how to actually use it: https://www.bilibili.com/video/BV12h4y1G7Zc
1913

14+
You can also check the [Documentation](./Doc_en.md) for how to use it
15+
2016
## Translator
2117

2218
since the model only replies in english even if it's able to process chinese, i decided to add a plugin for it, which is a translator provided by Youdao.
@@ -89,7 +85,7 @@ Format: `/`+`command`
8985

9086
| Command | |
9187
|------------|--------------------------------------|
92-
| exit | exit the program |
88+
| exit/q | exit the program |
9389
| ls | list all conversations |
9490
| cd <index> | cd into the chosen conversation |
9591
| web | activate `Search web` or not |

Server/HuggingChat/OpenAssistant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def getReply(self, conversation_id, text, web_search_id: str = ""):
216216

217217
for i in range(3):
218218
data = self.getData(text, web_search_id)
219-
# print(data)
220219
res = self.requestsPost(url, stream=True, data=json.dumps(data))
221220
reply = self.parseData(res, conversation_id=conversation_id)
222221
if reply != None:
@@ -307,6 +306,7 @@ def chat(self, text: str, conversation_id=None, web=False):
307306
).getWebSearch()
308307
web_search_id = js["messages"][-1]["id"] if js else ""
309308
self.WSOut.sendMessage(status=True, msg=text, user="user", conversation_id=conversation_id)
309+
print("web_search_id: ", web_search_id)
310310
self.getReply(conversation_id, text, web_search_id)
311311

312312
# eng = self.getReply(conversation, text)

Server/HuggingChat/WebSearch.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ def parseData(self, data):
2828
js = json.loads(data)
2929
self.data = js
3030
messages = js["messages"]
31+
if messages[-1]["type"] == "result":
32+
self.WSOut.sendWebSearch(messages[-1], conversation_id=self.conversation_id)
33+
return 456
34+
elif len(messages) - 1 > self.index:
35+
if self.index == -1:
36+
self.WSOut.sendWebSearch(messages[0], conversation_id=self.conversation_id)
37+
self.index = 0
38+
for message in messages[self.index + 1:]:
39+
self.WSOut.sendWebSearch(message, conversation_id=self.conversation_id)
40+
self.index += 1
3141
except Exception as e:
32-
logging.error("One error occurred when parsing WebSearch data, it's fine since it sometimes returns responses in a wrong json format")
33-
# logging.error("WebSearch error:" + data)
34-
# traceback.print_exc()
35-
return
36-
if messages[-1]["type"] == "result":
37-
self.WSOut.sendWebSearch(messages[-1], conversation_id=self.conversation_id)
38-
return 456
39-
elif len(messages) - 1 > self.index:
40-
if self.index == -1:
41-
self.WSOut.sendWebSearch(messages[0], conversation_id=self.conversation_id)
42-
self.index = 0
43-
for message in messages[self.index + 1:]:
44-
self.WSOut.sendWebSearch(message, conversation_id=self.conversation_id)
45-
self.index += 1
42+
logging.error(
43+
"One error occurred when parsing WebSearch data, it's fine since it sometimes returns responses in a wrong json format")
44+
# logging.error("WebSearch error:" + data)
45+
# traceback.print_exc()
4646

4747
def getWebSearch(self):
4848

@@ -63,7 +63,7 @@ def getWebSearch(self):
6363
except Exception as e:
6464
if e.args[0] != 23:
6565
traceback.print_exc()
66-
self.c.close()
66+
# self.c.close()
6767
return self.data
6868

6969

Server/main_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def main():
216216
command = text.strip()
217217
if command[0] == "/":
218218
command = command[1:].split(" ")
219-
if command[0] == "exit":
219+
if command[0] == "exit" or "q":
220220
os._exit(0)
221221
elif command[0] == "new":
222222
newConversation(openassistant)

0 commit comments

Comments
 (0)