npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sdk_gigai

v0.2.11-beta.0

Published

<div style="text-align: center;"> <img style=" border: 1px solid #ddd; border-radius: 4px; padding: 5px; max-width: 35%; text-align: center;" src="https://main.gigasoft.com.pl/logo.png"> </img> </div>

Downloads

6

Readme

GigaAI Chat Hook Documentation

Current SDK version 0.2

Welcome to the GigaAI Chat Hook documentation. This React hook is designed to simplify the integration of GigaSoft's AI chat models into your application, providing a seamless interactive chat experience. Currently supporting several NLP models, this guide will walk you through installation, usage, and examples.

Changelog

  • 07.03.2024
interface UseGigaAIParams {
  api: string;
  additionalData?: AdditionalData;
}

export default function useGigaAI({
  api="api/chat",
  additionalData
}: UseGigaAIParams) 

Now u can send optional data to api

Added support for receiving raw replies

Example

export async function POST(req: Request) {
  const { messages } = await req.json();
  
  const raw = "aaaa";
  return new Response(raw);

  const stream = await Giga.chat({
    model: "GigAI-v1",
    messages: messages,
    stream:true, // must be set to true, for hook useGigAI react...
    
  })
  return new Response(stream);
}
  • 10.03.2024

Demo web app

Getting Started

The GigaAI Chat Hook (useGigaAI) is a part of @/package/core/frontend/react.ts within the GigaSoft AI package. It enables easy integration with GigaSoft AI's chat API, allowing for real-time chat functionalities within your React application. This initial version (v0.1) supports a selection of NLP models and will be updated to include more models such as GigAI-OCR in future releases.

src/app/api/chat/route.tsx

import Gigasoft from "@/package/core/backend/GigaSoft";
export const runtime = "edge";
const Giga = new Gigasoft({
  API_KEY: process.env.GIGAI,
});

export async function POST(req: Request) {
  const { messages } = await req.json();

  const stream = await Giga.chat({
    model: "GigAI-v1",
    messages: messages,
    stream: true, // must be set to true, for hook useGigAI react...
  });
  return new Response(stream);
}

src/app/page.tsx

"use client";
import useGigaAI from "@/package/core/frontend/react";
// code from https://sdk.vercel.ai/docs/guides/providers/openai
// But using hook useGigaAI()
export default function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useGigaAI();
  return (
    <div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
      {messages.map((m) => (
        <div key={m.id} className="whitespace-pre-wrap">
          {m.role === "user" ? "User: " : "AI: "}
          {m.content}
        </div>
      ))}

      <form onSubmit={handleSubmit}>
        <input
          className="fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl"
          value={input}
          placeholder="Say something..."
          onChange={handleInputChange}
        />
      </form>
    </div>
  );
}

Supported AI Models

As of version 0.1, the following NLP models are supported:

  • GigAI-v1
  • GigAI-v1_5
  • Fake

Please ensure your application is configured to use one of these models for the chat functionalities.

Installation

To use useGigaAI, ensure that you have first cloned the GigaSoft AI package into your project. The hook is located at src/package/core/frontend/react.ts within the package structure.

Step 1: Import the Hook

In your React component file where you intend to use the chat functionality, import useGigaAI as follows:

import useGigaAI from "@/package/core/frontend/react";

Step 2: Initialization and Configuration

Initialize useGigaAI in your component to get access to its functionalities and states:

const { messages, input, handleInputChange, handleSubmit } = useGigaAI();

Usage

After importing and initializing the hook in your component, you can now make use of the provided states and functions to integrate a chat interface within your application.

Displaying Messages

The messages state holds an array of message objects that can be rendered in your UI. Each message object contains details such as the message content, sender role, and more.

Example of displaying messages:

<div className="chat-messages">
  {messages.map((m) => (
    <div key={m.id} className={`message ${m.role}`}>
      {m.role === "user" ? "User: " : "AI: "}
      {m.content}
    </div>
  ))}
</div>

Sending Messages

To send a message, use the input and handleInputChange to capture user input, and handleSubmit for processing and sending the message to the backend for a response.

Example of a message input form:

<form onSubmit={handleSubmit}>
  <input
    className="message-input"
    value={input}
    placeholder="Say something..."
    onChange={handleInputChange}
  />
</form>

Examples

Simple Chat Application

Here's a complete example of a simple chat application using the useGigaAI hook.

import React from "react";
import useGigaAI from "@/package/core/frontend/react";

function ChatApp() {
  const { messages, input, handleInputChange, handleSubmit } = useGigaAI();

  return (
    <div className="chat-container">
      <div className="messages">
        {messages.map((m) => (
          <div key={m.id} className={`message ${m.role}`}>
            {m.role === "user" ? "User: " : "AI: "}
            {m.content}
          </div>
        ))}
      </div>
      <form onSubmit={handleSubmit}>
        <input
          value={input}
          onChange={handleInputChange}
          placeholder="Type your message..."
        />
      </form>
    </div>
  );
}

export default ChatApp;

This example demonstrates the basic setup needed to implement a chat feature using useGigaAI.

Future Developments

The GigaAI Chat Hook is in its initial version (v0.1), and future updates will include support for additional models and functionalities. Feedback and contributions are welcome, as we aim to expand the capabilities of this hook to cater to various chat-interaction needs.

Stay tuned for updates and enhancements, including the introduction of the GigAI-OCR model in upcoming versions. Your feedback is valuable to us as we continue to develop and improve the GigaAI Chat Hook.

For more information or support, please visit our GitHub repository or contact our support team.