ParthSadaria commited on
Commit
d8a25bb
·
verified ·
1 Parent(s): 88fcb56

Update playground.html

Browse files
Files changed (1) hide show
  1. playground.html +102 -62
playground.html CHANGED
@@ -685,74 +685,114 @@ document.addEventListener('DOMContentLoaded', function() {
685
 
686
  // Fetch available models
687
  async function fetchModels() {
688
- try {
689
- const response = await fetch('https://parthsadaria-lokiai.hf.space/models', {
690
- headers: {
691
- 'Authorization': 'playground'
692
- }
693
- });
694
-
695
- if (response.ok) {
696
- const data = await response.json();
697
- modelsList = data.data || [];
698
-
699
- // Add search GPT option
700
- modelsList.push({
701
- id: 'searchgpt',
702
- displayName: 'SearchGPT (with internet)',
703
- description: 'GPT model with internet search capability'
704
- });
705
-
706
- populateModelOptions(modelsList);
707
- } else {
708
- modelLoader.textContent = 'Failed to load models';
709
- }
710
- } catch (error) {
711
- console.error('Error fetching models:', error);
712
- modelLoader.textContent = 'Error loading models';
713
- }
 
 
 
714
  }
715
-
716
- // Populate model dropdown
717
- function populateModelOptions(models) {
718
- modelOptions.innerHTML = '';
719
-
720
- if (models.length === 0) {
721
- const noModels = document.createElement('div');
722
- noModels.className = 'py-2 px-4 text-sm text-gray-600 dark:text-gray-400';
723
- noModels.textContent = 'No models available';
724
- modelOptions.appendChild(noModels);
725
- return;
726
- }
727
-
728
- models.forEach(model => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  const option = document.createElement('div');
730
- option.className = 'py-2 px-4 text-sm hover:bg-light-input dark:hover:bg-dark-input cursor-pointer';
731
- option.dataset.modelId = model.id;
732
-
733
- const modelName = document.createElement('div');
734
- modelName.className = 'font-medium text-gray-800 dark:text-gray-200';
735
- modelName.textContent = model.displayName || model.id;
736
-
737
- const modelDesc = document.createElement('div');
738
- modelDesc.className = 'text-xs text-gray-500 dark:text-gray-400';
739
- modelDesc.textContent = model.description || '';
740
-
741
- option.appendChild(modelName);
742
- option.appendChild(modelDesc);
743
-
744
- option.addEventListener('click', function() {
745
- selectModel(model);
746
- });
747
-
748
  modelOptions.appendChild(option);
749
  });
750
-
751
- // Default to first model if available
752
- if (models.length > 0 && !selectedModel) {
753
- selectModel(models[0]);
 
 
 
 
 
 
 
 
 
 
 
 
754
  }
755
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
756
 
757
  // Select a model
758
  function selectModel(model) {
 
685
 
686
  // Fetch available models
687
  async function fetchModels() {
688
+ try {
689
+ const response = await fetch('https://parthsadaria-lokiai.hf.space/models', {
690
+ method: 'GET',
691
+ headers: { 'Authorization': 'playground' }
692
+ });
693
+ if (response.ok) {
694
+ const data = await response.json();
695
+ modelsList = data;
696
+ populateModels(data);
697
+ } else {
698
+ const fallbackModels = [
699
+ { id: "gpt-4o", object: "model" },
700
+ { id: "gpt-3.5-turbo", object: "model" },
701
+ { id: "claude-3-5-sonnet", object: "model" },
702
+ { id: "claude-3-haiku", object: "model" },
703
+ { id: "llama-3.1-70b", object: "model" }
704
+ ];
705
+ populateModels(fallbackModels);
706
+ }
707
+ } catch (error) {
708
+ console.error('Error fetching models:', error);
709
+ const fallbackModels = [
710
+ { id: "gpt-4o", object: "model" },
711
+ { id: "gpt-3.5-turbo", object: "model" },
712
+ { id: "claude-3-5-sonnet", object: "model" },
713
+ { id: "claude-3-haiku", object: "model" },
714
+ { id: "llama-3.1-70b", object: "model" }
715
+ ];
716
+ populateModels(fallbackModels);
717
  }
718
+ }
719
+
720
+ function populateModels(models) {
721
+ // Group models by provider
722
+ const providers = {};
723
+ models.forEach(model => {
724
+ const modelName = model.id;
725
+ let provider = 'Other';
726
+ if (modelName.includes('gpt')) provider = 'OpenAI';
727
+ else if (modelName.includes('claude')) provider = 'Anthropic';
728
+ else if (modelName.includes('llama')) provider = 'Meta';
729
+ else if (modelName.includes('gemini')) provider = 'Google';
730
+ else if (modelName.includes('mistral')) provider = 'Mistral';
731
+ else if (modelName.includes('yi')) provider = 'Yi';
732
+ if (!providers[provider]) providers[provider] = [];
733
+ providers[provider].push(model);
734
+ });
735
+
736
+ // Clear existing options
737
+ modelOptions.innerHTML = '';
738
+
739
+ // Add special option for web search
740
+ const searchOption = document.createElement('div');
741
+ searchOption.className = 'px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer';
742
+ searchOption.textContent = 'SearchGPT (Web-access)';
743
+ searchOption.dataset.value = 'searchgpt';
744
+ modelOptions.appendChild(searchOption);
745
+
746
+ // Add a separator
747
+ const separator = document.createElement('div');
748
+ separator.className = 'px-4 py-1 text-xs font-semibold text-gray-500 bg-gray-50 dark:bg-gray-800 dark:text-gray-400';
749
+ separator.textContent = 'AI Models';
750
+ modelOptions.appendChild(separator);
751
+
752
+ // Create and append provider groups and their models
753
+ Object.keys(providers).sort().forEach(provider => {
754
+ const providerGroup = document.createElement('div');
755
+ providerGroup.className = 'px-4 py-1 text-xs font-semibold text-gray-500 bg-gray-50 dark:bg-gray-800 dark:text-gray-400';
756
+ providerGroup.textContent = provider;
757
+ modelOptions.appendChild(providerGroup);
758
+ providers[provider].sort((a, b) => a.id.localeCompare(b.id)).forEach(model => {
759
  const option = document.createElement('div');
760
+ option.className = 'px-4 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer';
761
+ option.textContent = model.id;
762
+ option.dataset.value = model.id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
  modelOptions.appendChild(option);
764
  });
765
+ });
766
+
767
+ // Set default model if none selected
768
+ if (!selectedModel && models.length > 0) {
769
+ const preferredModels = ['gpt-4o', 'gpt-4', 'claude-3-5-sonnet', 'gpt-3.5-turbo'];
770
+ for (const preferred of preferredModels) {
771
+ const match = models.find(m => m.id.includes(preferred));
772
+ if (match) {
773
+ selectedModel = match.id;
774
+ modelSelectDisplay.textContent = selectedModel;
775
+ break;
776
+ }
777
+ }
778
+ if (!selectedModel) {
779
+ selectedModel = models[0].id;
780
+ modelSelectDisplay.textContent = selectedModel;
781
  }
782
  }
783
+
784
+ // Add click event listeners
785
+ document.querySelectorAll('#modelOptions > div').forEach(option => {
786
+ if (option.dataset.value) {
787
+ option.addEventListener('click', function() {
788
+ selectedModel = this.dataset.value;
789
+ modelSelectDisplay.textContent = this.textContent;
790
+ modelOptions.classList.add('hidden');
791
+ });
792
+ }
793
+ });
794
+ }
795
+
796
 
797
  // Select a model
798
  function selectModel(model) {