Update functions.py
Browse files- functions.py +6 -8
functions.py
CHANGED
@@ -1,16 +1,14 @@
|
|
1 |
import plotly.express as px
|
2 |
-
import gradio as gr
|
3 |
from client import client
|
4 |
|
5 |
# Fungsi untuk menghasilkan plot acak
|
6 |
def random_plot():
|
7 |
df = px.data.iris()
|
8 |
-
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
|
9 |
-
size='petal_length', hover_data=['petal_width'])
|
10 |
return fig
|
11 |
|
12 |
# Fungsi untuk mencetak data suka/tidak suka
|
13 |
-
def print_like_dislike(x
|
14 |
print(x.index, x.value, x.liked)
|
15 |
|
16 |
# Fungsi untuk menambahkan pesan ke riwayat
|
@@ -23,8 +21,8 @@ def add_message(history, message):
|
|
23 |
return history, gr.Textbox(value="", interactive=True)
|
24 |
|
25 |
# Fungsi untuk menghubungkan dengan model Llama
|
26 |
-
def chat_mem(message, chat_history):
|
27 |
-
chat_history_role = [{"role": "system", "content": "Anda adalah Chat Bot milik Riswan Nopiyar, yang dirancang untuk membantu menjawab pertanyaan dan memberikan informasi dengan sopan dan akurat dalam bahasa Indonesia. Seluruh percakapan akan dilakukan dalam bahasa Indonesia.
|
28 |
|
29 |
if chat_history:
|
30 |
for user_msg, assistant_msg in chat_history:
|
@@ -38,7 +36,7 @@ def chat_mem(message, chat_history):
|
|
38 |
else:
|
39 |
chat_completion = client.chat_completion(
|
40 |
messages=chat_history_role,
|
41 |
-
max_tokens=
|
42 |
)
|
43 |
assistant_response = chat_completion.choices[0].message.content
|
44 |
|
@@ -47,4 +45,4 @@ def chat_mem(message, chat_history):
|
|
47 |
modified = [msg["content"] for msg in chat_history_role]
|
48 |
chat_history = [(modified[i * 2 + 1], modified[i * 2 + 2]) for i in range(len(modified) // 2)]
|
49 |
|
50 |
-
return "", chat_history
|
|
|
1 |
import plotly.express as px
|
|
|
2 |
from client import client
|
3 |
|
4 |
# Fungsi untuk menghasilkan plot acak
|
5 |
def random_plot():
|
6 |
df = px.data.iris()
|
7 |
+
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size='petal_length', hover_data=['petal_width'])
|
|
|
8 |
return fig
|
9 |
|
10 |
# Fungsi untuk mencetak data suka/tidak suka
|
11 |
+
def print_like_dislike(x):
|
12 |
print(x.index, x.value, x.liked)
|
13 |
|
14 |
# Fungsi untuk menambahkan pesan ke riwayat
|
|
|
21 |
return history, gr.Textbox(value="", interactive=True)
|
22 |
|
23 |
# Fungsi untuk menghubungkan dengan model Llama
|
24 |
+
def chat_mem(message, chat_history, max_tokens=512):
|
25 |
+
chat_history_role = [{"role": "system", "content": "Anda adalah Chat Bot milik Riswan Nopiyar, yang dirancang untuk membantu menjawab pertanyaan dan memberikan informasi dengan sopan dan akurat dalam bahasa Indonesia. Seluruh percakapan akan dilakukan dalam bahasa Indonesia."}]
|
26 |
|
27 |
if chat_history:
|
28 |
for user_msg, assistant_msg in chat_history:
|
|
|
36 |
else:
|
37 |
chat_completion = client.chat_completion(
|
38 |
messages=chat_history_role,
|
39 |
+
max_tokens=max_tokens,
|
40 |
)
|
41 |
assistant_response = chat_completion.choices[0].message.content
|
42 |
|
|
|
45 |
modified = [msg["content"] for msg in chat_history_role]
|
46 |
chat_history = [(modified[i * 2 + 1], modified[i * 2 + 2]) for i in range(len(modified) // 2)]
|
47 |
|
48 |
+
return "", chat_history
|