Spaces:
Runtime error
Runtime error
on1onmangoes
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,52 +8,86 @@ HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using
|
|
8 |
# Initialize the Gradio Client for the specified API
|
9 |
client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
|
10 |
|
11 |
-
#
|
12 |
def stream_chat_with_rag(
|
13 |
message: str,
|
14 |
history: list,
|
15 |
client_name: str,
|
16 |
system_prompt: str,
|
17 |
-
num_retrieved_docs: int
|
18 |
-
num_docs_final: int
|
19 |
-
temperature: float
|
20 |
-
max_new_tokens: int
|
21 |
-
top_p: float
|
22 |
-
top_k: int
|
23 |
-
penalty: float
|
24 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
# Function to handle chat API call
|
27 |
-
# def stream_chat_with_rag(message, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
|
28 |
-
# response = client.predict(
|
29 |
-
# message=message,
|
30 |
-
# client_name="rosariarossi", # Hardcoded client name
|
31 |
-
# system_prompt=system_prompt,
|
32 |
-
# num_retrieved_docs=num_retrieved_docs,
|
33 |
-
# num_docs_final=num_docs_final,
|
34 |
-
# temperature=temperature,
|
35 |
-
# max_new_tokens=max_new_tokens,
|
36 |
-
# top_p=top_p,
|
37 |
-
# top_k=top_k,
|
38 |
-
# penalty=penalty,
|
39 |
-
# api_name="/chat"
|
40 |
-
# )
|
41 |
-
# return response
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
|
59 |
|
|
|
8 |
# Initialize the Gradio Client for the specified API
|
9 |
client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
|
10 |
|
11 |
+
# Function to handle chat API call
|
12 |
def stream_chat_with_rag(
|
13 |
message: str,
|
14 |
history: list,
|
15 |
client_name: str,
|
16 |
system_prompt: str,
|
17 |
+
num_retrieved_docs: int,
|
18 |
+
num_docs_final: int,
|
19 |
+
temperature: float,
|
20 |
+
max_new_tokens: int,
|
21 |
+
top_p: float,
|
22 |
+
top_k: int,
|
23 |
+
penalty: float,
|
24 |
):
|
25 |
+
# Use the parameters provided by the UI
|
26 |
+
response = client.predict(
|
27 |
+
message=message,
|
28 |
+
client_name=client_name,
|
29 |
+
system_prompt=system_prompt,
|
30 |
+
num_retrieved_docs=num_retrieved_docs,
|
31 |
+
num_docs_final=num_docs_final,
|
32 |
+
temperature=temperature,
|
33 |
+
max_new_tokens=max_new_tokens,
|
34 |
+
top_p=top_p,
|
35 |
+
top_k=top_k,
|
36 |
+
penalty=penalty,
|
37 |
+
api_name="/chat"
|
38 |
+
)
|
39 |
+
# Return the assistant's reply
|
40 |
+
return response
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
|
44 |
+
|
45 |
+
# # OG code in V9
|
46 |
+
# def stream_chat_with_rag(
|
47 |
+
# message: str,
|
48 |
+
# history: list,
|
49 |
+
# client_name: str,
|
50 |
+
# system_prompt: str,
|
51 |
+
# num_retrieved_docs: int = 10,
|
52 |
+
# num_docs_final: int = 9,
|
53 |
+
# temperature: float = 0,
|
54 |
+
# max_new_tokens: int = 1024,
|
55 |
+
# top_p: float = 1.0,
|
56 |
+
# top_k: int = 20,
|
57 |
+
# penalty: float = 1.2,
|
58 |
+
# ):
|
59 |
+
|
60 |
+
# # Function to handle chat API call
|
61 |
+
# # def stream_chat_with_rag(message, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
|
62 |
+
# # response = client.predict(
|
63 |
+
# # message=message,
|
64 |
+
# # client_name="rosariarossi", # Hardcoded client name
|
65 |
+
# # system_prompt=system_prompt,
|
66 |
+
# # num_retrieved_docs=num_retrieved_docs,
|
67 |
+
# # num_docs_final=num_docs_final,
|
68 |
+
# # temperature=temperature,
|
69 |
+
# # max_new_tokens=max_new_tokens,
|
70 |
+
# # top_p=top_p,
|
71 |
+
# # top_k=top_k,
|
72 |
+
# # penalty=penalty,
|
73 |
+
# # api_name="/chat"
|
74 |
+
# # )
|
75 |
+
# # return response
|
76 |
+
|
77 |
+
# result = client.predict(
|
78 |
+
# message=message,
|
79 |
+
# client_name="rosariarossi",
|
80 |
+
# system_prompt="You are an expert assistant",
|
81 |
+
# num_retrieved_docs=10,
|
82 |
+
# num_docs_final=9,
|
83 |
+
# temperature=0,
|
84 |
+
# max_new_tokens=1024,
|
85 |
+
# top_p=1,
|
86 |
+
# top_k=20,
|
87 |
+
# penalty=1.2,
|
88 |
+
# api_name="/chat"
|
89 |
+
# )
|
90 |
+
# return result
|
91 |
|
92 |
|
93 |
|