Coder Social home page Coder Social logo

do-function-openai's Introduction

Sample Function: OpenAI Text Completion

Introduction

This repository contains a DigitalOcean Function that integrates OpenAI and implements the Completion API that when given a prompt, returns a completion. The function requires a POST request and in the body at a minimum requires a prompt property sent as json. Additionally, in the body of the POST request you can pass a max_tokens, temperature, and top_p properties. Learn more about the OpenAI Completion API here.

Examples

Sample Input:

{
    "prompt": "My favorite thing to do on the weekend is",
    "max_tokens": 100
}

Sample Response:

go on long walks with my dog. We usually go to the park or around the neighborhood. I love spending time with her and
getting some fresh air.

Sample Input:

{
    "prompt": "What is the sentiment of the following passage: I never knew serverless was so awesome"
}

Sample Response:

The sentiment of the passage is positive.

Sample Input:

{
    "prompt": "Tell me a programming joke",
    "max_tokens": 100
}

Sample Response:

Why do programmers always have to write code? Because without code, there would be nothing to debug!

Requirements

Deployment

You can deploy this function either via DigitalOcean's doctl CLI or directly on the DigitalOcean App Platform.

1-Click Quick Deploy to DigitalOcean App Platform

Deploy to DO

Deploy via doctl

  • Optional Fork the repo, so you can make changes and take ownership of the code
  • Clone the repo to your machine
  • Navigate to the repo on your machine, and rename .env.example to .env
  • Open the .env file and set your OpenAI API Key
  • Open up a terminal and execute the doctl command: doctl serverless deploy do-function-openai

Deploy via App Platform

  • Fork the repo, so you can make changes and take ownership of the code
  • Navigate to the App Platform section in your DigitalOcean Dashboard, and either create a new app or new resource in an existing app
  • Select the do-function-openai repo that you forked
  • In the Environment Variables section, add your OpenAI API Key to the pre-populated apiKey environment variable

do-function-openai's People

Contributors

brianpmaher avatar kukicado avatar

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.