PeepDaSlan9/B2BMGMT_cyber_app
4
1import os2from openai import OpenAI3# os.environ['LEPTON_API_KEY']= 'e6ua0rtm4drrpl7tz16farcczod387dz'4# os.environ['LEPTON_API_KEY']= 'twoun3dz0fzw289dgyp2rlb3kltti8zi'5 6 7def generate_response(model, user_query):8 client = OpenAI(9 api_key=os.environ.get("LEPTON_API_KEY", "twoun3dz0fzw289dgyp2rlb3kltti8zi"),10 base_url=f'https://{model}.lepton.run/api/v1',11 )12 response = client.chat.completions.create(13 model= f"{model}",14 messages=[15 {16 "role": "user", 17 "content": user_query18 },19 ],20 max_tokens=4096,21 stream=True,22 )23 24 reply = ''25 for chunk in response:26 if chunk.choices:27 content = chunk.choices[0].delta.content28 if content:29 reply += content30 31 return reply