Skip to content

r13v/use-prediction

Repository files navigation

use-prediction

It is like a Copilot for your input fields.

Installation

npm install use-prediction

Usage

import{usePrediction}from"use-prediction"constExample=()=>{constprediction=usePrediction({get: getOpenAICompletion})return(<div><inputref={prediction.ref}/></div>)}functiongetOpenAICompletion(text: string,controller: AbortController){returnfetch("https://api.openai.com/v1/completions",{method: "POST",headers: {"Content-Type": "application/json","Authorization": `Bearer ${process.env.OPENAI_TOKEN}`,},body: JSON.stringify({model: "gpt-3.5-turbo-instruct",prompt: text,temperature: 0,max_tokens: 5,top_p: 1,}),signal: controller.signal,}).then((res)=>res.json()).then((data)=>data.choices[0].text)}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published