ryanraposo / gem

1 stars 0 forks source link

Generating Game Elements with AI #2

Open ryanraposo opened 2 years ago

ryanraposo commented 2 years ago

Background

An experiment demonstrating the possiblity of generating game elements with OpenAI's completion API.

Method


# Simple OpenAI completion playground 

import os
import openai

def getCompletion(prompt):
    openai.api_key = "YOUR_KEY_HERE" 
    completion = openai.Completion.create(
        model="text-davinci-002",
        prompt=prompt,
        max_tokens=1028
    )
    return completion.choices[0].text.strip()

while True:
    input_prompt = input("Enter a prompt:")
    completion = getCompletion(input_prompt)
    print(completion)

Results

Each line is a prompt, with previous answers looped in:

ryanraposo commented 2 years ago

Background

In this example, a character sheet is generated with:

Method: Code

import os
import openai

openai.api_key = "YOUR_KEY_HERE"
completion = openai.Edit.create(
    model="text-davinci-edit-001",
    input="There are three possible traits: power-hungry, lonely, violent.\n\nRYAN\n\nTRAIT: ___\nLIFE GOAL: ____\nVIDEO-GAME STYLE ENEMY NAME: ____\nENEMY ATTACK NAME: ____\nENEMY WEAK TO ATTACK NAMED: ____\nALWAYS CARRY: ____\nFAVOURITE PHRASE: ____\n\n",
    instruction="Fill in the blanks",
    temperature=0.7,
    top_p=1
)

print(completion.choices[0].text.strip())

Method: Playground

image

Results

A personal favourite:

There are three possible traits: power-hungry, lonely, violent.

RYAN

TRAIT: LONELY
LIFE GOAL: BECOME THE CEO OF A FORTUNE 500 COMPANY
VIDEO-GAME STYLE ENEMY NAME: MR. SLITHER
ENEMY ATTACK NAME: SNAKES OF HELL
ENEMY WEAK TO ATTACK NAMED: SNAKES OF HELL
ALWAYS CARRY: A BOOK
FAVOURITE PHRASE: GO TOGETHER, OR GO ALONE