#Let's start a separate thread about AI

1 messages · Page 1 of 1 (latest)

gray spear
#

Do you have gloud?

inland vector
#

Yes, I have gcloud installed.

gray arch
#

please share the link, help me install

gray arch
#

just installed

gray spear
#

ok, try this:

  • unset GOOGLE_APPLICATION_CREDENTIALS
  • run gcloud auth application-default login and login with the user the model was created under
  • then run the app that accesses the model
inland vector
#

I found this warning

pulsar verge
#

Hi all, didn't follow the whole thread, but assuming the tuned model was made in AI Studio? If so then I think it's associated with your logged in user account and not the gcloud project/service account, so generate calls would need to be oauth authenticated with your user account.

You can add permissions to models using https://ai.google.dev/api/rest/v1beta/tunedModels.permissions/create but there's no UI for this in AI Studio currently.

gray spear
gray spear
pulsar verge
#

I think the best working flow is (1) Make model in AI Studio (2) Make OAuth'ed POST request as yourself to add your service account (or everyone if that works for you, you'd need to know the model name to call it but it's obfuscation at best)

Definitely complicated

inland vector
#
Error: 7 PERMISSION_DENIED: Request had insufficient authentication scopes.
gray spear
#

I'm honestly confused by that one, since the library should be requesting the right scopes.

inland vector
gray spear
#

stand by

#

it looks like the node library doesn't have listModels

#

(that call is from the PaLM page, so is obsolete)

gray arch
gray arch
# inland vector

hold up, we might need to set permissions before trying to access it

inland vector
gray arch
#

we would need to create a session to obtain an access token

inland vector
gray spear
#

Try just accessing the model once you've done the gauth

#

The gauth should log you into the applicaiton default credentials as yourself. The node library will use these default credentials if no other credentials are provided.

#

The problem is - the node library doens't have a way to list models.

gray spear
#

Well... this is a new one for me. Trying to log in using gcloud with the training scope is blocked as an unsafe action

gray arch
#

yes im trying for the scope as well

#

is it training?

gray spear
#

https://www.googleapis.com/auth/generative-language.tuning
or
https://www.googleapis.com/auth/generative-language.tuning.readonly

gray arch
#

can you give me an example url string

#

to set permissions

gray arch
#

@gray spear @inland vector @pulsar verge was able to figure the url below is the data im passing and error as follows

gray spear
#

https://generativelanguage.googleapis.com/v1beta3/tunedModels/YOUR_MODEL_NAME_HERE

gray arch
#

@gray spear got it, i was able to set permissions as well

#

it was a 200

gray arch
#

@gray spear @inland vector @pulsar verge I was able to create a session with tuning scope and then make call to set permissions, get content , getmodel as per the documentation. REST is fine, but node doesn't work even after updating the permissions. Is REST the possible work around for this. do we need to generate tokens and make REST calls. or will it work, the NODE way

gray spear
#

It should work with Node. If you have permitted your service account, and then use the credentials for the service account, I would expect it to work.

#

How did you get the REST to use your account permissions?

pulsar verge
gray spear
#

There is no trained models list in node, apparently.

#

(at least from my reading of the documentation and code)

#

And when I try to use REST, I either don't have the right scope... or it won't allow me to use the scope for security reasons. {:

pulsar verge
#

it's written in Python but uses REST calls

gray spear
#

interesting. and it uses the --scopes parameter for gcloud auth application-default login, which is giving me an error. tho I'm not using the client-secret.json. will have to plahy with this more.

pulsar verge
gray arch
# gray spear How did you get the REST to use your account permissions?

I achieved this using only tuning scope, in the Postman Client. The workflow would be similar to creating a login session and storing the access token. With the access token present, I was able make api Calls and it is working fine. It seems that REST alone is working. But I would need a NODE work around so I wouldn't need to deal with sessions and tokens

gray arch
#

let's just say, we want to build an API endpoint and want to use this Tuned Model in it to process the input. it appears that all the requests should be authenticated, is it? and it is the only possible work around? @pulsar verge

pulsar verge
#

I haven't used the tuning API much myself, but my understanding is all requests involving tuned models would have to be OAuth authenticated

#

how you want to design the authentication is up to your business requirements

pulsar verge
leaden thunder
#

have anyone successfully run tuned model with OAuth?

pulsar verge
gray arch
# leaden thunder have anyone successfully run tuned model with OAuth?

i was able to make authenticated calls to it over POSTMAN to the endpoint and was able to generate content. Tried to develop REST API using NODE+EXPRESS but was unsuccessful. Now im trying with PYTHON+FLASK. Hopefully it works since Gemini API has better Documentation with Python

leaden thunder
gray arch
#

google.api_core.exceptions.PermissionDenied: 403 You do not have permission to access tuned model tunedModels/test-12va0xxxx5ij. //// Got the same error in the python+flask as well. Now this confirms that we can only use tuned models with our own authenticated sessions. @pulsar verge @gray spear

pulsar verge
gray arch
#

the problem is, i would want to create an api endpoint so it can be accessible by the allowed domain names. I want to be able to call the tuned model from the api logic. but it requires authentication, and only works with the owner's session. now i am obligated to authenticate it every time i make calls to it. access tokens, refresh tokens and persist tokens. ah! what a mess, google should have never published it for production use. I was able to make it work, but it feels like i wasted a lot of time. why would i deploy it and authenticate it logging in and creating a session. this doesn't feel right, and even there is no proper documentation. @pulsar verge

pulsar verge
pulsar verge
gray spear
#

I've had to deal with auth extensively - and I find this a mess to deal with. {:

#

(It might be easier if I could set permissions in the UI, however, I will admit. And I'll see if I can coerce it to play with this weekend, perhaps.)

pulsar verge
#

I'm working on more OAuth docs/examples for Colab at least!

gray arch
#

anyways I was able to deploy my REST API, but the catch is, I would login over the browser to hold the session, and then using the refresh tokens in the Api logic to handle token expiration and making subsequent calls. it feels slightly unprofessional, kind of, just a bit. Finally, some relief over the weekend:)

gray spear
gray arch
gray spear
#

Well... I'm in the middle of writing some. {:

And part of the problem is that you'd have to permit the service account, and I don't know how to do that yet for the tuned models.

pulsar verge
gray spear
#

Nod. That was my guess, but I haven't had the chance to test it yet, either.

pulsar verge
#

sudden realization that I wrote all the code snippets I need to test this over the weekend, let me try now 🙂

pulsar verge
#

Okay, I've basically confirmed this works, as I can genai.get_tuned_model() in Python, a tuned model shared with a service account, but it fails with a different model I didn't share

#

I'm having issues with generating content, but I think I just need more time to understand the SDK

willow solstice
#

this all intresting and i know the issue

crude mountain
#

@gray spear Okay, I'm here. I'm still stuck on the "Set up application default credentials" part. I don't understand where I need to insert this in the code and if I need to replace anything. I'm making a chatbot with Gemini in a messenger and if I mess up something it will be a bit difficult.

gray spear
crude mountain
gray spear
#

Win cmd or cloud shell
Wherever you're trying to run the app that will call the trained model from.

#

why is it that if the model on the Gemini website and in the code is essentially the same, but the behavior is different?
I'm... not sure I follow what you're saying.
You're asking why you need to use OAuth when it works fine using AI Studio?

crude mountain
crude mountain
gray spear
gray spear
crude mountain
#

Ok I can explane simply

#

For example, I can go to the official Gemini website and if I say "Hello" to him, he can also complete the answer and offer something (for example, to find out something). And if, for example, you take a own version in a telegram bot, then he can respond to "Hello" like "Hello, how are you?" And nothing else

gray spear
rotund nimbus
pulsar verge
# rotund nimbus How exactly do you do this permission creation in Python?

https://github.com/google-gemini/gemini-api-cookbook/blob/main/quickstarts/Authentication_with_OAuth.ipynb has relevant samples to prototype with. Using OAuth in production is beyond the scope of this doc, but also the challenges aren't specific to the Gemini API.

GitHub

A collection of guides and examples for the Gemini API. - google-gemini/gemini-api-cookbook

rotund nimbus
#

Thanks for the last session on permission creation. Will give it a try.

rotund nimbus
gray spear
pulsar verge
#

Where did you make the tuned model? if it was AI studio, you'll need to oauth to colab using the same account. You can confirm auth is working as expected if you see the tuned model under genai.list_tuned_models().

pulsar verge
rotund nimbus
rotund nimbus
#

I was following instructions "Get Code" in the AI studio.

rotund nimbus
#

Can confirm that base models are working so the auth should be good. I am guessing it's stuck at Tuned model permissions.

#

Is this like so by design? I can imagine Google imposes this to avoid naughty finetunings made to the news. But I am doing this for my PhD

pulsar verge
#

If you can't see the tuned model using list_tuned_models then the tuned model was created by a different account than yours.

#

or at least it was not made by the account you're currently authenticated as

pulsar verge
short bough
#

In the "new tuned model" screen in the Ai studio, why is my Tune button greyed out, even though everything is filled out and loaded

gray spear
#

Are you using an exisitng prompt or importing the data?