Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chatgpt-cloudflare

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatgpt-cloudflare

ChatGPT API client, compatible with Cloudflare Workers

  • 2.0.0-esm
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

chatgpt-cloudflare

ChatGPT API client, compatible with Cloudflare Workers

Running tests

In order to execute tests that make call to real ChatGPT, please copy dev.vars.default into .dev.vars and replace key with the real one.

Usage example

import { ChatGPTClient, ConversationContext } from "chatgpt-cloudflare";

export interface Env {
  OPENAI_API_KEY: string;
}

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    const openAiClient = new ChatGPTClient(env.OPENAI_API_KEY);
    const body = (await request.json()) as Record<string, any>;

    const context = new ConversationContext();
    await openAiClient.getResponse(
      {
        prompt:
          "After this sentence, I will give you some text; please repeat all of it verbatim, but add an exclamation point in its end. \n " +
          body.prompt,
        systemContext: "You are a helpful assistant.",
      },
      context
    );

    const response2 = await openAiClient.getResponse(
      {
        prompt:
          "Please respond with your previous answer, but add one more exclamation mark to it",
      },
      context
    );

    const responseText = response2.text;

    return new Response(
      JSON.stringify({
        response: responseText,
      })
    );
  },
};

Keywords

FAQs

Package last updated on 26 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc