Skip to content

Commit 9ff1fdb

Browse files
committed
Merge branch 'dev'
2 parents 021713e + c6ecf70 commit 9ff1fdb

File tree

16 files changed

+411
-105
lines changed

16 files changed

+411
-105
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ MCP is also an important part of LLM, so this project can also be used as an mcp
2323
6. **webSocket combined with asyncio use**
2424
7. **threading/queue use**
2525
8. **py program packaged into exe**
26+
9. **python -m llm_analysis_assistant**
2627

2728
# 2. Project Background
2829
Before the arrival of true AGI, we will have to go through a long journey, during which we will have to face constant challenges. Whether ordinary people or professionals, their lives will be changed.
@@ -90,6 +91,15 @@ python server.py --is_mock=true --mock_string=你好啊 --looptime=1
9091

9192
```
9293

94+
### Using uv (recommended)
95+
96+
When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will use
97+
[`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *llm-analysis-assistant*.
98+
99+
```
100+
uvx llm_analysis_assistant
101+
```
102+
93103
### Using PIP(🌟)
94104

95105
Alternatively you can install `llm-analysis-assistant` via pip:
@@ -130,6 +140,8 @@ Open the following address in the browser, the url is the sse service address
130140

131141
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/sse
132142

143+
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8002/sse?++user=xxx # ++user=xxx in the url means the HTTP request header user value is xxx
144+
133145
Or use Cherry Studio to add the mcp service
134146

135147
![Cherry-Studio-mcp-sse.png](docs/imgs/Cherry-Studio-mcp-sse.png)
@@ -139,6 +151,8 @@ Open the following address in the browser, the url is the streamableHttp service
139151

140152
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/mcp
141153

154+
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/mcp?++user=xxx # ++user=xxx in the url means the HTTP request header user value is xxx
155+
142156
Or use Cherry Studio to add the mcp service
143157

144158
![mcp-streamable-http.png](docs/imgs/mcp-streamable-http.png)

README_zh.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ MCP也是LLM中重要的一环,故此项目也可当用做mcp客户端使用,并
2323
6. **webSocket结合asyncio一起使用**
2424
7. **threading/queue使用**
2525
8. **py程序打包成exe**
26+
9. **支持python -m**
2627

2728
# 2、项目背景
2829
在真正的AGI到来之前,我们必将经历一段漫长的旅程,期间需要不断面对挑战,无论是普通人还是专业人士,生活都将因此而改变。
@@ -92,6 +93,15 @@ python server.py --is_mock=true --mock_string=你好啊 --looptime=1
9293

9394
```
9495

96+
### 使用 uv(推荐)
97+
98+
使用 [`uv`](https://docs.astral.sh/uv/) 时无需特殊安装。我们将使用
99+
[`uvx`](https://docs.astral.sh/uv/guides/tools/) 直接运行 *llm-analysis-assistant*
100+
101+
```
102+
uvx llm_analysis_assistant
103+
```
104+
95105
### 使用 PIP(🌟)
96106

97107
或者,您可以通过 pip 安装 'llm-analysis-assistant':
@@ -132,6 +142,8 @@ http://127.0.0.1:8000/mcp?url=stdio
132142

133143
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/sse
134144

145+
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8002/sse?++user=xxx # url中++user=xxx 表示HTTP请求头user值是xxx
146+
135147
或者使用Cherry Studio添加mcp服务
136148

137149
![Cherry-Studio-mcp-sse.png](docs/imgs/Cherry-Studio-mcp-sse.png)
@@ -141,6 +153,8 @@ http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/sse
141153

142154
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/mcp
143155

156+
http://127.0.0.1:8000/mcp?url=http://127.0.0.1:8001/mcp?++user=xxx # url中++user=xxx 表示HTTP请求头user值是xxx
157+
144158
或者使用Cherry Studio添加mcp服务
145159

146160
![mcp-streamable-http.png](docs/imgs/mcp-streamable-http.png)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "llm_analysis_assistant"
3-
version = "v0.2.3"
3+
version = "v0.2.7"
44
description = "An LLM analysis assistant to help you understand and implement PMF"
55
readme = "README.md"
66
requires-python = ">=3.10"

src/llm_analysis_assistant/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# __init__.py
2+
23
from llm_analysis_assistant.server import main
34

45
if __name__ == '__main__':
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# __main__.py
2-
import importlib.metadata
3-
import os
42

53
from llm_analysis_assistant.server import main
64

75
if __name__ == '__main__':
8-
os.environ["PROJECT_NAME"] = __package__
9-
try:
10-
version = importlib.metadata.version("llm_analysis_assistant")
11-
os.environ["PROJECT_VERSION"] = 'v' + version
12-
except importlib.metadata.PackageNotFoundError:
13-
pass
146
main()

src/llm_analysis_assistant/pages/execGET.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
2+
import os
23

34
from llm_analysis_assistant.pages.mySSE import mySSE_sse
45
from llm_analysis_assistant.utils.environ_utils import get_path, get_favicon, streamHeader, get_apikey, \
56
get_base_url, my_printHeader, \
6-
my_printBody, get_Res_Header, get_query, get_request_server
7+
my_printBody, get_Res_Header, get_query, get_request_server, get_real_url
78
from llm_analysis_assistant.utils.http_clientx import http_clientx
89
from llm_analysis_assistant.utils.js_utils import js_show_page
910
from llm_analysis_assistant.utils.logs_utils import write_httplog, get_num, LOG_END_SYMBOL, LogType
@@ -54,7 +55,10 @@ async def my_GET():
5455
http_url = get_query('url')
5556
server = get_request_server()
5657
await streamHeader()
57-
await mySSE_sse(True, server.send, num, http_url)
58+
http_url = http_url.replace(' ', '++')
59+
os.environ["MCP_SSE_URL"] = http_url
60+
headers, http_url = get_real_url(http_url)
61+
await mySSE_sse(True, server.send, num, http_url, headers)
5862
return
5963
if http_url is not None:
6064
write_httplog(LogType.GET, url_path, num)

src/llm_analysis_assistant/pages/execPost.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ async def my_POST():
2828
await my_printHeader({"Content-Type": "application/json; charset=utf-8"})
2929
http_url = post_json.get('url')
3030
# llm调用mcp时候
31-
if http_url is None and os.environ.get("MCP_HTTP_URL") is not None:
32-
parsed_url = urlparse(os.environ.get("MCP_HTTP_URL"))
31+
if http_url is None and os.environ.get("MCP_SSE_URL") is not None:
32+
parsed_url = urlparse(os.environ.get("MCP_SSE_URL"))
3333
http_url = parsed_url.scheme + "://" + parsed_url.netloc + '' + url_path
34+
mcp_sse_url = os.environ.get("MCP_SSE_URL")
35+
if mcp_sse_url.find('++') != -1:
36+
_envs = mcp_sse_url[mcp_sse_url.index('++'):]
37+
http_url = http_url + "&" + os.environ["PROJECT_NAME"] + "_envs=" + _envs
3438
# llm调用mcp时候
35-
if '/messages/' in url_path or '/message?' in url_path:
36-
md5_str = get_md5(url_path)
37-
elif '/sse_msg' in url_path:
38-
parsed_url = urlparse(post_json.get('url'))
39-
md5_str = get_md5(parsed_url.path + "?" + parsed_url.query)
39+
md5_str = get_md5(http_url)
4040
has_same_log = False
4141
if GlobalVal.logsNumList.get(md5_str) is not None:
4242
same_num = GlobalVal.logsNumList.get(md5_str)
@@ -47,13 +47,23 @@ async def my_POST():
4747
write_httplog(LogType.REQ, req_str, same_num)
4848
await mySSE_msg(post_json, same_num, has_same_log, http_url)
4949
return
50-
num = get_num()
51-
write_httplog(LogType.POST, url_path, num)
52-
write_httplog(LogType.REQ, req_str, num)
5350
# mcp streamable-http的调用
5451
if '/mcp' in url_path:
55-
await myMCP_msg(post_json, num)
52+
has_same_log = False
53+
md5_str = get_md5(url_path)
54+
if GlobalVal.logsNumList.get(md5_str) is not None:
55+
same_num = GlobalVal.logsNumList.get(md5_str)
56+
has_same_log = True
57+
else:
58+
same_num = get_num()
59+
GlobalVal.logsNumList[md5_str] = same_num
60+
write_httplog(LogType.POST, url_path, same_num)
61+
write_httplog(LogType.REQ, req_str, same_num)
62+
await myMCP_msg(post_json, same_num, has_same_log)
5663
return
64+
num = get_num()
65+
write_httplog(LogType.POST, url_path, num)
66+
write_httplog(LogType.REQ, req_str, num)
5767
is_mock_str = os.environ.get("IS_MOCK")
5868
res_type = None
5969
if '/v1/completions' in url_path:

0 commit comments

Comments
 (0)