Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

OpenAi-api Godot

An asset by DrWine
The page banner background of a mountain and forest
OpenAi-api Godot hero image

Quick Information

0 ratings
OpenAi-api Godot icon image
DrWine
OpenAi-api Godot

This plugin integrates OpenAI's GPT and DALL-E APIs into Godot, allowing easy access to these powerful AI tools within your Godot projects.

Supported Engine Version
4.2
Version String
1.0
License Version
Apache-2.0
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

OpenAI Godot Plugin

This plugin integrates OpenAI's GPT and DALL-E APIs into Godot, allowing easy access to these powerful AI tools within your Godot projects.

Features

  • ChatGPT integration for text generation
  • DALL-E integration for image generation
  • Asynchronous API calls using Godot's HTTPRequest
  • Easy-to-use Message class for handling conversation context

Installation

  1. Clone this repository or download the plugin files.
  2. Copy the addons/openai_api folder into your Godot project's addons directory.
  3. Enable the plugin in your project settings.

Usage

Setting up the API Key

Before using the plugin, make sure to set your OpenAI API key:

var openai = get_node("OpenAI")
openai.set_api("your-api-key-here")

Using ChatGPT

To send a prompt to ChatGPT:

var messages = [Message.new()]
messages[0].set_content("Hello, how are you?")
openai.prompt_gpt(messages)

Listen for the response:

func _ready():
    open_ai.connect("gpt_response_completed", gpt_response_completed)

func _on_gpt_response(message: Message, response: Dictionary):
    print(message.get_content())

Full code:

extends Node2D

@onready var open_ai = $OpenAi

# Called when the node enters the scene tree for the first time.
func _ready():
    ##Conecting the output from chatgpt
    open_ai.connect("gpt_response_completed", gpt_response_completed)
    
    ##Creating meessages template
    var messages:Array[Message] = [Message.new()]
    messages[0].set_content("say hi!")
    
    ##setting the api key
    open_ai.set_api("<API HERE>")
    
    ##Prompt chatgpt
    open_ai.prompt_gpt(messages)
    
func gpt_response_completed(message:Message, response:Dictionary):
    printt(message.get_as_dict())

Using DALL-E

To generate an image with DALL-E:

openai.prompt_dalle("A beautiful sunset over mountains")

Listen for the response:

func _ready():
    open_ai.connect("dalle_response_completed", dalle_response_completed)

func _on_dalle_response(texture: ImageTexture):
    $Sprite2D.texture = texture

Classes

OpenAI

The main node that handles API requests and responses.

Message

A utility class for handling conversation messages.

ChatGpt

Handles ChatGPT API requests.

Dalle

Handles DALL-E API requests.

This plugin integrates OpenAI's GPT and DALL-E APIs into Godot, allowing easy access to these powerful AI tools within your Godot projects.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
OpenAi-api Godot icon image
DrWine
OpenAi-api Godot

This plugin integrates OpenAI's GPT and DALL-E APIs into Godot, allowing easy access to these powerful AI tools within your Godot projects.

Supported Engine Version
4.2
Version String
1.0
License Version
Apache-2.0
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers