-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (35 loc) · 1.18 KB
/
app.py
File metadata and controls
51 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import chainlit as cl
import ollama
@cl.on_chat_start
async def start_chat():
cl.user_session.set(
"interaction",
[
{
"role": "system",
"content": "You are a helpful assistant.",
}
],
)
msg = cl.Message(content="")
start_message = "Hello, I'm your 100% local alternative to ChatGPT running on DeepSeek-R1. How can I help you today?"
for token in start_message:
await msg.stream_token(token)
await msg.send()
@cl.step(type="tool")
async def tool(input_message):
interaction = cl.user_session.get("interaction")
interaction.append({"role": "user",
"content": input_message})
response = ollama.chat(model="deepseek-r1",
messages=interaction)
interaction.append({"role": "assistant",
"content": response.message.content})
return response
@cl.on_message
async def main(message: cl.Message):
tool_res = await tool(message.content)
msg = cl.Message(content="")
for token in tool_res.message.content:
await msg.stream_token(token)
await msg.send()