Open Ai Api response is way more different from Chat Gpt response

ChatGPT and openal API responses are very different. Though i am using same 3.5 turbo model as of chatGPT UI. API responses are very short and they are not following the prompt correctly I am keeping temperature= 0.7 can someone help me on this. Am I missing some other parameters and if so what would be recommended value for same

1 Like

Can you share your API code? Try adding a system prompt if you don’t have one.

Try to lower the temperature to 0.3-0.5, so the model will follow your request more strictly. Also did you set max_tokens? That decides the expected response length.

It would be helpful if you can paste your request.

I have the same issue but in the opposite direction: api responses very long although explicitely instructed to not respond with more than a certain number of words.

This is the exact prompt I used both in the api and in chat.
The model is gpt-3.5 turbo:


Write the text for a documentary about the main topic: ‘National Dishes: Quick facts about a country’s national dish and its cultural significance.’. The text must be no longer than 112 words. Structure the narration into distinct arguments, each discussing a different sub-topic. For each argument, provide a title enclosed in square brackets. For example: [Galileo’s Telescope Discovery]. The title must contain the key concept and keywords of the related argument in a maximum of 12 words. The title has to summarise the topic in a way that makes its content clear even without reading the text of the argument. Do not include the word ‘section’, ‘chapter’, ‘introduction’, ‘conclusion’ in the title. Separate each argument and its content with a line break. Please do not include any time codes. The text will be used for a documentary. Do not write an introduction or conclusion, but only the relevant arguments, go straight to the point. The text has not to end with a conclusion, a legacy or final thoughts, but simply with the last relevant argument to be exposed. In the text, you don’t have to provide considerations and thoughts, but only the facts related to the argument provided without any introduction or final thoughts. The text must be no longer than 112 words.


This is the response in the chat:


[National Dish Definition]
A national dish, often considered a culinary ambassador, is a prominent meal representing a country’s culinary heritage.

[Cultural Significance]
These dishes reflect a nation’s history, geography, and diverse traditions, fostering a sense of pride and unity.

[Symbolism]
National dishes often carry symbolic elements, like ingredients or colors, embodying cultural values and stories.

[Social Gatherings]
These iconic meals play a crucial role in social gatherings, reinforcing bonds among family and friends.

[Regional Variations]
Despite being a national symbol, these dishes often boast regional variations, showcasing the rich diversity within a country.

[Preservation]
Efforts are made to preserve and promote these dishes as a means of safeguarding cultural identity.

[Global Influence]
National dishes also find their way onto international menus, sharing a taste of a country’s culture worldwide.


And this with the api:

[National Dishes: Quick facts about a country’s national dish and its cultural significance]

[Historical Origins]
Many national dishes hold historical significance, reflecting a country’s cultural heritage and traditions. These dishes often have origins dating back centuries and have been passed down through generations, preserving their unique flavors and preparation methods.

[Sense of Identity]
A national dish is more than just food; it represents a nation’s identity and values. It serves as a symbol of unity and pride, connecting people to their roots. Through the preparation and consumption of these dishes, individuals feel a strong sense of belonging and cultural identity.

[Regional Variations]
Despite being a national dish, there can be regional variations that showcase the diverse culinary traditions within a country. These variations often showcase the availability of local ingredients, regional cooking techniques, and cultural influences, adding depth and complexity to the national cuisine.

[Celebrations and Festivals]
National dishes are often closely associated with celebrations and festivals. These occasions provide an opportunity for people to come together, share traditional foods, and celebrate their cultural heritage. These dishes can be complemented by cultural performances, music, and rituals, creating a vibrant and festive atmosphere.

[Global Recognition]
In recent years, many national dishes have gained global recognition and become cultural ambassadors for their respective countries. Thanks to globalization, people from different backgrounds can now experience and appreciate the diverse flavors and traditions of other nations, forging connections and fostering cultural understanding.

[Conclusion]
National dishes are not merely meals; they carry historical, cultural, and emotional significance. They represent a nation’s identity and unite people in celebration of their shared heritage. Whether enjoyed at home or experienced abroad, these dishes serve as a bridge that connects individuals from various backgrounds, fostering cultural exchange and appreciation.


This is the api code:

def generate_content(prompt, system_message):
print(f"\nSystem message: {system_message}\n")
try:
response = openai.ChatCompletion.create(
model=“gpt-3.5-turbo”,
messages=[
{“role”: “system”, “content”: system_message},
{“role”: “user”, “content”: prompt},
],
temperature=1,
)
return response[‘choices’][0][‘message’][‘content’].strip()
except Exception as e:
print(f"An error occurred while generating content: {e}")
return None

I also set the temperature to lower values but always the same.
I also used different system messages.

But the api and chat should not use the same model?

1 Like