chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:58:18 +08:00
commit 6d5d58c1a9
18293 changed files with 3502153 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "object",
parameters: [
{
name: "arg",
type: "object[]",
description: "The object argument to display.",
attributes: [
{
name: "x",
type: "string",
description: "The x attribute.",
},
{
name: "y",
type: "number",
description: "The y attribute.",
},
],
},
],
handler: async ({ arg }) => {
const x: string = arg[0].x;
const y: number = arg[0].y;
const z: boolean = arg[0].z;
},
});
+26
View File
@@ -0,0 +1,26 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "enum",
parameters: [
{
name: "arg",
type: "string",
description: "The enum to display.",
enum: ["one", "two", "three"],
},
],
handler: async ({ arg }) => {
switch (arg) {
case "one":
console.log("One");
break;
case "two":
console.log("Two");
break;
default:
const exhaustiveCheck: never = arg;
}
console.log("No args action");
},
});
+8
View File
@@ -0,0 +1,8 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "noargs",
handler: async (args) => {
console.log("No args action");
},
});
+29
View File
@@ -0,0 +1,29 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "object",
parameters: [
{
name: "arg",
type: "object",
description: "The object argument to display.",
attributes: [
{
name: "x",
type: "string",
description: "The x attribute.",
},
{
name: "y",
type: "number",
description: "The y attribute.",
},
],
},
],
handler: async ({ arg }) => {
const x: string = arg.x;
const y: number = arg.y;
const z: boolean = arg.z;
},
});
+17
View File
@@ -0,0 +1,17 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "optional",
parameters: [
{
name: "arg",
type: "string",
description: "The optional argument to display.",
required: false,
},
],
handler: async ({ arg }) => {
// TODO this should fail
let x: string = arg;
},
});
+28
View File
@@ -0,0 +1,28 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "array",
parameters: [
{
name: "arg",
type: "object[]",
description: "The object argument to display.",
attributes: [
{
name: "x",
type: "string",
description: "The x attribute.",
},
{
name: "y",
type: "number",
description: "The y attribute.",
},
],
},
],
handler: async ({ arg }) => {
const x: string = arg[0].x;
const y: number = arg[0].y;
},
});
+29
View File
@@ -0,0 +1,29 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "enum",
parameters: [
{
name: "arg",
type: "string",
description: "The enum to display.",
enum: ["one", "two", "three"],
},
],
handler: async ({ arg }) => {
switch (arg) {
case "one":
console.log("One");
break;
case "two":
console.log("Two");
break;
case "three":
console.log("Three");
break;
default:
const exhaustiveCheck: never = arg;
}
console.log("No args action");
},
});
+8
View File
@@ -0,0 +1,8 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "noargs",
handler: async () => {
console.log("No args action");
},
});
+28
View File
@@ -0,0 +1,28 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "object",
parameters: [
{
name: "arg",
type: "object",
description: "The object argument to display.",
attributes: [
{
name: "x",
type: "string",
description: "The x attribute.",
},
{
name: "y",
type: "number",
description: "The y attribute.",
},
],
},
],
handler: async ({ arg }) => {
const x: string = arg.x;
const y: number = arg.y;
},
});
+20
View File
@@ -0,0 +1,20 @@
import { useCopilotAction } from "@copilotkit/react-core";
useCopilotAction({
name: "optional",
parameters: [
{
name: "arg",
type: "string",
description: "The optional argument to display.",
required: false,
},
],
handler: async ({ arg }) => {
let x: string = "y";
if (arg !== undefined) {
x = arg;
}
},
});
+95
View File
@@ -0,0 +1,95 @@
#!/bin/bash
get_latest_versions() {
local result="" # Initialize an empty string to hold the results
for pkg in "$@"; do
# Encode the package name for use in a URL
encoded_pkg=$(echo "$pkg" | sed 's|/|%2F|g')
# Fetch the latest version of the package
latest_version=$(curl -s "https://registry.npmjs.org/$encoded_pkg" | jq -r '.["dist-tags"].latest')
# Check if the latest version was found
if [[ $latest_version != "null" && ! -z $latest_version ]]; then
# Append the package and version to the result string, separated by '@' and spaces between packages
result+="${pkg}@${latest_version} "
else
echo "Latest version for package ${pkg} could not be found." >&2
return 1 # Optionally return an error code if a package's latest version can't be found
fi
done
# Trim the trailing space and print the result
echo "${result% }"
}
get_latest_copilotkit_versions() {
get_latest_versions "@copilotkit/backend" "@copilotkit/react-core" "@copilotkit/react-textarea" "@copilotkit/react-ui" "@copilotkit/shared"
}
get_latest_prerelease_versions() {
local result="" # Initialize an empty string to hold the results
local tag_part="$1" # The specific part of the tag to match
# Shift the arguments so $@ contains the packages
shift
for pkg in "$@"; do
# Encode the package name for use in a URL
encoded_pkg=$(echo "$pkg" | sed 's|/|%2F|g')
# Fetch the list of all versions
versions=$(curl -s "https://registry.npmjs.org/$encoded_pkg" | jq -r '.versions | keys[]')
# Filter versions that match the tag part and get the last one
latest_prerelease_version=$(echo "$versions" | grep "$tag_part" | tail -n 1)
# Check if a version was found
if [[ ! -z $latest_prerelease_version ]]; then
# Append the package and version to the result string, separated by '@' and spaces between packages
result+="${pkg}@${latest_prerelease_version} "
else
echo "Latest pre-release version matching '$tag_part' for package ${pkg} could not be found." >&2
fi
done
# Trim the trailing space and print the result
echo "${result% }"
}
get_latest_copilotkit_prerelase_versions() {
get_latest_prerelease_versions $1 "@copilotkit/runtime" "@copilotkit/react-core" "@copilotkit/react-textarea" "@copilotkit/react-ui" "@copilotkit/shared"
}
use_local_packages() {
echo "Building local packages..."
pnpm -w freshbuild
echo "Done building local packages."
packages="file:$(pwd)/packages/runtime file:$(pwd)/packages/react-core file:$(pwd)/packages/react-textarea file:$(pwd)/packages/react-ui file:$(pwd)/packages/shared"
}
yarn_install_packages() {
local app_path="$1"
if [ -z "$packages" ]; then
use_local_packages;
fi
(cd "$app_path" && yarn add $packages)
info "Package manager: yarn"
info "Using CopilotKit packages: $packages"
}
npm_install_packages() {
local app_path="$1"
if [ -z "$packages" ]; then
use_local_packages;
fi
(cd "$app_path" && npm install $packages --save)
info "Package manager: npm"
info "Using CopilotKit packages: $packages"
}
+61
View File
@@ -0,0 +1,61 @@
source scripts/qa/lib/bash/qa.sh
source scripts/qa/lib/bash/packages.sh
prerelease_tag="$1"
packages=""
if [ -n "$prerelease_tag" ]; then
echo "Fetching pre-release CopilotKit packages..."
packages=$(get_latest_copilotkit_prerelase_versions "$prerelease_tag")
echo "Pre-release CopilotKit packages: $packages"
fi
if [ -z "$packages" ]; then
echo "No pre-release CopilotKit packages provided."
read -p "Enter package names separated by space or Enter to install local packages: " packages
fi
if [ -z "$packages" ]; then
echo "Installing local packages..."
else
echo "Installing packages: $packages"
fi
# only prompt for openai key if it is not set already
if [ -z "$OPENAI_API_KEY" ]; then
read -p "Enter OpenAI API key: " OPENAI_API_KEY
else
# Extract the first 5 characters of the API key
key_start=${OPENAI_API_KEY:0:5}
# Calculate the number of asterisks to print based on the key length
num_asterisks=$((${#OPENAI_API_KEY}-5))
asterisks=$(printf '%*s' "$num_asterisks" '' | tr ' ' '*')
echo "Using existing OPENAI_API_KEY: $key_start$asterisks"
fi
pid1=0
pid2=0
pid3=0
cleanup() {
if [ $pid1 -ne 0 ]; then
kill -9 $pid1 2>/dev/null || true
fi
if [ $pid2 -ne 0 ]; then
kill -9 $pid2 2>/dev/null || true
fi
if [ $pid3 -ne 0 ]; then
kill -9 $pid3 2>/dev/null || true
fi
killall next-server 2>/dev/null || true
}
# Trap Ctrl+C (INT signal) and exit
trap "echo 'Script interrupted.'; cleanup; exit" INT
trap "cleanup" EXIT
# Exit on any error
set -e
# record the current date + time
info "Test started at $(date)"
+47
View File
@@ -0,0 +1,47 @@
#!/bin/bash
# Get the current date in YYYY-MM-DD format
current_date=$(date +%Y-%m-%d)
# Define the file path with the current date
file_path="/tmp/qa-${current_date}.txt"
prompt() {
local prompt="$1"
local user_input
while true; do
# Display the prompt to the user and read a single character input
read -p "$prompt (y/n): " -n 1 user_input
echo # Move to a new line
# Check the user input and append the prompt to the file with the appropriate emoji
if [[ $user_input == "y" ]]; then
echo -e "$prompt" >> "$file_path" # Green checkmark emoji
break
elif [[ $user_input == "n" ]]; then
echo -e "$prompt" >> "$file_path" # Red X emoji
break
else
echo "Invalid input. Please enter 'y' or 'n'."
fi
done
}
info() {
local info_msg="$1"
# Append the string to the file with the information emoji
echo -e "📢 $info_msg" >> "$file_path"
}
fail() {
local fail_msg="$1"
# Append the string to the file with the information emoji
echo -e "$fail_msg" >> "$file_path"
}
succeed() {
local success_msg="$1"
# Append the string to the file with the information emoji
echo -e "$success_msg" >> "$file_path"
}
+78
View File
@@ -0,0 +1,78 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotKitCSSProperties, CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<div
style={
{
height: `100vh`,
"--copilot-kit-primary-color": "red",
} as CopilotKitCSSProperties
}
>
<CopilotKit url="/api/copilotkit/openai">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
icons={{
sendIcon: "📩",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
</div>
);
}
+6
View File
@@ -0,0 +1,6 @@
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
export async function POST(req: Request): Promise<Response> {
const copilotKit = new CopilotRuntime();
return copilotKit.response(req, new OpenAIAdapter({}));
}
+5
View File
@@ -0,0 +1,5 @@
{
"projects": {
"default": "copilotkit-test-12345"
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"emulators": {
"functions": {
"port": 5001
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}
+20
View File
@@ -0,0 +1,20 @@
/**
* Import function triggers from their respective submodules:
*
* import {onCall} from "firebase-functions/v2/https";
* import {onDocumentWritten} from "firebase-functions/v2/firestore";
*
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/
import { onRequest } from "firebase-functions/v2/https";
// import * as logger from "firebase-functions/logger";
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
// Start writing functions
// https://firebase.google.com/docs/functions/typescript
export const copilotKit = onRequest((request, response) => {
const copilotKit = new CopilotRuntime();
copilotKit.streamHttpServerResponse(request, response, new OpenAIAdapter({}));
});
+31
View File
@@ -0,0 +1,31 @@
{
"name": "functions",
"private": true,
"main": "lib/index.js",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"@copilotkit/backend": "^0.7.0-mme-firebase-fixes.0",
"@copilotkit/react-core": "^0.23.0-mme-firebase-fixes.0",
"@copilotkit/react-textarea": "^0.33.0-mme-firebase-fixes.0",
"@copilotkit/react-ui": "^0.20.0-mme-firebase-fixes.0",
"@copilotkit/shared": "^0.7.0-mme-firebase-fixes.0",
"firebase-admin": "^12.0.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0",
"firebase-tools": "^13.6.0",
"typescript": "^5.4.3"
},
"engines": {
"node": "18"
}
}
+59
View File
@@ -0,0 +1,59 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<div className="h-screen w-full flex items-center justify-center text-2xl">
{message}
</div>
);
}
export default function Home() {
return (
<CopilotKit url="http://127.0.0.1:5001/copilotkit-test-12345/us-central1/copilotKit">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
clickOutsideToClose={false}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+13
View File
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": ["src"]
}
+74
View File
@@ -0,0 +1,74 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
{/* <CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/> */}
</>
);
}
export default function Home() {
return (
<CopilotKit url="/api/copilotkit/langchain">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+43
View File
@@ -0,0 +1,43 @@
import {
CopilotRuntime,
LangChainAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { ChatOpenAI } from "@langchain/openai";
const runtime = new CopilotRuntime({
actions: [
{
name: "sayHello",
description: "Says hello to someone.",
parameters: [
{
name: "arg",
type: "string",
description: "The name of the person to say hello to.",
required: true,
},
],
handler: async ({ arg }) => {
console.log("Hello from the server", arg, "!");
},
},
],
});
const serviceAdapter = new LangChainAdapter({
chainFn: async ({ messages, tools }) => {
const model = new ChatOpenAI({ modelName: "gpt-4-1106-preview" }).bind(
tools as any,
);
return model.stream(messages);
},
});
export const { GET, POST, OPTIONS } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit/langchain",
debug: true,
}) as any;
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env python
"""Example LangChain server exposes multiple runnables (LLMs in this case)."""
from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI
from langchain.chat_models import ChatOpenAI
from langchain.vectorstores import FAISS
from langchain.embeddings import OpenAIEmbeddings
from langchain.agents import AgentExecutor, tool
from langchain.tools.render import format_tool_to_openai_function
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
from langchain.pydantic_v1 import BaseModel
from typing import Any
from langchain.agents.format_scratchpad import format_to_openai_functions
from langserve import add_routes
app = FastAPI(
title="LangChain Server",
version="1.0",
description="Spin up a simple api server using Langchain's Runnable interfaces",
)
# ChatOpenAI
# ----------
# We probably can't support ChatOpenAI...
# see input schema: http://localhost:8000/openai/input_schema
# also playground: http://localhost:8000/openai/playground/
# it looks tricky to support this in a generic way
add_routes(
app,
ChatOpenAI(),
path="/openai",
)
# Retriever
# ---------
# receives a single input VectorStoreRetrieverInput (type string)
# Input Schema: {"title":"VectorStoreRetrieverInput","type":"string"}
# according to the client docs, it can be called like this:
# - requests.post("http://localhost:8000/invoke", json={"input": "tree"})
# - remote_runnable.invoke("tree")
vectorstore = FAISS.from_texts(
["cats like fish", "dogs like sticks"], embedding=OpenAIEmbeddings()
)
retriever = vectorstore.as_retriever()
add_routes(
app,
retriever,
path="/retriever",
)
# Agent
# -----
# Input Schema: {"title":"Input","type":"object","properties":{"input":{"title":"Input","type":"string"}},"required":["input"]}
# - requests.post("http://localhost:8000/invoke", json={"input": {"input": "what does eugene think of cats?"}})
# - remote_runnable.invoke({"input": "what does eugene think of cats?"})
@tool
def get_eugene_thoughts(query: str) -> list:
"""Returns Eugene's thoughts on a topic."""
return retriever.get_relevant_documents(query)
tools = [get_eugene_thoughts]
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0, streaming=True)
llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant."),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
agent = (
{
"input": lambda x: x["input"],
"agent_scratchpad": lambda x: format_to_openai_functions(
x["intermediate_steps"]
),
}
| prompt
| llm_with_tools
| OpenAIFunctionsAgentOutputParser()
)
agent_executor = AgentExecutor(graph=agent, tools=tools)
class Input(BaseModel):
input: str
class Output(BaseModel):
output: Any
add_routes(
app,
agent_executor.with_types(input_type=Input, output_type=Output).with_config(
{"run_name": "agent"}
),
path="/agent",
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="localhost", port=8000)
+74
View File
@@ -0,0 +1,74 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
{/* <CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/> */}
</>
);
}
export default function Home() {
return (
<CopilotKit url="/api/copilotkit/openai">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+87
View File
@@ -0,0 +1,87 @@
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";
const runtime = new CopilotRuntime({
actions: [
{
name: "sayHello",
description: "Says hello to someone.",
parameters: [
{
name: "name",
type: "string",
description: "The name of the person to say hello to.",
required: true,
},
],
handler: async ({ name }) => {
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
"The user tells you their name. Say hello to the person in the most " +
" ridiculous way, roasting their name.",
],
["user", "My name is {name}"],
]);
const chain = prompt.pipe(new ChatOpenAI());
return chain.invoke({
name: name,
});
},
},
{
name: "sayGoodbye",
description: "Says goodbye to someone.",
parameters: [
{
name: "name",
type: "string",
description: "The name of the person to say goodbye to.",
required: true,
},
],
handler: async ({ name }) => {
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
"The user tells you their name. Say goodbye to the person in the most " +
" ridiculous way, roasting their name.",
],
["user", "My name is {name}"],
]);
const chain = prompt.pipe(new ChatOpenAI());
return chain.stream({
name: name,
});
},
},
],
langserve: [
{
chainUrl: "http://localhost:8000/retriever",
name: "askAboutAnimals",
description:
"Always call this function if the users asks about a certain animal.",
},
{
chainUrl: "http://localhost:8000/agent",
name: "askAboutEugeneThoughts",
description:
"Always call this function if the users asks about Eugene's thoughts on a certain topic.",
},
],
});
const serviceAdapter = new OpenAIAdapter();
export const { GET, POST, OPTIONS } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit/openai",
debug: true,
}) as any;
@@ -0,0 +1,8 @@
python-dotenv
fastapi
langserve
langchain
langchain-cli
langchain-community
langchain-core
langchain-openai
+27
View File
@@ -0,0 +1,27 @@
/**
* @filePath pages/api/copilotkit.ts
*/
import { NextApiRequest, NextApiResponse } from "next";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSPagesRouterEndpoint,
} from "@copilotkit/runtime";
import OpenAI from "openai";
const openai = new OpenAI();
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const handleRequest = copilotRuntimeNextJSPagesRouterEndpoint({
endpoint: "/api/copilotkit",
runtime,
serviceAdapter,
});
return await handleRequest(req, res);
};
export default handler;
+64
View File
@@ -0,0 +1,64 @@
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit runtimeUrl="/api/copilotkit">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+74
View File
@@ -0,0 +1,74 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Home() {
return (
<CopilotKit url="/api/copilotkit/openai">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+25
View File
@@ -0,0 +1,25 @@
/**
* @filePath app/copilotkit/route.ts
*/
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { NextRequest } from "next/server";
import OpenAI from "openai";
const openai = new OpenAI();
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: req.nextUrl.pathname,
});
return handleRequest(req);
};
+29
View File
@@ -0,0 +1,29 @@
/**
* @filePath server.ts
*/
import express from "express";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";
import OpenAI from "openai";
const openai = new OpenAI();
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();
const copilotRuntime = copilotRuntimeNodeHttpEndpoint({
endpoint: "/copilotkit",
runtime,
serviceAdapter,
});
const app = express();
app.use("/copilotkit", copilotRuntime);
app.listen(4000, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});
+58
View File
@@ -0,0 +1,58 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit url="http://localhost:4000">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @filePath server.ts
*/
import { createServer } from "node:http";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";
import OpenAI from "openai";
const openai = new OpenAI();
const serviceAdapter = new OpenAIAdapter({ openai });
const runtime = new CopilotRuntime();
const copilotRuntime = copilotRuntimeNodeHttpEndpoint({
endpoint: "/copilotkit",
runtime,
serviceAdapter,
});
const server = createServer((req, res) => {
return copilotRuntime(req, res);
});
server.listen(4000, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});
+82
View File
@@ -0,0 +1,82 @@
import type { MetaFunction } from "@remix-run/node";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
export const meta: MetaFunction = () => {
return [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];
};
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
render: (props) => {
return (
<div style={{ backgroundColor: "black", color: "white" }}>
<div>Status: {props.status}</div>
<div>Message: {props.args.message}</div>
</div>
);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Index() {
return (
<CopilotKit runtimeUrl="/copilotkit">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+11
View File
@@ -0,0 +1,11 @@
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
import type { ActionFunctionArgs } from "@remix-run/node";
export async function action({ request }: ActionFunctionArgs) {
if (request.method !== "POST") {
return new Response("Method Not Allowed", { status: 405 });
}
const copilotKit = new CopilotRuntime();
return copilotKit.response(request, new OpenAIAdapter({}));
}
@@ -0,0 +1,58 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit url="http://localhost:4000" properties={{ userId: "xyz" }}>
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,34 @@
import express from "express";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";
const port = 4000;
var HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers": "X-Requested-With,content-type",
};
const handler = copilotRuntimeNodeHttpEndpoint({
endpoint: "/",
runtime: new CopilotRuntime(),
serviceAdapter: new OpenAIAdapter(),
});
const app = express();
app.use("/", (req, res, next) => {
if (req.method === "OPTIONS") {
res.writeHead(200, HEADERS);
res.end();
return;
}
return handler(req, res, next);
});
app.listen(port, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});
@@ -0,0 +1,58 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit url="http://localhost:4000">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,25 @@
import express from "express";
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/backend";
const port = 4000;
var HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers": "X-Requested-With,content-type",
};
const app = express();
app.use("/", (req, res, next) => {
if (req.method === "OPTIONS") {
res.writeHead(200, HEADERS);
res.end();
return;
}
var copilotKit = new CopilotRuntime();
copilotKit.streamHttpServerResponse(req, res, new OpenAIAdapter(), HEADERS);
});
app.listen(port, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});
@@ -0,0 +1,69 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Home() {
return (
<CopilotKit
runtimeUrl="/api/copilotkit/openai"
properties={{ userid: "abc_123" }}
>
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,36 @@
import { NextRequest } from "next/server";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
const runtime = new CopilotRuntime({
actions: [
{
name: "sayHello",
description: "say hello so someone by roasting their name",
parameters: [
{
name: "roast",
description: "A sentence or two roasting the name of the person",
type: "string",
required: true,
},
],
handler: ({ roast }) => {
console.log(roast);
},
},
],
});
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter: new OpenAIAdapter(),
endpoint: req.nextUrl.pathname,
});
return handleRequest(req);
};
@@ -0,0 +1,66 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Home() {
return (
<CopilotKit runtimeUrl="/api/copilotkit/openai">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,26 @@
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/backend";
export async function POST(req: Request): Promise<Response> {
const copilotKit = new CopilotRuntime({
actions: [
{
name: "research",
description:
"Call this function to conduct research on a certain topic. Respect other notes about when to call this function",
parameters: [
{
name: "topic",
type: "string",
description: "The topic to research. 5 characters or longer.",
required: true,
},
],
handler: async ({ topic }) => {
console.log("Researching topic: ", topic);
return "The secret is xyz";
},
},
],
});
return copilotKit.response(req, new OpenAIAdapter({}));
}
@@ -0,0 +1,69 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Home() {
return (
<CopilotKit
runtimeUrl="/api/copilotkit/openai"
properties={{ userid: "abc_123" }}
>
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,48 @@
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNextJSPagesRouterEndpoint,
} from "@copilotkit/runtime";
import { NextApiRequest, NextApiResponse } from "next";
const serviceAdapter = new OpenAIAdapter();
const runtime = new CopilotRuntime({
actions: [
{
name: "sayHello",
description: "say hello so someone by roasting their name",
parameters: [
{
name: "roast",
description: "A sentence or two roasting the name of the person",
type: "string",
required: true,
},
],
handler: ({ roast }) => {
console.log(roast);
return "The person has been roasted.";
},
},
],
});
// This is required for file upload to work
export const config = {
api: {
bodyParser: false,
},
};
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const handleRequest = copilotRuntimeNextJSPagesRouterEndpoint({
endpoint: "/api/copilotkit",
runtime,
serviceAdapter,
});
return await handleRequest(req, res);
};
export default handler;
@@ -0,0 +1,66 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
<CopilotTextarea
value={text}
onChange={(e) => setText(e.target.value)}
autosuggestionsConfig={{
textareaPurpose: "an outline of a presentation about elephants",
chatApiConfigs: {},
}}
/>
</>
);
}
export default function Home() {
return (
<CopilotKit runtimeUrl="/api/copilotkit/openai">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
@@ -0,0 +1,12 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/backend";
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const copilotKit = new CopilotRuntime({});
copilotKit.streamHttpServerResponse(
req,
res,
new OpenAIAdapter({ model: "gpt-4o" }),
);
}
+58
View File
@@ -0,0 +1,58 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit url="http://localhost:4000" properties={{ userId: "xyz" }}>
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+33
View File
@@ -0,0 +1,33 @@
import * as http from "http";
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";
const port = 4000;
var HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers": "X-Requested-With,content-type",
};
const handler = copilotRuntimeNodeHttpEndpoint({
endpoint: "/",
runtime: new CopilotRuntime(),
serviceAdapter: new OpenAIAdapter(),
});
var server = http.createServer(function (req, res) {
// Respond to OPTIONS (preflight) request
if (req.method === "OPTIONS") {
res.writeHead(200, HEADERS);
res.end();
return;
}
return handler(req, res);
});
server.listen(port, function () {
console.log(`Server running at http://localhost:${port}`);
});
+58
View File
@@ -0,0 +1,58 @@
"use client";
import {
CopilotKit,
useCopilotAction,
useCopilotReadable,
} from "@copilotkit/react-core";
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { CopilotSidebar } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
import { useState } from "react";
import "@copilotkit/react-textarea/styles.css";
import "@copilotkit/react-ui/styles.css";
function InsideHome() {
const [message, setMessage] = useState("Hello World!");
const [text, setText] = useState("");
useCopilotReadable({
description: "This is the current message",
value: message,
});
useCopilotAction(
{
name: "displayMessage",
description: "Display a message.",
parameters: [
{
name: "message",
type: "string",
description: "The message to display.",
required: true,
},
],
handler: async ({ message }) => {
setMessage(message);
},
},
[],
);
return (
<>
<div>{message}</div>
</>
);
}
export default function Home() {
return (
<CopilotKit url="http://localhost:4000">
<CopilotSidebar
defaultOpen={true}
labels={{
title: "Presentation Copilot",
initial: "Hi you! 👋 I can give you a presentation on any topic.",
}}
>
<InsideHome />
</CopilotSidebar>
</CopilotKit>
);
}
+22
View File
@@ -0,0 +1,22 @@
import * as http from "http";
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/backend";
const port = 4000;
var HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers": "X-Requested-With,content-type",
};
var server = http.createServer(function (req, res) {
// Respond to OPTIONS (preflight) request
if (req.method === "OPTIONS") {
res.writeHead(200, HEADERS);
res.end();
return;
}
var copilotKit = new CopilotRuntime();
copilotKit.streamHttpServerResponse(req, res, new OpenAIAdapter(), HEADERS);
});
server.listen(port, function () {
console.log(`Server running at http://localhost:${port}`);
});