Closed mehnoorsiddiqui closed 2 months ago
Where exactly are you running this code (console, Cloud Function, Cloud Run)? Also, which sample are you trying exactly?
Have you done gcloud auth application-default login
before running the sample?
No. Do I have to run it only once? As I will use this code in production. Isn't there any way I can do the authentication in the code without using this command?
If you're running locally, that's the easiest way to get auth working by running that gcloud command once. There are other ways, as explained here but I don't have samples for them. If running this code in GCP on Cloud Functions or Cloud Run, you don't need to do any of this.
I should also mention that, there's another version of this sample using the Vertex AI library: https://github.com/meteatamel/genai-samples/blob/main/vertexai/gemini/console/csharp/sdk/GenerateTextFromText.cs
This one handles auth under the covers and might be easier to run.
Thanks @meteatamel
I tried the Vertex AI library, but I am having a hard time figuring out how function calling is done through it. Previously I wrote my own SDK for gemini ai studio api and I was using the code below for function calling
Tools = new List<Tool>
{
new Tool
{
FunctionDeclarations = new List<FunctionDeclaration>
{
new FunctionDeclaration
{
Name="get_relevant_endpoints",
Description="Retrieve Endpoint names that will solve what the user is asking in the question",
Parameters= new Schema
{
Properties = new
{
endpoint_name = new
{
Type = TypeEnum.ARRAY,
Items = new Schema
{
Type = TypeEnum.STRING
}
}
},
Type = TypeEnum.OBJECT,
Required = new List<string>
{
"endpoint_name",
}
},
},
},
}
}
But now can't figure out how to pass the schema to the parameter property as it is read-only in the vertex ai library you mentioned.
You need to use this class somehow: https://cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.FunctionDeclaration#Google_Cloud_AIPlatform_V1_FunctionDeclaration_Parameters
But I don't have a sample ready unfortunately.
If something is read-only, it usually means it's a list that you can't assign but you can add elements to that list. Not sure if this is the issue here.
I don't have time right now to look into this but if I figure it out later, I'll add a sample to the repo.
@mehnoorsiddiqui I have a function calling sample here now: https://github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/main/aiplatform/api/AIPlatform.Samples/FunctionCalling.cs
Closing this.
You have provided the code to authenticate to the Gemini api but this is not working at my end. I have set the service account credentials in the environment variable but it is still not working. Is there any other pre-requisite that I have to do so make this code executable?