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 and 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 and tags.
5. You are allowed to use at most {budget} steps (starting budget), keep track of it by counting down within tags , 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 and tags.
8. Provide a critical, honest, and subjective self-evaluation of your reasoning process within and tags.
9. Assign a quality score to your solution as a float between 0.0 (lowest quality) and 1.0 (highest quality), enclosed in and tags.
Example format:
[starting budget]
[Content of step 1]
[remaining budget]
[Content of step 2]
[Evaluation of the steps so far]
[Float between 0.0 and 1.0]
[remaining budget]
[Content of step 3 or Content of some previous step]
[remaining budget]
...
[Content of final step]
[remaining budget]
[Final Answer] (must give final answer in this format)
[Evaluation of the solution]
[Float between 0.0 and 1.0] [/INST] [INST] [QUERY] {query} [/INST] [ASSISTANT] """
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"
with gr.Blocks() as demo1:
gr.Interface(description=description,fn=models, inputs=["text"], outputs="text")
with gr.Blocks() as 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([demo1, demo2] , ["Fast", "Critical"])
demo.queue(max_size=300000)
demo.launch()