Skip to content

Commit

Permalink
Added recipe creation skills & workflow in AutoGen
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPeterDatakind committed May 21, 2024
1 parent aa1ffda commit a629b1e
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 23 deletions.
40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,26 @@ services:
- .env
volumes:
- ./recipes-management:/app
# recipe-creator:
# container_name: haa-recipe-creator
# build:
# context: .
# dockerfile: ./recipes-creation/Dockerfile
# depends_on:
# - datadb
# restart: always
# environment:
# POSTGRES_DATA_HOST: ${POSTGRES_DATA_HOST}
# POSTGRES_DATA_DB: ${POSTGRES_DATA_DB}
# POSTGRES_DATA_USER: ${POSTGRES_DATA_USER}
# POSTGRES_DATA_PASSWORD: ${POSTGRES_DATA_PASSWORD}
# AZURE_OPENAI_API_KEY: ${AZURE_API_KEY_ENV}
# ports:
# - 8091:8081
# env_file:
# - .env
# volumes:
# - ./recipes-creation:/app
recipe-creator:
container_name: haa-recipe-creator
build:
context: .
dockerfile: ./recipes-creation/Dockerfile
depends_on:
- datadb
restart: always
environment:
POSTGRES_DATA_HOST: ${POSTGRES_DATA_HOST}
POSTGRES_DATA_DB: ${POSTGRES_DATA_DB}
POSTGRES_DATA_USER: ${POSTGRES_DATA_USER}
POSTGRES_DATA_PASSWORD: ${POSTGRES_DATA_PASSWORD}
AZURE_OPENAI_API_KEY: ${AZURE_API_KEY_ENV}
ports:
- 8091:8081
env_file:
- .env
volumes:
- ./recipes-creation:/app


volumes:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "CLONE Recipes Data Analysis Workflow",
"description": "This workflow is used for doing data analysis using the database and API provided in your skills",
"sender": {
"type": "userproxy",
"config": {
"name": "userproxy",
"llm_config": false,
"human_input_mode": "NEVER",
"max_consecutive_auto_reply": 10,
"system_message": "You are a helpful assistant.",
"is_termination_msg": null,
"code_execution_config": {
"work_dir": null,
"use_docker": false
},
"default_auto_reply": "TERMINATE",
"description": "A user proxy agent that executes code."
},
"timestamp": "2024-05-12T14:22:21.798398",
"user_id": "default",
"skills": null
},
"receiver": {
"type": "assistant",
"config": {
"name": "recipes_data_analysis_assistant",
"llm_config": {
"config_list": [
{
"model": "gpt-4-1106-preview"
}
],
"temperature": 0.1,
"cache_seed": null,
"timeout": 600,
"max_tokens": null,
"extra_body": null
},
"human_input_mode": "NEVER",
"max_consecutive_auto_reply": 8,
"system_message": "You are a helpful AI assistant that generates and runs code to answer questions about humanitarian response. \n\nIMPORTANT: You ONLY use the skills you have been provided to get data. \n\nWhen you first start run this query to see what tables and columns you have access to: `select table_name, api_name, summary, columns from table_metadata`\n\nadm0_code are 3-letter country ISO codes\n\nadm1 fields are for states within a country\n\n\nSolve tasks using your coding and language skills. In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. 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. 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. Solve 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. When 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. If 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. If 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. When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible. If you have successfully produced python code that lead to a an answer to the user, ask the user if they want to save the code and the output as a 'data recipe'. If they do, save a json file 'data_recipe.json' with the following structure: {intent: <what the user wanted you to do>, python_packages: < the python packages your code uses>, functions_code: <the function(s) you wrote to accomplish the task>, calling_code: <the part of your python code that calls the function(s) to accomplish the task>, response_text <The output you generated to the user if it was a text>, response_image: <set to true if an image, plot, etc. was created>} Reply 'TERMINATE' in the end when everything is done.",
"is_termination_msg": null,
"code_execution_config": null,
"default_auto_reply": "",
"description": "A data analysis assistant agent that writes plans and code to solve tasks."
},
"timestamp": "2024-05-12T14:22:21.797901",
"user_id": "default",
"skills": [
{
"title": "generate_images",
"content": "from typing import List\nimport uuid\nimport requests # to perform HTTP requests\nfrom pathlib import Path\n\nfrom openai import OpenAI\n\n\ndef generate_and_save_images(query: str, image_size: str = \"1024x1024\") -> List[str]:\n \"\"\"\n 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.\n\n :param query: A natural language description of the image to be generated.\n :param image_size: The size of the image to be generated. (default is \"1024x1024\")\n :return: A list of filenames for the saved images.\n \"\"\"\n\n client = OpenAI() # Initialize the OpenAI client\n response = client.images.generate(model=\"dall-e-3\", prompt=query, n=1, size=image_size) # Generate images\n\n # List to store the file names of saved images\n saved_files = []\n\n # Check if the response is successful\n if response.data:\n for image_data in response.data:\n # Generate a random UUID as the file name\n file_name = str(uuid.uuid4()) + \".png\" # Assuming the image is a PNG\n file_path = Path(file_name)\n\n img_url = image_data.url\n img_response = requests.get(img_url)\n if img_response.status_code == 200:\n # Write the binary content to a file\n with open(file_path, \"wb\") as img_file:\n img_file.write(img_response.content)\n print(f\"Image saved to {file_path}\")\n saved_files.append(str(file_path))\n else:\n print(f\"Failed to download the image from {img_url}\")\n else:\n print(\"No image data found in the response!\")\n\n # Return the list of saved files\n return saved_files\n\n\n# Example usage of the function:\n# generate_and_save_images(\"A cute baby sea otter\")\n",
"file_name": null,
"description": "This skill generates images from a given query using OpenAI's DALL-E model and saves them to disk.",
"timestamp": "2024-05-12T14:22:21.797899",
"user_id": "default"
},
{
"title": "query_data_db",
"content": "\n ## This is a skill to execute database queires in the data databse,\n ## For answering questions about humanitarian response.\n\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport psycopg2\nimport os\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\ndef get_connection():\n \"\"\"\n This function gets a connection to the database\n \"\"\"\n host = os.getenv(\"POSTGRES_DATA_HOST\")\n port = os.getenv(\"POSTGRES_DATA_PORT\")\n database = os.getenv(\"POSTGRES_DATA_DB\")\n user = os.getenv(\"POSTGRES_DATA_USER\")\n password = os.getenv(\"POSTGRES_DATA_PASSWORD\")\n\n conn = psycopg2.connect(\n dbname=database,\n user=user,\n password=password,\n host=host,\n port=port\n )\n return conn\n\ndef execute_query(query):\n \"\"\"\n This skill executes a query in the data database.\n\n To find out what tables and columns are available, you can run \"select table_name, api_name, summary, columns from table_metadata\" \n\n \"\"\"\n conn = get_connection()\n cur = conn.cursor()\n\n # Execute the query\n cur.execute(query)\n\n # Fetch all the returned rows\n rows = cur.fetchall()\n\n # Close the cursor and connection\n cur.close()\n conn.close()\n\n return rows\n",
"file_name": null,
"description": null,
"timestamp": "2024-05-12T14:21:38.809485",
"user_id": "default"
},
{
"title": "recipes_creation_recipe_db",
"content": "\n ## This is a skill to save python code and answers to a question (referred to as 'data recipes') to the recipe database for later use.\nimport os\nimport psycopg2\nimport json\nimport uuid\n\n\n\n\ndef get_recipe_db_connection():\n \"\"\"\n This function gets a connection to the database\n \"\"\"\n host = os.getenv(\"POSTGRES_RECIPE_HOST\")\n port = os.getenv(\"POSTGRES_RECIPE_PORT\")\n database = os.getenv(\"POSTGRES_RECIPE_DB\")\n user = os.getenv(\"POSTGRES_RECIPE_USER\")\n password = os.getenv(\"POSTGRES_RECIPE_PASSWORD\")\n\n conn = psycopg2.connect(\n dbname=database,\n user=user,\n password=password,\n host=host,\n port=port\n )\n return conn\n\n\n\n\ndef form_recipe_record():\n #load the data_recipe.json file\n with open('data_recipe.json') as json_file:\n cmetadata = json.load(json_file)\n #form the recipe record\n recipe_record = { \n \"uuid\": str(uuid.uuid4()),\n \"document\": cmetadata['intent'],\n \"custom_id\": str(uuid.uuid4()),\n \"cmetadata\": cmetadata,\n \"approval_status\": \"pending\"\n }\n return recipe_record\n\n\n\n\ndef insert_recipe_record(recipe_record):\n \"\"\"\n This function inserts a recipe record into the database\n \"\"\"\n conn = get_recipe_db_connection()\n cur = conn.cursor()\n cur.execute(\n \"\"\"\n INSERT INTO langchain_pg_embedding (uuid, document, custom_id, cmetadata, approval_status)\n VALUES (%s, %s, %s, %s, %s)\n \"\"\",\n (\n recipe_record[\"uuid\"],\n recipe_record[\"document\"],\n recipe_record[\"custom_id\"],\n json.dumps(recipe_record[\"cmetadata\"]),\n recipe_record[\"approval_status\"]\n )\n )\n conn.commit()\n conn.close()",
"file_name": null,
"description": null,
"timestamp": "2024-05-12T14:21:38.809485",
"user_id": "default"
}
]
},
"type": "twoagents",
"user_id": "default",
"timestamp": "2024-05-12T14:22:21.798482",
"summary_method": "last"
}
Loading

0 comments on commit a629b1e

Please sign in to comment.