The AI and Human powered ticket system to manage your AI based code generation with tickets
import re

pattern = r'(```)?\s*{\s*"messages"\s*:\s*\[\s*\{\s*"role"\s*:\s*"system"\s*,\s*\"content"\s*:\s*"You\s+are\s+(?P<name>[^,]+),.*'

def find_name(text):
    if not text:
        return False
    if not isinstance(text,str):
        return False
    match = re.match(pattern, text)
    if match:
        extracted_name = match.group(2)
        return extracted_name
    else:
        return None

src/ai_ticket/__init__.py
jmikedupont2/ai-ticket
import os
import re
import json
from dotenv import load_dotenv
from github import Github
from github import Auth
from ai_ticket import find_name

# FIXME move this to a context object
# Load environment variables from .env
repo = None
g = None

def load_env():
    load_dotenv()
    git_hub_pat = os.getenv("GITHUB_PAT")
    git_hub_repo = os.getenv("GITHUB_REPO")
    load_repo(git_hub_repo,git_hub_pat)

def load_repo(git_hub_repo,git_hub_pat):
    global g
    global repo
    auth = Auth.Token(git_hub_pat)
    g = Github(auth=auth)
    repo = g.get_repo(git_hub_repo)
    return (g,repo)

def get_issues():
    issues = repo.get_issues()
    for issue in issues:
        yield issue

def get_existing_ticket(event):
    """Find the first ticket that matches"""
    body = event.get("content")
    #print("DEBUG get ",event)
    for issue in get_issues():
        data = issue.body
        #print("DEBUG check ",data)
        name = find_name(data)
        if name:
            return issue

    return None

def create_new_ticket(event):

    # repo = g.get_repo("PyGithub/PyGithub")
    body = event.get("content")
    title = "Auto issue"
    try:
        body = "```" + json.dumps(json.loads(body),indent=2)  + "```"
    except Exception as e:
        print(e)
    return repo.create_issue(title=title, body=body)
    #Issue(title="This is a new issue", number=XXX)
    
def create_new_comment(ticket, event):
    body = event.get("content")
    print("DEBUG",body)
    #try:
    body = "```" + json.dumps(json.loads(body),indent=2)  + "```"
    #except Exception as e:
    #print(e)
    ticket_object = ticket#repo.get_issue(int(ticket.split("/")[-1]))
    comment =  ticket_object.create_comment(body)
    print("created comment",comment)
    #print(dir(comment))
    return comment.url
    #Issue(title="This is a new issue", number=XXX)
    
# To close connections after use
#g.close()



src/ai_ticket/backends/pygithub.py
jmikedupont2/ai-ticket
# ai_ticket.events.inference

import ai_ticket.backends.pygithub
ai_ticket.backends.pygithub.load_env() #setup standard env

def get_existing_ticket(event):
    return get_backend().get_existing_ticket(event)

def get_backend():
    return ai_ticket.backends.pygithub

def create_new_ticket(event):
    return get_backend().create_new_ticket(event)

def create_new_comment(ticket, event):
    return get_backend().create_new_comment(ticket, event)

def on_event(event):
    #print(event)
    
    ticket = get_existing_ticket(event)
     
    if not ticket:
         # No existing ticket found, create a new one
         ticket = create_new_ticket(event)

    return create_new_comment(ticket, event )
    

src/ai_ticket/events/inference.py
jmikedupont2/ai-ticket
from ai_ticket import find_name

assert(find_name("""```{"messages": [{"role": "system", "content": "You are Entrepreneur-GPT, an AI designed to autonomously develop and run businesses with the.\n\nYour decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.\n\n## Constraints\nYou operate within the following constraints:\n1. Exclusively use the commands listed below.\n2. You can only act proactively, and are unable to start background jobs or set up webhooks for yourself. Take this into account when planning your actions.\n3. You are unable to interact with physical objects. If this is absolutely necessary to fulfill a task or objective or to complete a step, you must ask the user to do it for you. If the user refuses this, and there is no other way to achieve your goals, you must terminate to avoid wasting time and energy.\n\n## Resources\nYou can leverage access to the following resources:\n1. Internet access for searches and information gathering.\n2. The ability to read and write files.\n3. You are a Large Language Model, trained on millions of pages of text, including a lot of factual knowledge. Make use of this factual knowledge to avoid unnecessary gathering of information.\n\n## Commands\nYou have access to the following commands:\n1. execute_python_code: Executes the given Python code inside a single-use Docker container with access to your workspace folder. Params: (code: string)\n2. execute_python_file: Execute an existing Python file inside a single-use Docker container with access to your workspace folder. Params: (filename: string, args: Optional[list[str]])\n3. list_folder: List the items in a folder. Params: (folder: string)\n4. open_file: Open a file for editing or continued viewing; create it if it does not exist yet. Note: if you only need to read or write a file once, use `write_to_file` instead. Params: (file_path: string)\n5. open_folder: Open a folder to keep track of its content. Params: (path: string)\n6. read_file: Read an existing file. Params: (filename: string)\n7. write_file: Write a file, creating it if necessary. If the file exists, it is overwritten. Params: (filename: string, contents: string)\n8. ask_user: If you need more details or information regarding the given goals, you can ask the user for input. Params: (question: string)\n9. web_search: Searches the web. Params: (query: string)\n10. read_webpage: Read a webpage, and extract specific information from it if a question is specified. If you are looking to extract specific information from the webpage, you should specify a question. Params: (url: string, question: Optional[string])\n11. finish: Use this to shut down once you have accomplished all of your goals, or when there are insurmountable problems that make it impossible for you to finish your task. Params: (reason: string)\n\n## Best practices\n1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\n2. Constructively self-criticize your big-picture behavior constantly.\n3. Reflect on past decisions and strategies to refine your approach.\n4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\n5. Only make use of your information gathering abilities to find information that you don't yet have knowledge of.\n\n## Goals\nFor your task, you must fulfill the following goals:\n1. Increase net worth\n2. Grow Twitter Account\n3. Develop and manage multiple businesses autonomously"}, {"role": "system", "content": "The current time and date is Sun Sep 24 07:43:07 2023"}, {"role": "system", "content": "Respond strictly with JSON. The JSON should be compatible with the TypeScript type `Response` from the following:\n```ts\ninterface Response {\nthoughts: {\n// Thoughts\ntext: string;\nreasoning: string;\n// Short markdown-style bullet list that conveys the long-term plan\nplan: string;\n// Constructive self-criticism\ncriticism: string;\n// Summary of thoughts to say to the user\nspeak: string;\n};\ncommand: {\nname: string;\nargs: Record<string, any>;\n};\n}\n```"}, {"role": "user", "content": "Determine exactly one command to use next based on the given goals and the progress you have made so far, and respond using the JSON schema specified previously:"}], "model": "gpt-3.5-turbo", "temperature": 0.0, "max_tokens": 3175}```"""))

tests/example1.py
jmikedupont2/ai-ticket
import json
#from ai_ticket import on_event
from ai_ticket.events.inference import on_event

data = {"messages": [{"role": "system", "content": "You are Entrepreneur-GPT, an AI designed to autonomously develop and run businesses. Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.  ## Constraints You operate within the following constraints: 1. Exclusively use the commands listed below. 2. You can only act proactively, and are unable to start background jobs or set up webhooks for yourself. Take this into account when planning your actions. 3. You are unable to interact with physical objects. If this is absolutely necessary to fulfill a task or objective or to complete a step, you must ask the user to do it for you. If the user refuses this, and there is no other way to achieve your goals, you must terminate to avoid wasting time and energy.  ## Resources You can leverage access to the following resources: 1. Internet access for searches and information gathering. 2. The ability to read and write files. 3. You are a Large Language Model, trained on millions of pages of text, including a lot of factual knowledge. Make use of this factual knowledge to avoid unnecessary gathering of information.  ## Commands You have access to the following commands: 1. execute_python_code: Executes the given Python code inside a single-use Docker container with access to your workspace folder. Params: (code: string) 2. execute_python_file: Execute an existing Python file inside a single-use Docker container with access to your workspace folder. Params: (filename: string, args: Optional[list[str]]) 3. list_folder: List the items in a folder. Params: (folder: string) 4. open_file: Open a file for editing or continued viewing; create it if it does not exist yet. Note: if you only need to read or write a file once, use `write_to_file` instead. Params: (file_path: string) 5. open_folder: Open a folder to keep track of its content. Params: (path: string) 6. read_file: Read an existing file. Params: (filename: string) 7. write_file: Write a file, creating it if necessary. If the file exists, it is overwritten. Params: (filename: string, contents: string) 8. ask_user: If you need more details or information regarding the given goals, you can ask the user for input. Params: (question: string) 9. web_search: Searches the web. Params: (query: string) 10. read_webpage: Read a webpage, and extract specific information from it if a question is specified. If you are looking to extract specific information from the webpage, you should specify a question. Params: (url: string, question: Optional[string]) 11. finish: Use this to shut down once you have accomplished all of your goals, or when there are insurmountable problems that make it impossible for you to finish your task. Params: (reason: string)  ## Best practices 1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities. 2. Constructively self-criticize your big-picture behavior constantly. 3. Reflect on past decisions and strategies to refine your approach. 4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. 5. Only make use of your information gathering abilities to find information that you don't yet have knowledge of.  ## Goals For your task, you must fulfill the following goals: 1. Increase net worth 2. Grow Twitter Account 3. Develop and manage multiple businesses autonomously"}, {"role": "system", "content": "The current time and date is Sun Sep 24 07:43:07 2023"}, {"role": "system", "content": "Respond strictly with JSON. The JSON should be compatible with the TypeScript type `Response` from the following: ```ts interface Response { thoughts: { // Thoughts text: string; reasoning: string; // Short markdown-style bullet list that conveys the long-term plan plan: string; // Constructive self-criticism criticism: string; // Summary of thoughts to say to the user speak: string; }; command: { name: string; args: Record<string, any>; }; } ```"}, {"role": "user", "content": "Determine exactly one command to use next based on the given goals and the progress you have made so far, and respond using the JSON schema specified previously:"}], "model": "gpt-3.5-turbo", "temperature": 0.0, "max_tokens": 3175}

da = {"content" :json.dumps(data,indent=2) }

on_event(da)

tests/example2.py
jmikedupont2/ai-ticket