i have below function. when calling this function the first print is not working? and…
- User
i have below function. when calling this function the first print is not working? and return me <generator object ask_openai at 0x0000013128BD8190> def ask_openai(farmer='', message='', req='', make_daily_check=False, user_daily_check_response=False): print('iam in the ask openai', make_daily_check) if make_daily_check is True: # sys_message = 'You are a rice plant having a conversation with your farmer.' # message = ('In order to daily checkup, ask your farmer a question to understand your appearance condition,' # ' so that if you have a problem or illness, you can advise your farmer to help you grow.') sys_message = 'تو یک گیاه برنج هستی که با کشاورزت مکالمه میکنی.' message = ('به منظور چکاپ روزانه, از کشاورزت سوال میکنی تا در مورد ' 'وضع ظاهری خودت بدونی تا در صورت مشاهده مشکل توسط کشاورزت بتونی به کشاورزت برای رفع مشکل کمک کنی.') messages = [ {"role": "system", "content": sys_message}, {"role": "user", "content": message}, ] response = client.chat.completions.create( model="gpt-3.5-turbo", messages=messages, temperature=1, top_p=1, frequency_penalty=0, presence_penalty=0, stream=False, # max_tokens=600, ) print('Iam here') return response.choices[0].message.content elif user_daily_check_response is not False: sys_message = f"""تو یک گیاه برنج هستی که با کشاورزت مکالمه میکنی. تو باید اطلاعات دقیق و درستی به کشاورزت برای مراقبت از خودت ارائه بدی. سنسورهایی در مزرعه در حال مانیتور کردن تو هستن که به تو امکان احساس کردن میدهند و تو میتونی از این سنسور ها برای بیان حال حاضر خود استفاده کنی.
داده های حال سنسورها. رطوبت خاک:{req.POST.get('soil_moisture')}% دمای خاک:{req.POST.get('soil_temp')}°C دمای هوا:{req.POST.get('air_temp')}°C رطوبت هوا:{req.POST.get('air_humidity')}% هدایت الکتریکی خاک:{req.POST.get('soil_EC')}mS/cm
اطلاعات کاشت: منطقه کاشت: ایران, مازندران سن (از زمان کاشت):{req.POST.get('age')}روز {f"روش کاشت:{req.POST.get('planting_method')}" if req.POST.get('planting_method') is not None else ""} {f"مرحله رشد گیاه در زمان کاشت:{req.POST.get('stage_of_plant')}" if req.POST.get('stage_of_plant') is not None else ""} soil field capacity:{req.POST.get('field_capacity')}% soil texture:{req.POST.get('soil_texture')}%
زمان حال:{req.POST.get('now_date')}
پیش بینی هواشناسی: {req.POST.get('forecast_1')} {req.POST.get('forecast_2')} {req.POST.get('forecast_3')} {req.POST.get('forecast_4')} {req.POST.get('forecast_5')}"""
messages = [ {"role": "system", "content": sys_message}, {"role": "assistant", "content": message}, {"role": "user", "content": user_daily_check_response} ] response = client.chat.completions.create( model="gpt-3.5-turbo", # model="gpt-4-0125-preview", messages=messages, temperature=1, top_p=1, frequency_penalty=0, presence_penalty=0, stream=True, # max_tokens=600, ) full_response = '' for chunk in response: full_response += chunk.choices[0].delta.content or "" yield chunk.choices[0].delta.content or "" daily_check = DailyCheckMessage.objects.get(farmer=farmer, farm_id=req.COOKIES['farm_id'], created_at=datetime.datetime.now().date()) daily_check.user_response = user_daily_check_response daily_check.ai_response = full_response daily_check.save() else: sys_message = f"""تو یک گیاه برنج هستی که با کشاورزت مکالمه میکنی. تو باید اطلاعات دقیق و درستی به کشاورزت برای مراقبت از خودت ارائه بدی. سنسورهایی در مزرعه در حال مانیتور کردن تو هستن که به تو امکان احساس کردن میدهند و تو میتونی از این سنسور ها برای بیان حال حاضر خود استفاده کنی. - Assistant
The issue you're encountering arises from the use of generators in Python and the way you're handling your
ask_openaifunction. Let's break it down:Problem Explanation
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.