| title | <CopilotTextarea /> |
|---|---|
| description | A context-aware, auto-completing textarea. |
{/* GENERATE-DOCS path=packages/react-textarea/src/components/copilot-textarea/copilot-textarea.tsx component=CopilotTextarea */}
```jsx CopilotTextarea Example ```<CopilotTextarea> is a React component that acts as a drop-in replacement for the standard <textarea>,
offering enhanced autocomplete features powered by AI. It is context-aware, integrating seamlessly with the
useCopilotReadable() hook to provide intelligent suggestions based on the application context.
In addition, it provides a hovering editor window (available by default via Cmd+k) that allows the user to
suggest changes to the text, for example providing a summary or rephrasing the text.
Install the CopilotTextarea frontend packagess:
```bash npm npm i @copilotkit/react-core @copilotkit/react-textarea ``` yarn add @copilotkit/react-core @copilotkit/react-textarea pnpm add @copilotkit/react-core @copilotkit/react-textareaUse the CopilotTextarea component in your React application similarly to a standard <textarea />,
with additional configurations for AI-powered features.
For example:
import { CopilotTextarea } from "@copilotkit/react-textarea";
import { useState } from "react";
export function ExampleComponent() {
const [text, setText] = useState("");
return (
<CopilotTextarea
className="custom-textarea-class"
value={text}
onValueChange={(value: string) => setText(value)}
placeholder="Enter your text here..."
autosuggestionsConfig={{
textareaPurpose: "Provide context or purpose of the textarea.",
chatApiConfigs: {
suggestionsApiConfig: {
forwardedParams: {
max_tokens: 20,
stop: [".", "?", "!"],
},
},
},
}}
/>
);
}Autosuggestions can be configured as follows:
{
// the purpose of the textarea
textareaPurpose: string,
chatApiConfigs: {
// the config for the suggestions api (optional)
suggestionsApiConfig: {
// use this to provide a custom system prompt
makeSystemPrompt: (textareaPurpose: string, contextString: string) => string;
// custom few shot messages
fewShotMessages: Message[];
forwardedParams: {
// max number of tokens to generate
max_tokens: number,
// stop generating when these characters are encountered, e.g. [".", "?", "!"]
stop: string[],
},
},
insertionApiConfig: //... the same options as suggestionsApiConfig
},
}