-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepseek_coder_v2_ollama_chat.py
More file actions
53 lines (42 loc) · 1.42 KB
/
deepseek_coder_v2_ollama_chat.py
File metadata and controls
53 lines (42 loc) · 1.42 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
52
53
from openai import OpenAI, AsyncOpenAI
import chainlit as cl
client = AsyncOpenAI(
base_url='http://localhost:11434/v1/',
# required but ignored
api_key='ollama',
)
settings = {
"model": "deepseek-coder-v2",
"temperature": 0.7,
"max_tokens": 1024,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}
@cl.on_chat_start
async def start_chat():
elements = [
cl.Image(name="image1", display="inline", path="deepseek-coder-v2.png", size = "large")
]
await cl.Message(content="Hello there, I am deepseek-coder-v2. How can I help you ?", elements=elements).send()
cl.user_session.set(
"message_history",
[
{"role": "system",
"content": "You are an expert in guiding coding issues. Please carefully answer users’ questions about code writing."}
],
)
@cl.on_message
async def main(message: cl.Message):
message_history = cl.user_session.get("message_history")
message_history.append({"role": "user", "content": message.content})
msg = cl.Message(content="")
await msg.send()
stream = await client.chat.completions.create(
messages=message_history, stream=True, **settings
)
async for part in stream:
if token := part.choices[0].delta.content or "":
await msg.stream_token(token)
message_history.append({"role": "assistant", "content": msg.content})
await msg.update()