Convert Figma logo to code with AI

CopilotKit logoCopilotKit

React UI + elegant infrastructure for AI Copilots, in-app AI agents, AI chatbots, and AI-powered Textareas 🪁

14,149
2,142
14,149
114

Top Related Projects

Integrate cutting-edge LLM technology quickly and easily into your apps

98,623

🦜🔗 Build context-aware reasoning applications

Examples and guides for using the OpenAI API

The official Python library for the OpenAI API

Quick Overview

CopilotKit is an open-source SDK for building AI-powered applications. It provides developers with tools to create custom AI assistants and copilots, integrating seamlessly with large language models (LLMs) like GPT-4. CopilotKit aims to simplify the process of adding AI capabilities to applications, making it accessible for developers of various skill levels.

Pros

  • Easy integration with popular LLMs and AI services
  • Customizable and extensible for various use cases
  • Active development and community support
  • Supports both React and Next.js frameworks

Cons

  • Limited documentation for advanced use cases
  • Potential learning curve for developers new to AI integration
  • Dependency on third-party AI services and their limitations
  • May require additional configuration for complex applications

Code Examples

  1. Creating a basic AI assistant:
import { CopilotKit, CopilotTextarea } from "@copilotkit/react-core";

function App() {
  return (
    <CopilotKit>
      <CopilotTextarea
        placeholder="Ask me anything..."
        chatApiEndpoint="/api/chat"
      />
    </CopilotKit>
  );
}
  1. Customizing the AI assistant's behavior:
import { CopilotKit, CopilotTextarea } from "@copilotkit/react-core";

function App() {
  return (
    <CopilotKit
      initialMessages={[
        { role: "system", content: "You are a helpful assistant." },
      ]}
    >
      <CopilotTextarea
        placeholder="How can I help you today?"
        chatApiEndpoint="/api/chat"
        maxTokens={100}
        temperature={0.7}
      />
    </CopilotKit>
  );
}
  1. Implementing a chat interface:
import { CopilotKit, CopilotChat } from "@copilotkit/react-core";

function ChatApp() {
  return (
    <CopilotKit>
      <CopilotChat
        chatApiEndpoint="/api/chat"
        welcomeMessage="Hello! How can I assist you today?"
        messageStyles={{
          user: { backgroundColor: "#e6f3ff" },
          assistant: { backgroundColor: "#f0f0f0" },
        }}
      />
    </CopilotKit>
  );
}

Getting Started

To start using CopilotKit in your project:

  1. Install the package:

    npm install @copilotkit/react-core
    
  2. Import and use CopilotKit components in your React application:

    import { CopilotKit, CopilotTextarea } from "@copilotkit/react-core";
    
    function App() {
      return (
        <CopilotKit>
          <CopilotTextarea
            placeholder="Ask me anything..."
            chatApiEndpoint="/api/chat"
          />
        </CopilotKit>
      );
    }
    
    export default App;
    
  3. Set up your API endpoint to handle chat requests and integrate with your chosen LLM service.

Competitor Comparisons

Integrate cutting-edge LLM technology quickly and easily into your apps

Pros of Semantic Kernel

  • More comprehensive and feature-rich, offering a broader range of AI integration capabilities
  • Better documentation and community support, backed by Microsoft
  • Supports multiple programming languages, including C#, Python, and Java

Cons of Semantic Kernel

  • Steeper learning curve due to its more complex architecture
  • Heavier and potentially slower for simpler AI integration tasks
  • May be overkill for projects that only require basic AI-assisted features

Code Comparison

Semantic Kernel (C#):

var kernel = Kernel.Builder.Build();
var function = kernel.CreateSemanticFunction("Generate a story about {{$input}}");
var result = await kernel.RunAsync("a brave knight", function);

CopilotKit (JavaScript):

import { CopilotKit } from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";

<CopilotKit>
  <CopilotTextarea />
</CopilotKit>

The code snippets demonstrate that Semantic Kernel offers more flexibility in creating custom AI functions, while CopilotKit provides a simpler, React-based approach for integrating AI-assisted features into web applications.

98,623

🦜🔗 Build context-aware reasoning applications

Pros of Langchain

  • More comprehensive and flexible framework for building AI applications
  • Larger community and ecosystem with extensive documentation
  • Supports a wide range of language models and integrations

Cons of Langchain

  • Steeper learning curve due to its extensive features and abstractions
  • Can be overkill for simpler projects or specific use cases
  • Requires more setup and configuration compared to CopilotKit

Code Comparison

CopilotKit:

import { CopilotKit } from "copilotkit";

const copilot = new CopilotKit({
  apiKey: "your-api-key",
});

copilot.chat("Hello, how can I help you today?");

Langchain:

from langchain import OpenAI, LLMChain, PromptTemplate

llm = OpenAI(temperature=0.9)
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)
chain = LLMChain(llm=llm, prompt=prompt)

print(chain.run("colorful socks"))

CopilotKit focuses on providing a simple interface for AI-powered chat and code completion, while Langchain offers a more extensive toolkit for building complex AI applications with various components and integrations.

Examples and guides for using the OpenAI API

Pros of OpenAI Cookbook

  • Comprehensive collection of examples and best practices for using OpenAI's APIs
  • Regularly updated with new features and improvements from OpenAI
  • Covers a wide range of use cases and applications

Cons of OpenAI Cookbook

  • Focused solely on OpenAI's offerings, limiting its scope compared to CopilotKit
  • Less emphasis on integrating AI capabilities into existing applications
  • May require more setup and configuration for each example

Code Comparison

OpenAI Cookbook:

import openai

response = openai.Completion.create(
  engine="text-davinci-002",
  prompt="Translate the following English text to French: '{}'",
  max_tokens=60
)

CopilotKit:

import { CopilotKit } from "@copilotkit/react-core";

<CopilotKit>
  <YourApp />
</CopilotKit>

The OpenAI Cookbook provides direct API usage examples, while CopilotKit offers a more integrated approach for adding AI capabilities to React applications. OpenAI Cookbook is better suited for developers looking to work directly with OpenAI's APIs, whereas CopilotKit provides a higher-level abstraction for integrating AI features into existing projects.

The official Python library for the OpenAI API

Pros of openai-python

  • Comprehensive and official SDK for OpenAI's API
  • Well-documented with extensive examples and tutorials
  • Supports a wide range of OpenAI services and models

Cons of openai-python

  • Focused solely on OpenAI's services, limiting flexibility
  • Requires more setup and configuration for custom applications
  • May have a steeper learning curve for beginners

Code Comparison

openai-python:

import openai

openai.api_key = "your-api-key"
response = openai.Completion.create(
  engine="davinci", prompt="Hello, world!"
)

CopilotKit:

import { CopilotKit } from "copilot-kit";

const copilot = new CopilotKit({ apiKey: "your-api-key" });
const response = await copilot.complete("Hello, world!");

The openai-python library provides a more direct interface to OpenAI's services, while CopilotKit offers a simplified abstraction layer for AI-powered features. CopilotKit focuses on easy integration of AI capabilities into applications, whereas openai-python provides comprehensive access to OpenAI's API functionalities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CopilotKit Logo

Build deeply-integrated AI assistants & agents
that work alongside your users inside your applications.





214 (1)

Demos (click to clone / run)

📊 Spreadsheets + Copilot

Spreadsheet Demo

View Demo Repository →

A powerful spreadsheet assistant that helps users analyze data, create formulas, and generate insights through natural language interaction.

🏦 Banking Assistant (SaaS Copilot)

View Demo Repository →

An AI-powered banking interface that helps users manage transactions, analyze spending patterns, and get personalized financial advice.

✈️ [Tutorial] Agent-Native Travel Planner (ANA)

View Tutorial →

Interactive travel planning assistant that helps users discover destinations, create itineraries, and manage trip details with natural language.

🔍 [Tutorial] Agent-Native Research Canvas (ANA)

View Demo Repository →

An intelligent research assistant that helps users analyze academic papers, synthesize information across multiple sources, and generate comprehensive research summaries through natural language interaction.

Getting Started

Get started in minutes - check out the quickstart documentation.

Code Samples

// Headless UI with full control
const { visibleMessages, appendMessage, setMessages, ... } = useCopilotChat();

// Pre-built components with deep customization options (CSS + pass custom sub-components)
<CopilotPopup 
  instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."} 
  labels={{ title: "Popup Assistant", initial: "Need any help?" }} 
/>

// ---

// Frontend RAG
useCopilotReadable({
  description: "The current user's colleagues",
  value: colleagues,
});

// knowledge-base integration
useCopilotKnowledgebase(myCustomKnowledgeBase)

// ---

// Frontend actions + generative UI, with full streaming support
useCopilotAction({
  name: "appendToSpreadsheet",
  description: "Append rows to the current spreadsheet",
  parameters: [
    { name: "rows", type: "object[]", attributes: [{ name: "cells", type: "object[]", attributes: [{ name: "value", type: "string" }] }] }
  ],
  render: ({ status, args }) => <Spreadsheet data={canonicalSpreadsheetData(args.rows)} />,
  handler: ({ rows }) => setSpreadsheet({ ...spreadsheet, rows: [...spreadsheet.rows, ...canonicalSpreadsheetData(rows)] }),
});

// ---

// structured autocomplete for anything
const { suggestions } = useCopilotStructuredAutocompletion(
  {
    instructions: `Autocomplete or modify spreadsheet rows based on the inferred user intent.`,
    value: { rows: spreadsheet.rows.map((row) => ({ cells: row })) },
    enabled: !!activeCell && !spreadsheetIsEmpty,
  },
  [activeCell, spreadsheet]
);

Code Samples (CoAgents: in-app LangGraph Agents)

// Share state between app and agent
const { agentState } = useCoAgent({ 
  name: "basic_agent", 
  initialState: { input: "NYC" } 
});

// agentic generative UI
useCoAgentStateRender({
  name: "basic_agent",
  render: ({ state }) => <WeatherDisplay {...state.final_response} />,
});

// Human in the Loop (Approval)
useCopilotAction({
    name: "email_tool",
    parameters: [{ name: "email_draft", type: "string", description: "The email content", required: true }],
    renderAndWaitForResponse: ({ args, status, respond }) => (
      <EmailConfirmation
        emailContent={args.email_draft || ""}
        isExecuting={status === "executing"}
        onCancel={() => respond?.({ approved: false })}
        onSend={() => respond?.({ approved: true, metadata: { sentAt: new Date().toISOString() } })}
      />
    ),
  });

// ---

// intermediate agent state streaming (supports both LangGraph.js + LangGraph python)
const modifiedConfig = copilotKitCustomizeConfig(config, {
  emitIntermediateState: [{ 
    stateKey: "outline", 
    tool: "set_outline", 
    toolArgument: "outline" 
  }],
});
const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(messages, modifiedConfig);

Contributing

Thanks for your interest in contributing to CopilotKit! 💜

We value all contributions, whether it's through code, documentation, creating demo apps, or just spreading the word.

Here are a few useful resources to help you get started:

💡 NOTE: All contributions must be submitted via a pull request and be reviewed by our team. This ensures all contributions are of high quality and align with the project's goals.

Get in touch

You are invited to join our community on Discord and chat with our team and other community members.

License

This repository's source code is available under the MIT License.

NPM DownloadsLast 30 Days