Add client-mode FastGPT routing
This commit is contained in:
85
test/api/fastapi-browser-addon.http
Normal file
85
test/api/fastapi-browser-addon.http
Normal file
@@ -0,0 +1,85 @@
|
||||
@baseUrl = http://127.0.0.1:8000
|
||||
###
|
||||
@sessionId = a1123
|
||||
@timeStamp = 202603310303
|
||||
@clientMode = browser_addon
|
||||
###
|
||||
GET {{baseUrl}}
|
||||
|
||||
HTTP/1.1 200 - OK
|
||||
date: Tue, 28 Jul 2026 00:36:56 GMT
|
||||
server: uvicorn
|
||||
content-length: 32
|
||||
content-type: application/json
|
||||
connection: close
|
||||
###
|
||||
DELETE {{baseUrl}}/delete_session
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"sessionId": "{{sessionId}}",
|
||||
"timeStamp": "{{$timestamp}}",
|
||||
"clientMode": "{{clientMode}}"
|
||||
}
|
||||
|
||||
HTTP/1.1 200 - OK
|
||||
date: Tue, 28 Jul 2026 00:36:57 GMT
|
||||
server: uvicorn
|
||||
content-length: 71
|
||||
content-type: application/json
|
||||
connection: close
|
||||
###
|
||||
POST {{baseUrl}}/chat?stream=true
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"sessionId": "{{sessionId}}",
|
||||
"timeStamp": "{{timeStamp}}",
|
||||
"text": "hi",
|
||||
"clientMode": "{{clientMode}}",
|
||||
"needFormUpdate": true,
|
||||
"useTextChunk": true
|
||||
}
|
||||
|
||||
HTTP/1.1 200 - OK
|
||||
date: Tue, 28 Jul 2026 00:36:58 GMT
|
||||
server: uvicorn
|
||||
content-type: text/event-stream; charset=utf-8
|
||||
connection: close
|
||||
transfer-encoding: chunked
|
||||
###
|
||||
POST {{baseUrl}}/get_info
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"sessionId": "{{sessionId}}",
|
||||
"timeStamp": "{{timeStamp}}",
|
||||
"key": "hphm1",
|
||||
"clientMode": "{{clientMode}}"
|
||||
}
|
||||
|
||||
HTTP/1.1 200 - OK
|
||||
date: Tue, 28 Jul 2026 00:37:07 GMT
|
||||
server: uvicorn
|
||||
content-length: 97
|
||||
content-type: application/json
|
||||
connection: close
|
||||
###
|
||||
POST {{baseUrl}}/set_info
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"sessionId": "{{sessionId}}",
|
||||
"timeStamp": "{{timeStamp}}",
|
||||
"key": "hphm1",
|
||||
"value": "沪A8939",
|
||||
"clientMode": "{{clientMode}}"
|
||||
}
|
||||
|
||||
HTTP/1.1 200 - OK
|
||||
date: Tue, 28 Jul 2026 00:37:00 GMT
|
||||
server: uvicorn
|
||||
content-length: 70
|
||||
content-type: application/json
|
||||
connection: close
|
||||
###
|
||||
76
test/test_client_mode.py
Normal file
76
test/test_client_mode.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from src.api.endpoints import external_stage_code
|
||||
from src.schemas.models import (
|
||||
ProcessRequest_chat,
|
||||
ProcessRequest_delete_session,
|
||||
ProcessRequest_get,
|
||||
ProcessRequest_set,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("request_model", "payload"),
|
||||
[
|
||||
(
|
||||
ProcessRequest_chat,
|
||||
{"sessionId": "session-1", "timeStamp": "1", "text": "你好"},
|
||||
),
|
||||
(
|
||||
ProcessRequest_set,
|
||||
{
|
||||
"sessionId": "session-1",
|
||||
"timeStamp": "1",
|
||||
"key": "name",
|
||||
"value": "张三",
|
||||
},
|
||||
),
|
||||
(
|
||||
ProcessRequest_get,
|
||||
{"sessionId": "session-1", "timeStamp": "1", "key": "name"},
|
||||
),
|
||||
(
|
||||
ProcessRequest_delete_session,
|
||||
{"sessionId": "session-1", "timeStamp": "1"},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_client_mode_defaults_to_direct(request_model, payload):
|
||||
request = request_model(**payload)
|
||||
|
||||
assert request.clientMode == "direct"
|
||||
|
||||
|
||||
def test_browser_addon_client_mode_is_accepted():
|
||||
request = ProcessRequest_chat(
|
||||
sessionId="session-1",
|
||||
timeStamp="1",
|
||||
text="你好",
|
||||
clientMode="browser_addon",
|
||||
)
|
||||
|
||||
assert request.clientMode == "browser_addon"
|
||||
|
||||
|
||||
def test_unknown_client_mode_is_rejected():
|
||||
with pytest.raises(ValidationError):
|
||||
ProcessRequest_chat(
|
||||
sessionId="session-1",
|
||||
timeStamp="1",
|
||||
text="你好",
|
||||
clientMode="unknown",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("client_mode", "raw_code", "expected"),
|
||||
[
|
||||
("direct", "0001", "0001"),
|
||||
("direct", "1002", "1002"),
|
||||
("browser_addon", "0001", "browser_addon.0001"),
|
||||
("browser_addon", "1002", "browser_addon.1002"),
|
||||
],
|
||||
)
|
||||
def test_external_stage_code(client_mode, raw_code, expected):
|
||||
assert external_stage_code(client_mode, raw_code) == expected
|
||||
Reference in New Issue
Block a user