0.0.2 • Published 1 year ago

@bodhiapp/bodhijs v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

bodhijs

A JavaScript library for interacting with local LLM capabilities via Bodhi Browser Extension.

Installation

You can use bodhijs either via npm or directly in the browser with a script tag.

NPM Installation

npm install @bodhiapp/bodhijs

Browser Installation

Download the latest bodhi.js from the releases page and include it in your HTML:

<script src="dist/bodhi.js"></script>

Usage

Using with NPM

import { bodhijs } from '@bodhiapp/bodhijs';

// Check if extension is installed
const isInstalled = bodhijs.isInstalled();
console.log('Extension installed:', isInstalled);

// Example chat completion
async function example() {
  try {
    // First verify connection with a ping
    const pingResult = await bodhijs.ping();
    console.log('Ping result:', pingResult);
    
    // Use chat completions
    const response = await bodhijs.chat.completions.create({
      model: 'bartowski/Meta-Llama-3.1-8B-Instruct-GGUF:Q4_K_M',
      messages: [
        { role: 'user', content: 'Hello, how can you help me?' }
      ]
    });
    
    console.log('Chat response:', response);
  } catch (error) {
    console.error('Error:', error);
  }
}

// Call the example function
example();

Using with Script Tag

<script src="dist/bodhi.js"></script>
<script>
  // The library is available globally as 'bodhijs'
  
  // Check if extension is installed
  const isInstalled = bodhijs.isInstalled();
  console.log('Extension installed:', isInstalled);

  // Example chat completion
  async function example() {
    try {
      // First verify connection with a ping
      const pingResult = await bodhijs.ping();
      console.log('Ping result:', pingResult);
      
      // Use chat completions
      const response = await bodhijs.chat.completions.create({
        model: 'bartowski/Meta-Llama-3.1-8B-Instruct-GGUF:Q4_K_M',
        messages: [
          { role: 'user', content: 'Hello, how can you help me?' }
        ]
      });
      
      console.log('Chat response:', response);
    } catch (error) {
      console.error('Error:', error);
    }
  }

  // Call the example function
  example();
</script>

API Reference

bodhijs.isInstalled()

Returns a boolean indicating whether the Bodhi Browser Extension is installed.

bodhijs.ping()

Tests the connection to the extension. Returns a promise that resolves to a ping response.

bodhijs.chat.completions.create(options)

Creates a chat completion request.

  • options.model: The model to use (e.g., 'bartowski/Meta-Llama-3.1-8B-Instruct-GGUF:Q4_K_M')
  • options.messages: Array of message objects with role and content

Development

# Install dependencies
npm install

# Build the library
npm run build

# Run in development mode with watch
npm run dev

# Run validation (format and lint checks)
npm run validate

# Format code
npm run format

# Run lint checks
npm run lint

Testing

The library is tested through integration tests in the integration-tests directory. These tests verify both npm package usage and script tag usage.

To run the tests: 1. Build the library: npm run build 2. Navigate to integration-tests: cd ../integration-tests 3. Run tests: npm test

License

MIT

0.0.2

1 year ago

0.0.1

1 year ago