Website Check out my blogs Check out this library's blogs

API-LLM-Hub Demo

What is API-LLM-Hub?

API-LLM-Hub is a lightweight JavaScript library that simplifies the use of multiple AI language models directly in your web browser, with no build steps or backend required.

Direct Usage Example


<script type="module">
  import APILLMHub from 'https://amanpriyanshu.github.io/API-LLM-Hub/unified-llm-api.js';

  const ai = new APILLMHub({
    provider: 'anthropic',
    apiKey: 'your-anthropic-api-key',
    model: 'claude-3-5-sonnet-20240620',
    maxTokens: 50,
    temperature: 0.7
  });
  
  await ai.initialize();
  const response = await ai.sendMessage("Hello, how are you?");
  document.body.innerHTML += `<p>Input: Hello<br>Output: ${response}</p>`;
  console.log(response);
</script>
        

API Keys

Individual Provider Examples


<script type="module">
  import APILLMHub from 'https://amanpriyanshu.github.io/API-LLM-Hub/unified-llm-api.js';
  
  async function runOpenAIExample() {
    const ai = new APILLMHub({
      provider: 'openai',
      apiKey: 'your-openai-api-key',
      model: 'gpt-3.5-turbo',
      maxTokens: 50,
      temperature: 0.7
    });
                
    await ai.initialize();
    const response = await ai.sendMessage("Hello");
    console.log(response);
  document.body.innerHTML += `<p>Input: Hello<br>Output: ${response}</p>`;
  }
  
  runOpenAIExample();
</script>
            

<script type="module">
  import APILLMHub from 'https://amanpriyanshu.github.io/API-LLM-Hub/unified-llm-api.js';
  
  async function runAnthropicExample() {
    const ai = new APILLMHub({
      provider: 'anthropic',
      apiKey: 'your-anthropic-api-key',
      model: 'claude-3-5-sonnet-20240620',
      maxTokens: 50,
      temperature: 0.7
    });
                
    await ai.initialize();
    const response = await ai.sendMessage("Hello");
    console.log(response);
  document.body.innerHTML += `<p>Input: Hello<br>Output: ${response}</p>`;
  }
  
  runAnthropicExample();
</script>
            

<script type="module">
  import APILLMHub from 'https://amanpriyanshu.github.io/API-LLM-Hub/unified-llm-api.js';
  
  async function runTogetherAIExample() {
    const ai = new APILLMHub({
      provider: 'togetherai',
      apiKey: 'your-togetherai-api-key',
      model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',
      maxTokens: 50,
      temperature: 0.7
    });
                
    await ai.initialize();
    const response = await ai.sendMessage("Hello");
    console.log(response);
  document.body.innerHTML += `<p>Input: Hello<br>Output: ${response}</p>`;
  }
  
  runTogetherAIExample();
</script>
            

<script type="module">
  import APILLMHub from 'https://amanpriyanshu.github.io/API-LLM-Hub/unified-llm-api.js';
  
  async function runGeminiExample() {
    const ai = new APILLMHub({
      provider: 'gemini',
      apiKey: 'your-gemini-api-key',
      model: 'gemini-1.5-pro',
      maxTokens: 50,
      temperature: 0.7
    });
                
    await ai.initialize();
    const response = await ai.sendMessage("Hello");
    console.log(response);
  document.body.innerHTML += `<p>Input: Hello<br>Output: ${response}</p>`;
  }
  
  runGeminiExample();
</script>
            

Explore More

For a deep dive into my personal blogs within AI's evolution and its practical applications, visit my AI blog. Also, if you're interested in efficient, on-premise AI models? Explore my curated list of personal model picks for privacy-preserving and adaptable AI solutions. Finally, for those concerned about AI safety, read about my recent work on decomposing malicious intents for jailbreaking LLMs Finally, if you're curious about my work in AI beyond this demo? Check out my personal website for more projects and insights.