OpenAI API difference in results

Hello everyone. I have a pretty small API that connects to OpenAI API, using an env var that contains a few special chars prompt.

The problem I’m having is that I’m getting different results from OpenAI API when using it in Koyeb production, then from using localhost or in OpenAI demo section. It feels like the prompt is not being sent when connecting with OpenAI API.

Wondering if the env var value by being incorrectly interpreted or maybe if I should change how I insert these special chars in the env var?

Thoughts on this?
Thank you!

Just tried using Secrets, but no luck…

Hello,

You should be able to get the exact values of the environment variables used in your deployment by accessing a shell on your service and type env. You can open a shell using the Koyeb control panel or from the CLI.

Does this help you troubleshoot your issue?

1 Like

Hey nils, thank you so much for your reply!
Are you saying that there’s a difference of how Koyeb interprets an env var, for when setting it via Koyeb UI and via shell?

There should be no difference. You can review the actual values by accessing a shell on your service. There are two ways of doing that:

  • Login to app.koyeb.com, select the Service in question and switch to the Console tab, press Enter for default /bin/sh or override it, then run command env to list environment variables.
  • Download Koyeb CLI, generate a token and run koyeb instances exec [instance ID] -- env
1 Like

I see. Thank you for the reply, Sebastian_Wiewiora!
So it seems the env var is as it supposed to be. I checked in shell like suggested and it seems fine.

But the difference in results when using the OpenAI API in Koyeb production is still going on. If tested in my localhost or in the OpenAI demo section, the results are good.

I’m just guessing it’s the env var, since this might the only thing I have to manually adjust in the Koyeb environment, but not sure it’s the problem here.

For reference, this is a small part of the env var I’ve been using: "tags".\n\nExample 1:\nInput: -1PP [BR]. It has a few special chars and the total of 3714 chars.

Any suggestions on what might be the case here? I’m clueless on why this is happening only in Koyeb. Thank you!

Hello everyone. I was able to find and fix the problem.

My env var had so many special chars, that it was not being completely interpreted by the system. It had double quotes ", hashtags #, slashs /\ etc. So the fix was to convert double quotes to single quotes, and add a double quote around the whole env var. This way it was correctly interpreted.

So for example, instead of this:

You will be provided with "tags".\n\n"Example 1: [BR]" #\nExample 2

I had to correct to something like this:

“You will be provided with 'tags'.\n\n’Example 1: [BR]’ #\nExample 2”

Thank you for the support!
All the best.

2 Likes

Thank you for your response, I’m happy to hear that you managed to resolve the issue.

To avoid issues like these in the future, it’s a good practice to encode the value of a complex environment variable using Base64 for example

2 Likes

Oh my, this is really good advice! Thank you! Will definitely consider this! :grinning:

1 Like