Team Ai
Apppublic

Fozan-Talat/agentic-system

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
utils.py43 linesDownload Raw Back to root
1# Add your utilities or helper functions to this file.2 3import os4from dotenv import load_dotenv, find_dotenv5 6# these expect to find a .env file at the directory above the lesson.                                                                                                                     # the format for that file is (without the comment)                                                                                                                                       #API_KEYNAME=AStringThatIsTheLongAPIKeyFromSomeService7def load_env():8    _ = load_dotenv(find_dotenv())9 10def get_openai_api_key():11    load_env()12    # openai_api_key = os.getenv("OPENAI_API_KEY")13    openai_api_key = "sk-proj-yB2c7FvCOjmT1aRmn4HFT3BlbkFJzWapkbcRuZuo5uo0vtMr"14    return openai_api_key15 16def get_serper_api_key():17    load_env()18    openai_api_key = os.getenv("SERPER_API_KEY")19    return openai_api_key20 21 22# break line every 80 characters if line is longer than 80 characters23# don't break in the middle of a word24def pretty_print_result(result):25  parsed_result = []26  for line in result.split('\n'):27      if len(line) > 80:28          words = line.split(' ')29          new_line = ''30          for word in words:31              if len(new_line) + len(word) + 1 > 80:32                  parsed_result.append(new_line)33                  new_line = word34              else:35                  if new_line == '':36                      new_line = word37                  else:38                      new_line += ' ' + word39          parsed_result.append(new_line)40      else:41          parsed_result.append(line)42  return "\n".join(parsed_result)43