Disable api
Browse filesFiles changed (3)
- app_allenai.py+4-1
- app_experimental.py+82-96
- app_marco_o1.py+4-1
4 unmodified lines567894 unmodified linesdemo = gr.load(name="allenai/Llama-3.1-Tulu-3-8B", src=transformers_gradio.registry)demo.fn = spaces.GPU()(demo.fn)if __name__ == "__main__":demo.launch()4 unmodified lines567891011124 unmodified linesdemo = gr.load(name="allenai/Llama-3.1-Tulu-3-8B", src=transformers_gradio.registry)demo.fn = spaces.GPU()(demo.fn)for fn in demo.fns.values():fn.api_name = Falseif __name__ == "__main__":demo.launch()
12345678910111215 unmodified lines28293031323334358 unmodified lines4445464748499 unmodified lines59606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241252 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792 unmodified lines2822832842852862872881 unmodified line290291292293294295296297298299300301302303304305306307308309310311import osimport gradio as grfrom typing import List, Dict, Callableimport randomimport google.generativeai as genaifrom anthropic import Anthropicimport openaifrom openai import OpenAI # Add explicit OpenAI importdef get_all_models():"""Get all available models from the registries."""return [15 unmodified lines"Hyperbolic: meta-llama/Meta-Llama-3.1-405B-Instruct",]def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:"""Generate a prompt for models to discuss and build upon previous responses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:8 unmodified linesKeep your response focused and concise (max 3-4 paragraphs)."""return promptdef generate_consensus_prompt(original_question: str, discussion_history: List[str]) -> str:"""Generate a prompt for final consensus building."""return f"""Review this multi-AI discussion about: "{original_question}"9 unmodified linesKeep the final consensus concise but complete."""def chat_with_openai(model: str, messages: List[Dict], api_key: str) -> str:import openaiclient = openai.OpenAI(api_key=api_key)response = client.chat.completions.create(model=model,messages=messages)return response.choices[0].message.contentdef chat_with_anthropic(messages: List[Dict], api_key: str) -> str:"""Chat with Anthropic's Claude model."""client = Anthropic(api_key=api_key)response = client.messages.create(model="claude-3-sonnet-20240229",messages=messages,max_tokens=1024)return response.content[0].textdef chat_with_gemini(messages: List[Dict], api_key: str) -> str:"""Chat with Gemini Pro model."""genai.configure(api_key=api_key)model = genai.GenerativeModel('gemini-pro')# Convert messages to Gemini formatgemini_messages = []for msg in messages:role = "user" if msg["role"] == "user" else "model"gemini_messages.append({"role": role, "parts": [msg["content"]]})response = model.generate_content([m["parts"][0] for m in gemini_messages])return response.textdef chat_with_sambanova(messages: List[Dict], api_key: str, model_name: str = "Llama-3.2-90B-Vision-Instruct") -> str:"""Chat with SambaNova's models using their OpenAI-compatible API."""client = openai.OpenAI(api_key=api_key,base_url="https://api.sambanova.ai/v1",)response = client.chat.completions.create(model=model_name, # Use the specific model name passed inmessages=messages,temperature=0.1,top_p=0.1)return response.choices[0].message.contentdef chat_with_hyperbolic(messages: List[Dict], api_key: str, model_name: str = "Qwen/Qwen2.5-Coder-32B-Instruct") -> str:"""Chat with Hyperbolic's models using their OpenAI-compatible API."""client = OpenAI(api_key=api_key,base_url="https://api.hyperbolic.xyz/v1")# Add system message to the start of the messages listfull_messages = [{"role": "system", "content": "You are a helpful assistant. Be descriptive and clear."},*messages]response = client.chat.completions.create(model=model_name, # Use the specific model name passed inmessages=full_messages,2 unmodified lines)return response.choices[0].message.contentdef multi_model_consensus(question: str,selected_models: List[str],rounds: int = 3,progress: gr.Progress = gr.Progress()) -> tuple[str, List[Dict]]:if not selected_models:return "Please select at least one model to chat with.", []chat_history = []discussion_history = []# Initial responsesprogress(0, desc="Getting initial responses...")initial_responses = []for i, model in enumerate(selected_models):provider, model_name = model.split(": ", 1)try:if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")response = chat_with_anthropic(messages=[{"role": "user", "content": question}],api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")response = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": question}],api_key=api_key)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")response = chat_with_hyperbolic(messages=[{"role": "user", "content": question}],api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")response = chat_with_gemini(messages=[{"role": "user", "content": question}],api_key=api_key)initial_responses.append(f"{model}: {response}")discussion_history.append(f"Initial response from {model}:\n{response}")chat_history.append((f"Initial response from {model}", response))except Exception as e:chat_history.append((f"Error from {model}", str(e)))# Discussion roundsfor round_num in range(rounds):progress((round_num + 1) / (rounds + 2), desc=f"Discussion round {round_num + 1}...")round_responses = []random.shuffle(selected_models) # Randomize order each roundfor model in selected_models:provider, model_name = model.split(": ", 1)try:discussion_prompt = generate_discussion_prompt(question, discussion_history)if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")response = chat_with_anthropic(messages=[{"role": "user", "content": discussion_prompt}],api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")response = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": discussion_prompt}],api_key=api_key)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")response = chat_with_hyperbolic(messages=[{"role": "user", "content": discussion_prompt}],api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")response = chat_with_gemini(messages=[{"role": "user", "content": discussion_prompt}],api_key=api_key)round_responses.append(f"{model}: {response}")discussion_history.append(f"Round {round_num + 1} - {model}:\n{response}")chat_history.append((f"Round {round_num + 1} - {model}", response))except Exception as e:chat_history.append((f"Error from {model} in round {round_num + 1}", str(e)))# Final consensusprogress(0.9, desc="Building final consensus...")model = selected_models[0]provider, model_name = model.split(": ", 1)try:consensus_prompt = generate_consensus_prompt(question, discussion_history)if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")final_consensus = chat_with_anthropic(messages=[{"role": "user", "content": consensus_prompt}],api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")final_consensus = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": consensus_prompt}],api_key=api_key)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")final_consensus = chat_with_hyperbolic(messages=[{"role": "user", "content": consensus_prompt}],api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")final_consensus = chat_with_gemini(messages=[{"role": "user", "content": consensus_prompt}],api_key=api_key)except Exception as e:final_consensus = f"Error getting consensus from {model}: {str(e)}"chat_history.append(("Final Consensus", final_consensus))progress(1.0, desc="Done!")return chat_historywith gr.Blocks() as demo:gr.Markdown("# Experimental Multi-Model Consensus Chat")gr.Markdown("""Select multiple models to collaborate on answering your question.The models will discuss with each other and attempt to reach a consensus.Maximum 3 models can be selected at once.""")with gr.Row():with gr.Column():model_selector = gr.Dropdown(2 unmodified lineslabel="Select Models (max 3)",info="Choose up to 3 models to participate in the discussion",value=["SambaNova: Llama-3.2-90B-Vision-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct"],max_choices=3)rounds_slider = gr.Slider(minimum=1,1 unmodified linevalue=1,step=1,label="Discussion Rounds",info="Number of rounds of discussion between models")chatbot = gr.Chatbot(height=600, label="Multi-Model Discussion")msg = gr.Textbox(label="Your Question", placeholder="Ask a question for the models to discuss...")def respond(message, selected_models, rounds):chat_history = multi_model_consensus(message, selected_models, rounds)return chat_historymsg.submit(respond,[msg, model_selector, rounds_slider],[chatbot],api_name="consensus_chat")if __name__ == "__main__":demo.launch()123456789101112131415 unmodified lines303132333435363738398 unmodified lines484950515253549 unmodified lines6465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261272 unmodified lines1301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672 unmodified lines2702712722732742752761 unmodified line278279280281282283284285286287288289290291292293294295296297import osimport randomfrom typing import Dict, Listimport google.generativeai as genaiimport gradio as grimport openaifrom anthropic import Anthropicfrom openai import OpenAI # Add explicit OpenAI importdef get_all_models():"""Get all available models from the registries."""return [15 unmodified lines"Hyperbolic: meta-llama/Meta-Llama-3.1-405B-Instruct",]def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:"""Generate a prompt for models to discuss and build upon previousresponses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:8 unmodified linesKeep your response focused and concise (max 3-4 paragraphs)."""return promptdef generate_consensus_prompt(original_question: str, discussion_history: List[str]) -> str:"""Generate a prompt for final consensus building."""return f"""Review this multi-AI discussion about: "{original_question}"9 unmodified linesKeep the final consensus concise but complete."""def chat_with_openai(model: str, messages: List[Dict], api_key: str | None) -> str:import openaiclient = openai.OpenAI(api_key=api_key)response = client.chat.completions.create(model=model, messages=messages)return response.choices[0].message.contentdef chat_with_anthropic(messages: List[Dict], api_key: str | None) -> str:"""Chat with Anthropic's Claude model."""client = Anthropic(api_key=api_key)response = client.messages.create(model="claude-3-sonnet-20240229", messages=messages, max_tokens=1024)return response.content[0].textdef chat_with_gemini(messages: List[Dict], api_key: str | None) -> str:"""Chat with Gemini Pro model."""genai.configure(api_key=api_key)model = genai.GenerativeModel("gemini-pro")# Convert messages to Gemini formatgemini_messages = []for msg in messages:role = "user" if msg["role"] == "user" else "model"gemini_messages.append({"role": role, "parts": [msg["content"]]})response = model.generate_content([m["parts"][0] for m in gemini_messages])return response.textdef chat_with_sambanova(messages: List[Dict], api_key: str | None, model_name: str = "Llama-3.2-90B-Vision-Instruct") -> str:"""Chat with SambaNova's models using their OpenAI-compatible API."""client = openai.OpenAI(api_key=api_key,base_url="https://api.sambanova.ai/v1",)response = client.chat.completions.create(model=model_name, messages=messages, temperature=0.1, top_p=0.1 # Use the specific model name passed in)return response.choices[0].message.contentdef chat_with_hyperbolic(messages: List[Dict], api_key: str | None, model_name: str = "Qwen/Qwen2.5-Coder-32B-Instruct") -> str:"""Chat with Hyperbolic's models using their OpenAI-compatible API."""client = OpenAI(api_key=api_key, base_url="https://api.hyperbolic.xyz/v1")# Add system message to the start of the messages listfull_messages = [{"role": "system", "content": "You are a helpful assistant. Be descriptive and clear."},*messages,]response = client.chat.completions.create(model=model_name, # Use the specific model name passed inmessages=full_messages,2 unmodified lines)return response.choices[0].message.contentdef multi_model_consensus(question: str, selected_models: List[str], rounds: int = 3, progress: gr.Progress = gr.Progress()) -> list[tuple[str, str]]:if not selected_models:raise gr.Error("Please select at least one model to chat with.")chat_history = []discussion_history = []# Initial responsesprogress(0, desc="Getting initial responses...")initial_responses = []for i, model in enumerate(selected_models):provider, model_name = model.split(": ", 1)try:if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")response = chat_with_anthropic(messages=[{"role": "user", "content": question}], api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")response = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": question},],api_key=api_key,)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")response = chat_with_hyperbolic(messages=[{"role": "user", "content": question}], api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")response = chat_with_gemini(messages=[{"role": "user", "content": question}], api_key=api_key)initial_responses.append(f"{model}: {response}")discussion_history.append(f"Initial response from {model}:\n{response}")chat_history.append((f"Initial response from {model}", response))except Exception as e:chat_history.append((f"Error from {model}", str(e)))# Discussion roundsfor round_num in range(rounds):progress((round_num + 1) / (rounds + 2), desc=f"Discussion round {round_num + 1}...")round_responses = []random.shuffle(selected_models) # Randomize order each roundfor model in selected_models:provider, model_name = model.split(": ", 1)try:discussion_prompt = generate_discussion_prompt(question, discussion_history)if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")response = chat_with_anthropic(messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")response = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": discussion_prompt},],api_key=api_key,)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")response = chat_with_hyperbolic(messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")response = chat_with_gemini(messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key)round_responses.append(f"{model}: {response}")discussion_history.append(f"Round {round_num + 1} - {model}:\n{response}")chat_history.append((f"Round {round_num + 1} - {model}", response))except Exception as e:chat_history.append((f"Error from {model} in round {round_num + 1}", str(e)))# Final consensusprogress(0.9, desc="Building final consensus...")model = selected_models[0]provider, model_name = model.split(": ", 1)try:consensus_prompt = generate_consensus_prompt(question, discussion_history)if provider == "Anthropic":api_key = os.getenv("ANTHROPIC_API_KEY")final_consensus = chat_with_anthropic(messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key)elif provider == "SambaNova":api_key = os.getenv("SAMBANOVA_API_KEY")final_consensus = chat_with_sambanova(messages=[{"role": "system", "content": "You are a helpful assistant"},{"role": "user", "content": consensus_prompt},],api_key=api_key,)elif provider == "Hyperbolic": # Add Hyperbolic caseapi_key = os.getenv("HYPERBOLIC_API_KEY")final_consensus = chat_with_hyperbolic(messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key)else: # Geminiapi_key = os.getenv("GEMINI_API_KEY")final_consensus = chat_with_gemini(messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key)except Exception as e:final_consensus = f"Error getting consensus from {model}: {str(e)}"chat_history.append(("Final Consensus", final_consensus))progress(1.0, desc="Done!")return chat_historywith gr.Blocks() as demo:gr.Markdown("# Experimental Multi-Model Consensus Chat")gr.Markdown("""Select multiple models to collaborate on answering your question.The models will discuss with each other and attempt to reach a consensus.Maximum 3 models can be selected at once.""")with gr.Row():with gr.Column():model_selector = gr.Dropdown(2 unmodified lineslabel="Select Models (max 3)",info="Choose up to 3 models to participate in the discussion",value=["SambaNova: Llama-3.2-90B-Vision-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct"],max_choices=3,)rounds_slider = gr.Slider(minimum=1,1 unmodified linevalue=1,step=1,label="Discussion Rounds",info="Number of rounds of discussion between models",)chatbot = gr.Chatbot(height=600, label="Multi-Model Discussion")msg = gr.Textbox(label="Your Question", placeholder="Ask a question for the models to discuss...")def respond(message, selected_models, rounds):chat_history = multi_model_consensus(message, selected_models, rounds)return chat_historymsg.submit(respond, [msg, model_selector, rounds_slider], [chatbot], api_name="consensus_chat")for fn in demo.fns.values():fn.api_name = Falseif __name__ == "__main__":demo.launch()
4 unmodified lines567894 unmodified linesdemo = gr.load(name="AIDC-AI/Marco-o1", src=transformers_gradio.registry)demo.fn = spaces.GPU()(demo.fn)if __name__ == "__main__":demo.launch()4 unmodified lines567891011124 unmodified linesdemo = gr.load(name="AIDC-AI/Marco-o1", src=transformers_gradio.registry)demo.fn = spaces.GPU()(demo.fn)for fn in demo.fns.values():fn.api_name = Falseif __name__ == "__main__":demo.launch()
app_allenai.py+4-1
app_experimental.py+82-96
app_marco_o1.py+4-1