on1onmangoes commited on
Commit
61c92f4
·
verified ·
1 Parent(s): 6a518f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -38
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
- # OG code in V9
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 = 10,
18
- num_docs_final: int = 9,
19
- temperature: float = 0,
20
- max_new_tokens: int = 1024,
21
- top_p: float = 1.0,
22
- top_k: int = 20,
23
- penalty: float = 1.2,
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
- result = client.predict(
44
- message=message,
45
- client_name="rosariarossi",
46
- system_prompt="You are an expert assistant",
47
- num_retrieved_docs=10,
48
- num_docs_final=9,
49
- temperature=0,
50
- max_new_tokens=1024,
51
- top_p=1,
52
- top_k=20,
53
- penalty=1.2,
54
- api_name="/chat"
55
- )
56
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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