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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-react-hooks

v1.0.9

Published

A powerful collection of React hooks for AI models including ChatGPT, Ollama, Groq, DeepSeek, Anthropic, Google Gemini, and more.

Readme

ai-react-hooks 🤖

npm version

npm downloads

bundle size

license

TypeScript

A collection of React hooks for seamless AI integration across multiple providers


✨ Features

  • Unified API: Single hook (useAI) for all providers

  • Multi-Provider: OpenAI, Anthropic, Google Gemini, Ollama, Groq, DeepSeek

  • Feature-Rich: Chat, image generation, speech-to-text, summarization

  • TypeScript: Full type safety and IntelliSense support

  • Lightweight: Zero dependencies, tree-shakeable

  • React 18+: Built for modern React applications

📦 Installation

Install using your preferred package manager.

npm

npm  install  ai-react-hooks

yarn

yarn  add  ai-react-hooks

pnpm

pnpm  add  ai-react-hooks

🚀 Quick Start

Basic Usage


import { useAI } from  "ai-react-hooks";

function  ChatComponent() {

const { ask, response, loading, error } = useAI({

provider:  "openai", // "ollama", "groq", "deepseek", etc.

apiKey:  process.env.OPENAI_API_KEY,

model:  "gpt-4o-mini",
});


const  handleClick = () => {

ask("Explain quantum computing in simple terms");

};

return (

<div>

<button  onClick={handleClick}  disabled={loading}>

{loading ? "Thinking..." : "Ask AI"}

</button>

{response && <p>{response}</p>}

  

{error && <p  className="error">Error: {error.message}</p>}

  

</div>


);

  

}

🎯 Available Hooks

Hook | Provider | Description ---- | -------- | ----------- useAI | All Providers | Unified hook for any AI provider useChatGPT | OpenAI | GPT-4, GPT-4o, GPT-3.5 useAnthropic | Anthropic | Claude 3, Claude Instant useGoogleGemini | Google | Gemini Pro, Gemini Flash useOllama | Ollama | Local models (Llama, Mistral) useGroq | Groq | Ultra-fast LLM inference useDeepSeek | DeepSeek | DeepSeek models useSummarize | Text Processing | Text summarization useAiImageGenerator | Image Generation | DALL·E, Stable Diffusion useSpeechToText | Browser API | Web Speech API integration

📖 Examples

1. Chat with OpenAI


import { useChatGPT } from  "ai-react-hooks";

function  OpenAIChat() {

const { ask, response, loading } = useChatGPT({

apiKey:  "your-openai-key",

model:  "gpt-4",

temperature:  0.7,
});

return (

<div>

<button  onClick={() =>  ask("Write a poem about React hooks")}>

Generate Poem

</button>

{loading && <span>Thinking...</span>}

{response && <p>{response}</p>}

</div>

);

}

2. Image Generation


import { useAiImageGenerator } from  "ai-react-hooks";

function  ImageGenerator() {
const { generate, imageUrl, loading } = useAiImageGenerator({

provider:  "openai",

apiKey:  process.env.OPENAI_API_KEY,

size:  "1024x1024",

});
return (

<div>

<input

placeholder="Describe an image..."

onKeyPress={(e) =>  e.key === 'Enter' && generate(e.target.value)}
/>

{loading && <p>Generating...</p>}

{imageUrl && <img  src={imageUrl}  alt="Generated"  />}

</div>

)

3. Speech to Text

import { useSpeechToText } from  "ai-react-hooks";

function  VoiceInput() {

const { start, stop, text, listening } = useSpeechToText({

continuous:  true,

language:  "en-US",


});

return (

<div>

<button  onClick={listening ? stop : start}>

{listening ? "Stop Recording" : "Start Recording"}

</button>

<p>{text || "Speak to see transcription..."}</p>

</div>

);

}

🔧 Configuration

Environment Setup

.env.local

OPENAI_API_KEY=sk-...

ANTHROPIC_API_KEY=sk-ant-...

GOOGLE_AI_API_KEY=AIza...

Provider Configuration


// OpenAI

const  openAI = useChatGPT({

apiKey:  "your-key",

model:  "gpt-4",

temperature:  0.7,
maxTokens:  1000,

});


// Anthropic

  

const  anthropic = useAnthropic({

apiKey:  "your-key",

model:  "claude-3-opus-20240229",

maxTokens:  1000,

});


// Ollama (Local)

  

const  ollama = useOllama({

baseUrl:  "http://localhost:11434",

model:  "llama2",

});

  

📚 API Reference

Common Props

Prop | Type | Description ---- | ---- | ----------- apiKey | string | Provider API key model | string | Model identifier temperature | number | Creativity level (0–1) maxTokens | number | Maximum response length

Hook Return Values

All hooks return an object with:

Property | Type | Description -------- | ---- | ----------- ask / generate | Function | Trigger AI request response | string | null | AI response loading | boolean | Request in progress error | Error | null | Error information reset | Function | Reset hook state


🤝 Contributing

Contributions are welcome! Please read the Contributing Guide for details.

Steps to contribute:

  • Fork the repository

  • Create a feature branch

  • Commit your changes

  • Push to your branch

  • Open a Pull Request

🐛 Troubleshooting

CORS Issues with Ollama

Start Ollama with CORS enabled:

ollama serve --cors "*"

API Key Security

Always use environment variables for API keys:

import { useChatGPT } from 'your-package-name';

const { ask } = useChatGPT({
  apiKey: process.env.OPENAI_API_KEY, // ✅ Secure
  // apiKey: "sk-..." // ❌ Do not hardcode
});

📄 License

MIT © Yared Abebe