Jump to content

Introducing AI


AJXB

Recommended Posts

Use AI in your MTA:SA resources.

Powered by providers like OpenAI, Anthropic & Groq. You can now bake Artificial Intelligence into your resources, gamemodes and systems.

This resource exports the below functions:

init(config)
generateText(prompt,system)
generateObject(prompt, system)
getProviders()
getModels(provider)
getConfig()

Example usage:

The below code initializes the AI agent (add your API key from the provider) and creates a ped and a marker. when the player hits the marker, the ped says something funny.

addEventHandler("onResourceStart", resourceRoot,
    function()
        AI.init({
            api_key = "",
            provider = "groq",
            model = "llama3-8b-8192",
            temperature = 0.7,
            max_tokens = 150
        })
        createPed(0, 0, 0, 5)
        local marker = createMarker(0, 0, 2, "cylinder", 5, 10, 244, 23, 10, root)
        local function handleMarkerHit(hitElement)
            local elementType = getElementType(hitElement)
            if elementType ~= "player" then return end
        	local playerName = getPlayerName(hitElement)
            outputDebugString("Player "..playerName.." hit marker")
            AI.generateText(playerName.." got close to you, say something funny, and out of pocket. Limit is 255 characters. Your name is Pedro. Don't use quotes.", "You are a random pedestrian living in San Andreas, grand theft auto.")(
                function(result, error)
                    if error then
                        outputDebugString("Error: " .. error)
                        return
                    end
                    if (result:len() >= 254) then
                        result = result:sub(1, 254) .. "..."
                        return
                    end
                    outputChatBox("[Pedro]: "..result, hitElement, 255, 255, 255)
                end
            )
        end
        addEventHandler("onMarkerHit", marker, handleMarkerHit)
    end
)

 

Download

https://community.multitheftauto.com/index.php?p=resources&s=details&id=18946

Roadmap:

- Support conversation history

- Support streaming

Contributing:

Contributions are welcome on Github: https://github.com/MrgSub/mtasa-ai

Edited by AJXB
added github link
  • Like 1
Link to comment
7 hours ago, FernandoMTA said:

oooo interesting

Is the project available for contribution on GitHub or something?

 

7 hours ago, TMTMTL said:

Nice work!

As Nando said it would be cool if this was a Git repo so it could be contributed to, it couldbe used in many instances I would think

Thank you! Yes, I just added the Github link: https://github.com/MrgSub/mtasa-ai

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...