Create aux.py
Browse files
aux.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
# Use Meta's LLaMA 2 model
|
5 |
+
client = InferenceClient("meta-llama/Llama-2-7b-chat-hf", token="YOUR_HUGGING_FACE_TOKEN")
|
6 |
+
|
7 |
+
def respond(
|
8 |
+
message,
|
9 |
+
history: list[tuple[str, str]],
|
10 |
+
system_message,
|
11 |
+
max_tokens,
|
12 |
+
temperature,
|
13 |
+
top_p,
|
14 |
+
):
|
15 |
+
messages = [{"role": "system", "content": system_message}]
|
16 |
+
|
17 |
+
for val in history:
|
18 |
+
if val[0]:
|
19 |
+
messages.append({"role": "user", "content": val[0]})
|
20 |
+
if val[1]:
|
21 |
+
messages.append({"role": "assistant", "content": val[1]})
|
22 |
+
|
23 |
+
messages.append({"role": "user", "content": message})
|
24 |
+
|
25 |
+
response = ""
|
26 |
+
|
27 |
+
for message in client.chat_completion(
|
28 |
+
messages,
|
29 |
+
max_tokens=max_tokens,
|
30 |
+
stream=True,
|
31 |
+
temperature=temperature,
|
32 |
+
top_p=top_p,
|
33 |
+
):
|
34 |
+
token = message.choices[0].delta.content
|
35 |
+
|
36 |
+
response += token
|
37 |
+
yield response
|