Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
openai-edge
Advanced tools
A TypeScript module for querying OpenAI's API from an edge function environment
i.e. using fetch
(a standard Web API) instead of axios
.
Edge functions are very fast and, unlike lambda functions, allow streaming data to the client.
yarn add openai-edge
or
npm install openai-edge
This module offers a subset of the methods available in the official Node
package. The syntax and types are essentially the same but the methods return
the standard Fetch Promise<Response>
.
openai.createCompletion
openai.createImage
(since v0.2.0
)import type { NextRequest } from "next/server"
import { Configuration, OpenAIApi } from "openai-edge"
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
})
const openai = new OpenAIApi(configuration)
const handler = async (req: NextRequest) => {
const { searchParams } = new URL(req.url)
try {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: searchParams.get("prompt") ?? "Say this is a test",
max_tokens: 7,
temperature: 0,
stream: true,
})
return new Response(completion.body, {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "text/event-stream;charset=utf-8",
"Cache-Control": "no-cache, no-transform",
"X-Accel-Buffering": "no",
},
})
} catch (error: any) {
console.error(error)
return new Response(JSON.stringify(error), {
status: 400,
headers: {
"content-type": "application/json",
},
})
}
}
export const config = {
runtime: "edge",
}
export default handler
FAQs
Use OpenAI's API from an edge runtime, using standard Web APIs only
The npm package openai-edge receives a total of 12,892 weekly downloads. As such, openai-edge popularity was classified as popular.
We found that openai-edge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.