-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatty.py
36 lines (23 loc) · 790 Bytes
/
chatty.py
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
import chainlit as cl
import guidance
from guidance import models, user, system, assistant, gen
# run this with: chainlit run chatty.py -w
# load a model (could be Transformers, LlamaCpp, VertexAI, OpenAI...)
llama3 = models.LlamaCpp('./llama3.gguf', echo=False)
@cl.on_chat_start
def on_chat_start():
with system():
lm = llama3 + 'You are a helpful and terse assistant.'
cl.user_session.set("lm", lm)
@cl.on_message
async def main(message: cl.Message):
msg = cl.Message(content="")
await msg.send()
lm = cl.user_session.get("lm")
with user():
lm += message.content
with assistant():
lm += gen(name="assistant", stop='.')
msg.content = lm["assistant"]
cl.user_session.set("lm", lm)
await msg.update()