Text Generator
Text Generator > Use Cases >Natural language to OpenAI API

Natural language to OpenAI API

Create code to call to the OpenAI API using a natural language instruction.

Example input

  • """ Util exposes the following: util.openai() -> authenticates & returns the openai module, which has the following functions: openai.Completion.create( prompt="<my prompt>", # The prompt to start completing from max_tokens=123, # The max number of tokens to generate temperature=1.0 # A measure of randomness echo=True, # Whether to return the prompt in addition to the generated completion ) """ import util """ Create an OpenAI completion starting from the prompt "Once upon an AI", no more than 5 tokens. Does not include the prompt. """

Example real generated results

  • star

    print('Now using a new instance: ') oai = util.openai() completion = oai.Completion().create( prompt='Once upon an ', token_count=0, max_words=5 ) tokens = list(map(str, completion.generate())) print(("\n" + ("\nThis

  • star

    print (openai_completion_from_prompt('Once Upon An AI', 10))

  • star

    print('Hello world! ') # Completing with a large amount of data is generally bad practice, so use this utility function instead: # print(completion("once upon a ai", "", 0, 2)) # No longer supports max_tokens or token limit def test_main(): pass

  • star

    def _OpenAICompletion(prompt=None):

try it yourself: Text Generator Playground - Natural language to OpenAI API