Skip to content

Commit eec8b77

Browse files
committed
docs: update usage for chatglm sse
1 parent 8030e14 commit eec8b77

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

docs/custom-llm-server.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
# Custom Server API example (ChatGLM2)
22

3+
See in: [ChatGLM2 SSE Server](../example/custom_llm_server/chatglm_sse.py)
4+
35
Your LLM API example:
46

57
```http request
68
POST http://127.0.0.1:8000/chat
79
Content-Type: application/json
810
911
{
10-
"instruction": "code complete given code:\n```java public class Main {\n public static void main(String[] args) {",
11-
"input":""
12+
"messages": [
13+
{ "role": "user", "message": "I'm Nihillum." },
14+
{ "role": "assistant", "message": "OK" },
15+
{ "role": "user", "message": "What did I just say?" }
16+
]
1217
}
13-
14-
### Response:
15-
### "Here's an explanation of the given code:\n\n```\npublic class Main {\n```\nThis line defines the name of the main class as `Main`.\n```\npublic static void main(String[] args) {\n```\nThis line defines the `main` method as the entry point of the program. The `public`, `static`, and `void` access modifiers indicate that this method can be accessed directly from outside the class, it is static in nature and it does not take arguments.\n```\n String[] args = new String[1];\n args[0] = \"Hello\";\n args[1] = \"World\";\n \n // Do something with the arguments\n}\n```\nThis line declares a variable `args` of type `String` and initializes it with an array of one element `String` object. The elements of the array are assigned the values \"Hello\" and \"World\" respectively.\n```\n String[] args = new String[1];\n args[0] = \"Hello\";\n args[1] = \"World\";\n \n // Do something with the arguments\n}\n```\nThis line declares a variable `args` of type `String` and initializes it with an array of one element `String` object. The elements of the array are assigned the values \"Hello\" and \"World\" respectively.\n```\n public static void main(String[] args) {\n```\nThis line refers to the `main` method defined in the previous class and passes it the argument array `args`.\n```\n String[] args = new String[1];\n args[0] = \"Hello\";\n args[1] = \"World\";\n \n // Do something with the arguments\n}\n```\nThis line refers to the `main` method defined in the previous class and passes it the argument array `args`.\n```\n}\n```\nThis curly brace closes the `main` method.\n```\n}\n```\nThis curly brace closes the `main` method.\n```\n```\n\nOverall, this code creates a variable `args` of type `String` and assigns it an array of one element with the values \"Hello\" and \"World\". The `main` method is called and passes the argument array `args` to it."
1618
```
1719

18-
python code example: [main.py](example/custom_llm_server/main.py)
20+
Format Example
1921

2022
```python
21-
class MessageInput(BaseModel):
22-
instruction: str
23-
input: str
23+
class Message(BaseModel):
24+
role: str
25+
message: str
26+
2427

25-
@app.post("/chat")
26-
async def chat(data: MessageInput):
27-
input = {} # your backend data
28+
class ChatInput(BaseModel):
29+
messages: List[Message]
2830

29-
response = requests.post("your_llm_server", json={
30-
# your backend data
31-
}).json()
3231

33-
return response["data"][0]
32+
@app.post("/api/chat", response_class=Response)
33+
async def chat(msg: ChatInput):
34+
return StreamingResponse(fetch_chat_completion(msg.messages), media_type="text/event-stream")
3435
```

0 commit comments

Comments
 (0)