Code Monkey home page Code Monkey logo

openai's Introduction

Unofficial Deno wrapper for the Open Ai API

Tags Doc Checks License

Usage

Your Open AI Api key (found here) is needed for this library to work. We recommend setting it as an environment variable. Here is a configuration example.

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

Completion

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const completion = await openAI.createCompletion({
  model: "davinci",
  prompt: "The meaning of life is",
});

console.log(completion.choices);

Chat Completion

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const chatCompletion = await openAI.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Who won the world series in 2020?" },
    {
      "role": "assistant",
      "content": "The Los Angeles Dodgers won the World Series in 2020.",
    },
    { "role": "user", "content": "Where was it played?" },
  ],
});

console.log(chatCompletion);

Image

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const image = await openAI.createImage({
  prompt: "A unicorn in space",
});

console.log(image);

Edit

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const edit = await openAI.createEdit({
  model: "text-davinci-edit-001",
  input: "What day of the wek is it?",
  instruction: "Fix the spelling mistakes",
});

console.log(edit);

Image Edit

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const imageEdit = await openAI.createImageEdit({
  image: "@otter.png",
  mask: "@mask.png",
  prompt: "A cute baby sea otter wearing a beret",
  n: 2,
  size: "1024x1024",
});

console.log(imageEdit);

Image Variation

import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);

const imageVariation = await openAI.createImageVariation({
  image: "@otter.png",
  n: 2,
  size: "1024x1024",
});

console.log(imageVariation);

Maintainers

License

MIT

openai's People

Contributors

load1n9 avatar lino-levan avatar ferdousbhai avatar ymirke avatar ytkg avatar djmuted avatar mindon avatar

Forkers

jmatsushita

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.