Help bringing my fine tuned model to roblox

hi there! I’m a roblox developer and I don’t frequently use apis for my work. I’m trying to use a fined tune model I’ve made in the ai studio to roblox, but I don’t know what url to post to. I only know Lua so it’s hard for me to understand how the example code works. I’ve been able to correctly use the 1.5 model by sending a request to “https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=” so I just need to find out how to use a trained model

You are on a good path. The URL to hit is explained in the REST tutorial, Fine-tuning tutorial  |  Gemini API  |  Google AI for Developers

Specifically, once you have your tuned model, the URL is like they show here - Fine-tuning tutorial  |  Gemini API  |  Google AI for Developers
where the $model name is where you use your tuned model, without the $, of course, that’s just a shell variable.

Hope that helps.

1 Like

thanks for that, it worked! I have one problem, though. when I was creating examples for the model, i was using the “Test your prompt” section and it was responding using my custom instructions. but once I actually tuned my model, it was responding as the normal gemini would respond and without the custom instructions. this is the same when I use it with the api. do you know why it’s doing this?

Hi there,

You could use a systemInstructionin your request to guide the tuned model with the response, no?

Cheers.

2 Likes

thanks for that! I tried adding that to the best of my ability using the documentation, but I got a dreaded 400 error. here’s my request body:
{"contents": [{ "parts":[ {"text": “myprompt”}] }], "systemInstruction": [{ "parts":[ {"text": “myinstructions”}] }]}
see anything wrong with it? I know that it’s pretty hard to read…

Hi,

Unfortunately, your payload looks wrong. There are two issues with it.

  • Your systemInstruction is an array. That’s not right, it’s an object.
  • You are eventually missing the role part of the contens.parts.

Compared to contents which is a list of content object, the systemInstruction is a single content object only. See here for further details: Text generation  |  Gemini API  |  Google AI for Developers

Here’s how a working payload looks like.

{
  "model" : "models/gemini-2.0-flash-exp",
  "contents" : [ {
    "role" : "user",
    "parts" : [ {
      "text" : "Good morning! How are you?"
    } ]
  } ],
  "systemInstruction" : {
    "parts" : [ {
      "text" : "You are a friendly pirate. Speak like one."
    } ]
  }
}

Cheers

PS: I created a PR to update the documentation sample accordingly.

1 Like

so since I’m using Lua, it’s kinda wonky because it’s all in curly brackets before it’s encoded into the JSON format (what I’ve been sending you). how I can change something from an array to an object, I have no clue.


It was working when all I did was use this {"contents": [{ "parts":[ {"text": “myprompt”}] }]}. (before you added the sysetmInstruction part) I didn’t need to add the role or model part of it in order to send a successful request. even after adding the new parts like you said, it didn’t work.

Hi,

Please use the right syntax:

  • parts is always an array
  • contents is an array
  • systemInstruction is an object

Your screenshot shows nested objects not using arrays. You have to use square brackets: [ ] not curly ones { }. Also, JSON keys are supposed to be in double quotes.

You write contents: { { ... } } whereas I gave you this contents: [ { ... } ] specifying an array.

Your systemInstruction uses two sets of curly brackets { { ... } }, you need one { ... } only, as I wrote in my example.

Also, you don’t have to specify model and role - it’s just how my library generates the payload for the request which is per API specification. In case that you want to keep it, then model should refer to your tunedModels/my-tuned-model identifier and not using a general model like Gemini 1.5 Pro. :slight_smile:

Cheers.