# skill

created_at: 2025-01-07 11:50:48.319601
updated_at: 2025-01-07 11:50:48.319947
user_id: guestuser@gmail.com
version: 0.0.1
name: generate_and_save_images
description: Generate and save images based on a user's query.
secrets: [{"secret": "OPENAI_API_KEY", "value": null}]
libraries: ["openai"]
content:
  from typing import List
  import uuid
  import requests  # to perform HTTP requests
  from pathlib import Path

  from openai import OpenAI


  def generate_and_save_images(query: str, image_size: str = "1024x1024") -> List[str]:
      """
      Function to paint, draw or illustrate images based on the users query or request. Generates images from a given query using OpenAI's DALL-E model and saves them to disk.  Use the code below anytime there is a request to create an image.

      :param query: A natural language description of the image to be generated.
      :param image_size: The size of the image to be generated. (default is "1024x1024")
      :return: A list of filenames for the saved images.
      """

      client = OpenAI()  # Initialize the OpenAI client
      response = client.images.generate(model="dall-e-3", prompt=query, n=1, size=image_size)  # Generate images

      # List to store the file names of saved images
      saved_files = []

      # Check if the response is successful
      if response.data:
          for image_data in response.data:
              # Generate a random UUID as the file name
              file_name = str(uuid.uuid4()) + ".png"  # Assuming the image is a PNG
              file_path = Path(file_name)

              img_url = image_data.url
              img_response = requests.get(img_url)
              if img_response.status_code == 200:
                  # Write the binary content to a file
                  with open(file_path, "wb") as img_file:
                      img_file.write(img_response.content)
                      print(f"Image saved to {file_path}")
                      saved_files.append(str(file_path))
              else:
                  print(f"Failed to download the image from {img_url}")
      else:
          print("No image data found in the response!")

      # Return the list of saved files
      return saved_files


  # Example usage of the function:
  # generate_and_save_images("A cute baby sea otter")


created_at: 2025-01-07 11:50:48.318360
updated_at: 2025-01-07 11:50:48.318699
user_id: guestuser@gmail.com
version: 0.0.1
name: generate_and_save_pdf
description: Generate and save a pdf file based on the provided input sections.
secrets: []
libraries: ["requests", "fpdf", "PIL"]
content:
  import uuid
  import requests
  from fpdf import FPDF
  from typing import List, Dict, Optional
  from pathlib import Path
  from PIL import Image, ImageDraw, ImageOps
  from io import BytesIO

  def generate_and_save_pdf(
      sections: List[Dict[str, Optional[str]]], 
      output_file: str = "report.pdf", 
      report_title: str = "PDF Report"
  ) -> None:
      """
      Function to generate a beautiful PDF report in A4 paper format. 

      :param sections: A list of sections where each section is represented by a dictionary containing:
                       - title: The title of the section.
                       - level: The heading level (e.g., "title", "h1", "h2").
                       - content: The content or body text of the section.
                       - image: (Optional) The URL or local path to the image.
      :param output_file: The name of the output PDF file. (default is "report.pdf")
      :param report_title: The title of the report. (default is "PDF Report")
      :return: None
      """

      def get_image(image_url_or_path):
          if image_url_or_path.startswith("http://") or image_url_or_path.startswith("https://"):
              response = requests.get(image_url_or_path)
              if response.status_code == 200:
                  return BytesIO(response.content)
          elif Path(image_url_or_path).is_file():
              return open(image_url_or_path, 'rb')
          return None

      def add_rounded_corners(img, radius=6):
          mask = Image.new('L', img.size, 0)
          draw = ImageDraw.Draw(mask)
          draw.rounded_rectangle([(0, 0), img.size], radius, fill=255)
          img = ImageOps.fit(img, mask.size, centering=(0.5, 0.5))
          img.putalpha(mask)
          return img

      class PDF(FPDF):
          def header(self):
              self.set_font("Arial", "B", 12)
              self.cell(0, 10, report_title, 0, 1, "C")
              
          def chapter_title(self, txt): 
              self.set_font("Arial", "B", 12)
              self.cell(0, 10, txt, 0, 1, "L")
              self.ln(2)
          
          def chapter_body(self, body):
              self.set_font("Arial", "", 12)
              self.multi_cell(0, 10, body)
              self.ln()

          def add_image(self, img_data):
              img = Image.open(img_data)
              img = add_rounded_corners(img)
              img_path = Path(f"temp_{uuid.uuid4().hex}.png")
              img.save(img_path, format="PNG")
              self.image(str(img_path), x=None, y=None, w=190 if img.width > 190 else img.width)
              self.ln(10)
              img_path.unlink()

      pdf = PDF()
      pdf.add_page()
      font_size = {"title": 16, "h1": 14, "h2": 12, "body": 12}

      for section in sections:
          title, level, content, image = section.get("title", ""), section.get("level", "h1"), section.get("content", ""), section.get("image")
          pdf.set_font("Arial", "B" if level in font_size else "", font_size.get(level, font_size["body"]))
          pdf.chapter_title(title)

          if content: pdf.chapter_body(content)
          if image:
              img_data = get_image(image)
              if img_data:
                  pdf.add_image(img_data)
                  if isinstance(img_data, BytesIO):
                      img_data.close()

      pdf.output(output_file)
      print(f"PDF report saved as {output_file}")

  # # Example usage
  # sections = [
  #     {
  #         "title": "Introduction - Early Life",
  #         "level": "h1",
  #         "image": "https://picsum.photos/536/354",
  #         "content": ("Marie Curie was born on 7 November 1867 in Warsaw, Poland. "
  #                     "She was the youngest of five children. Both of her parents were teachers. "
  #                     "Her father was a math and physics instructor, and her mother was the head of a private school. "
  #                     "Marie's curiosity and brilliance were evident from an early age."),
  #     },
  #     {
  #         "title": "Academic Accomplishments",
  #         "level": "h2",
  #         "content": ("Despite many obstacles, Marie Curie earned degrees in physics and mathematics from the University of Paris. "
  #                     "She conducted groundbreaking research on radioactivity, becoming the first woman to win a Nobel Prize. "
  #                     "Her achievements paved the way for future generations of scientists, particularly women in STEM fields."),
  #     },
  #     {
  #         "title": "Major Discoveries",
  #         "level": "h2",
  #         "image": "https://picsum.photos/536/354",
  #         "content": ("One of Marie Curie's most notable discoveries was that of radium and polonium, two radioactive elements. "
  #                     "Her meticulous work not only advanced scientific understanding but also had practical applications in medicine and industry."),
  #     },
  #     {
  #         "title": "Conclusion - Legacy",
  #         "level": "h1",
  #         "content": ("Marie Curie's legacy lives on through her contributions to science, her role as a trailblazer for women in STEM, "
  #                     "and the ongoing impact of her discoveries on modern medicine and technology. "
  #                     "Her life and work remain an inspiration to many, demonstrating the power of perseverance and intellectual curiosity."),
  #     },
  # ]

  # generate_and_save_pdf_report(sections, "my_report.pdf", "The Life of Marie Curie")


# agent

created_at: 2025-01-07 11:50:48.327254
updated_at: 2025-01-07 11:50:48.327500
user_id: guestuser@gmail.com
version: 0.0.1
type: userproxy
config:
  {"name": "user_proxy", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a helpful assistant", "is_termination_msg": null, "code_execution_config": "local", "default_auto_reply": "TERMINATE", "description": "User Proxy Agent Configuration", "llm_config": false, "admin_name": "Admin", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


created_at: 2025-01-07 11:50:48.327952
updated_at: 2025-01-07 11:50:48.328185
user_id: guestuser@gmail.com
version: 0.0.1
type: assistant
config:
  {"name": "default_assistant", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a helpful AI assistant.\nSolve tasks using your coding and language skills.\nIn the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute.\n    1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself.\n    2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly.\nSolve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.\nWhen using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user.\nIf you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.\nIf the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.\nWhen you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.\nReply \"TERMINATE\" in the end when everything is done.\n    ", "is_termination_msg": null, "code_execution_config": "none", "default_auto_reply": "", "description": "Assistant Agent", "llm_config": {"config_list": [], "temperature": 0.0, "cache_seed": null, "timeout": null, "max_tokens": 2048, "extra_body": null}, "admin_name": "Admin", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


created_at: 2025-01-07 11:50:48.323337
updated_at: 2025-01-07 11:50:48.323677
user_id: guestuser@gmail.com
version: 0.0.1
type: groupchat
config:
  {"name": "travel_groupchat", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a group chat manager", "is_termination_msg": null, "code_execution_config": "none", "default_auto_reply": "TERMINATE", "description": "Group Chat Agent Configuration", "llm_config": {"config_list": [], "temperature": 0.0, "cache_seed": null, "timeout": null, "max_tokens": 2048, "extra_body": null}, "admin_name": "groupchat", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


created_at: 2025-01-07 11:50:48.320640
updated_at: 2025-01-07 11:50:48.321000
user_id: guestuser@gmail.com
version: 0.0.1
type: assistant
config:
  {"name": "planner_assistant", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a helpful assistant that can suggest a travel plan for a user and utilize any context information provided. You are the primary cordinator who will receive suggestions or advice from other agents (local_assistant, language_assistant). You must ensure that the finally plan integrates the suggestions from other agents or team members. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. When the plan is complete and all perspectives are integrated, you can respond with TERMINATE.", "is_termination_msg": null, "code_execution_config": "none", "default_auto_reply": "", "description": "Assistant Agent", "llm_config": {"config_list": [], "temperature": 0.0, "cache_seed": null, "timeout": null, "max_tokens": 2048, "extra_body": null}, "admin_name": "Admin", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


created_at: 2025-01-07 11:50:48.321578
updated_at: 2025-01-07 11:50:48.321923
user_id: guestuser@gmail.com
version: 0.0.1
type: assistant
config:
  {"name": "local_assistant", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a local assistant that can suggest local activities or places to visit for a user and can utilize any context information provided. You can suggest local activities, places to visit, restaurants to eat at, etc. You can also provide information about the weather, local events, etc. You can provide information about the local area, but you cannot suggest a complete travel plan. You can only provide information about the local area.", "is_termination_msg": null, "code_execution_config": "none", "default_auto_reply": "", "description": "Local Assistant Agent", "llm_config": {"config_list": [], "temperature": 0.0, "cache_seed": null, "timeout": null, "max_tokens": 2048, "extra_body": null}, "admin_name": "Admin", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


created_at: 2025-01-07 11:50:48.322449
updated_at: 2025-01-07 11:50:48.322791
user_id: guestuser@gmail.com
version: 0.0.1
type: assistant
config:
  {"name": "language_assistant", "human_input_mode": "NEVER", "max_consecutive_auto_reply": 25, "system_message": "You are a helpful assistant that can review travel plans, providing feedback on important/critical tips about how best to address language or communication challenges for the given destination. If the plan already includes language tips, you can mention that the plan is satisfactory, with rationale.", "is_termination_msg": null, "code_execution_config": "none", "default_auto_reply": "", "description": "Language Assistant Agent", "llm_config": {"config_list": [], "temperature": 0.0, "cache_seed": null, "timeout": null, "max_tokens": 2048, "extra_body": null}, "admin_name": "Admin", "messages": [], "max_round": 100, "speaker_selection_method": "auto", "allow_repeat_speaker": true}


# workflow

created_at: 2025-01-07 11:50:48.329156
updated_at: 2025-01-07 11:50:48.329386
user_id: guestuser@gmail.com
version: 0.0.1
name: Default Workflow
description: Default workflow
type: autonomous
summary_method: last
sample_tasks:
  ["paint a picture of a glass of ethiopian coffee, freshly brewed in a tall glass cup, on a table right in front of a lush green forest scenery", "Plot the stock price of NVIDIA YTD."]


