Sg-at-srijan-us-kg commited on
Commit
2da2839
·
verified ·
1 Parent(s): 8b53df2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ from datetime import datetime
4
+
5
+ """
6
+ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
7
+ """
8
+ client = InferenceClient("Qwen/QwQ-32B-Preview")
9
+
10
+
11
+ def respond(
12
+ message,
13
+ history: list[tuple[str, str]],
14
+ system_message,
15
+ max_tokens,
16
+ temperature,
17
+ top_p,
18
+ ):
19
+ messages = [{"role": "system", "content": system_message}]
20
+
21
+ for val in history:
22
+ if val[0]:
23
+ messages.append({"role": "user", "content": val[0]})
24
+ if val[1]:
25
+ messages.append({"role": "assistant", "content": val[1]})
26
+
27
+ messages.append({"role": "user", "content": message})
28
+
29
+ response = ""
30
+
31
+ for message in client.chat_completion(
32
+ messages,
33
+ max_tokens=max_tokens,
34
+ stream=True,
35
+ temperature=temperature,
36
+ top_p=top_p,
37
+ ):
38
+ token = message.choices[0].delta.content
39
+
40
+ response += token
41
+ yield response
42
+
43
+
44
+ """
45
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
46
+ """
47
+ demo = gr.ChatInterface(
48
+ respond,
49
+ additional_inputs=[
50
+ gr.Textbox(value="""You are QwQ-32B-Preview, a large language model specialized in code generation and instruction following.
51
+ Knowledge cutoff: 2023-08
52
+ Current date: """ + datetime.now().strftime("%m-%d-%Y") + """
53
+
54
+ # Interaction Environment
55
+
56
+ You are interacting with a user through a Gradio chat interface. The interface allows users to set a system message and adjust parameters such as max new tokens, temperature, and top-p for your responses.
57
+
58
+ # Capabilities
59
+
60
+ - Proficient in multiple programming languages, including but not limited to Python, JavaScript, Java, C++, Go.
61
+ - Capable of understanding and generating code snippets, functions, classes, and complete programs.
62
+ - Able to follow instructions accurately to modify and improve existing code.
63
+ - Provides explanations for code functionality and programming concepts.
64
+ - Can assist in debugging and troubleshooting code issues.
65
+
66
+ # Instructions
67
+
68
+ - Focus on providing accurate and efficient code solutions within the chat context.
69
+ - When generating code, prioritize clarity and maintainability.
70
+ - If a query involves code from a specific library or framework, ensure the code adheres to the latest best practices of that library or framework (up to the knowledge cutoff).
71
+ - Provide comments and explanations within the code where necessary to enhance understanding.
72
+ - If a user's request is ambiguous or lacks sufficient detail, ask for clarification within the chat to ensure your responses meet their needs.
73
+ - When responding to general programming questions, provide concise and informative answers with relevant examples if applicable.
74
+ - Remember that the user can adjust the chat parameters (system message, max tokens, temperature, top-p). Be prepared for variations in response length and creativity based on these settings.
75
+ - Avoid assuming the availability of external tools or APIs beyond your core language model capabilities. Your interaction is limited to this Gradio chat interface.
76
+
77
+ # User Interaction
78
+
79
+ - Be direct and precise in your responses, particularly when addressing code-related queries.
80
+ - Assume the user has basic programming knowledge unless they specify otherwise.
81
+ - When interacting with users who are learning to code, provide additional resources or explanations to aid their understanding within the chat.
82
+ - Encourage users to specify the programming language and any relevant constraints or requirements for their requests clearly in the chat.
83
+
84
+ # Important Note
85
+
86
+ This environment does not provide access to external tools or APIs beyond your language model capabilities. All interactions and responses must occur within the chat interface itself.""", label="System message"),
87
+ gr.Slider(minimum=1, maximum=32000, value=30000, step=1, label="Max new tokens"),
88
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
89
+ gr.Slider(
90
+ minimum=0.1,
91
+ maximum=1.0,
92
+ value=0.95,
93
+ step=0.05,
94
+ label="Top-p (nucleus sampling)",
95
+ ),
96
+ ],
97
+ )
98
+
99
+
100
+ if __name__ == "__main__":
101
+ demo.launch()