Spaces:
Sleeping
Sleeping
import gradio as gr | |
from huggingface_hub import InferenceClient | |
client = InferenceClient("google/gemma-1.1-2b-it") | |
client = InferenceClient("mistralai/Mistral-Nemo-Instruct-2407") | |
def models(Query): | |
messages = [] | |
messages.append({"role": "user", "content": f"[SYSTEM] You are ASSISTANT who answer question asked by user in short and concise manner. [USER] {Query}"}) | |
Response = "" | |
for message in client.chat_completion( | |
messages, | |
max_tokens=2048, | |
stream=True | |
): | |
token = message.choices[0].delta.content | |
Response += token | |
yield Response | |
def nemo(query): | |
budget = 3 | |
message = f"""[INST] [SYSTEM] You are a helpful assistant in normal conversation. | |
When given a problem to solve, you are an expert problem-solving assistant. | |
Your task is to provide a detailed, step-by-step solution to a given question. | |
Follow these instructions carefully: | |
1. Read the given question carefully and reset counter between <count> and </count> to {budget} (maximum 3 steps). | |
2. Think critically like a human researcher or scientist. Break down the problem using first principles to conceptually understand and answer the question. | |
3. Generate a detailed, logical step-by-step solution. | |
4. Enclose each step of your solution within <step> and </step> tags. | |
5. You are allowed to use at most {budget} steps (starting budget), keep track of it by counting down within tags <count> </count>, STOP GENERATING MORE STEPS when hitting 0, you don't have to use all of them. | |
6. Do a self-reflection when you are unsure about how to proceed, based on the self-reflection and reward, decide whether you need to return to the previous steps. | |
7. After completing the solution steps, reorganize and synthesize the steps into the final answer within <answer> and </answer> tags. | |
8. Provide a critical, honest, and subjective self-evaluation of your reasoning process within <reflection> and </reflection> tags. | |
9. Assign a quality score to your solution as a float between 0.0 (lowest quality) and 1.0 (highest quality), enclosed in <reward> and </reward> tags. | |
Example format: | |
<count> [starting budget] </count> | |
<step> [Content of step 1] </step> | |
<count> [remaining budget] </count> | |
<step> [Content of step 2] </step> | |
<reflection> [Evaluation of the steps so far] </reflection> | |
<reward> [Float between 0.0 and 1.0] </reward> | |
<count> [remaining budget] </count> | |
<step> [Content of step 3 or Content of some previous step] </step> | |
<count> [remaining budget] </count> | |
... | |
<step> [Content of final step] </step> | |
<count> [remaining budget] </count> | |
<answer> [Final Answer] </answer> (must give final answer in this format) | |
<reflection> [Evaluation of the solution] </reflection> | |
<reward> [Float between 0.0 and 1.0] </reward> [/INST] [INST] [QUERY] {query}""" | |
stream = client.text_generation(message, max_new_tokens=4096, stream=True, details=True, return_full_text=False) | |
output = "" | |
for response in stream: | |
output += response.token.text | |
return output | |
description="# Chat GO\n### Enter your query and Press enter and get lightning fast response" | |
demo = gr.Interface(description=description,fn=models, inputs=["text"], outputs="text") | |
demo2 = gr.Interface(description="Very low but critical thinker",fn=nemo, inputs=["text"], outputs="text", api_name="critical_thinker", concurrency_limit=10) | |
with gr.Blocks() as demo: | |
gr.TabbedInterface([demo, demo2] , ["Fast", "Critical"]) | |
demo.queue(max_size=300000) | |
demo.launch() |