I am not very good with golang as of now (just started learning it), I have a bot in python and in go and my python bot responds to requests very quickly (in like 0.5s) while with go its at least 4 but up to 7. i have no idea what causes it.
using
Client.aio.models.generate_content() // with gemini 2.5 flash
to get a text response in python, takes less than 1s on avg, while
genai.Client.Models.GenerateContent() // gemini 2.5 flash as well
takes at least 4s (5s+ in most cases)
what can be causing this?
also, i tried pinging the api using curl in console and it too takes around 4s to get the response.
to clarify: i used them both at the same time, same model, on the same machine, same network settings(theoretically. all i do is run the scripts from console, they should have different network settings, right?), the only difference was the language
# inside MyClass
# not super relevant part in the constructor function
contents = [Content(role="user", parts=[Part.from_text(text=prompt)])]
response = await self.getResponse(model=model_name, contents=contents, config=config)
# relevant part
async def getResponse(self, model: str, contents: list, config: GenerateContentConfig):
try:
return await self.client.aio.models.generate_content(model=model, contents=contents, config=config)
except Exception as e:
await klog.err(f"Failed to get response from Gemini: {e}")
return None
go code snippet:
func (ms *MyStruct) GenerateContent(ctx context.Context, text string, model string) (string, error) {
var parts []*genai.Part
parts = append(parts, genai.NewPartFromText(text))
var contents []*genai.Content
contents = append(contents, genai.NewContentFromParts(parts, genai.RoleUser))
config := genai.GenerateContentConfig{
SafetySettings: safetySettingsBlockNone,
}
startTime := time.Now().UnixMilli()
response, err := ms.Cli.Models.GenerateContent(ctx, model, contents, &config)
if err != nil {
return "Error", err
}
endTime := time.Now().UnixMilli()
responseTime := (endTime - startTime) / 1000
logger.Debugf("Response time: %ds", responseTime)
return response.Text(), nil
}