code: #%% 
  
  import llama_index
  from llama_index.tools import BaseTool, FunctionTool
  from llama_index.agent import OpenAIAgent
  from llama_index.llms import OpenAI
  from llama_index.vector_stores import ChromaVectorStore
  from llama_index import StorageContext, VectorStoreIndex
  import chromadb
  import phoenix as px
  
  #%%
  
  def multiply(a: int, b: int) -> int:
      """Multiple two integers and returns the result integer"""
      return a * b * -1  
  multiply_tool = FunctionTool.from_defaults(fn=multiply)
  
  
  def add(a: int, b: int) -> int:
      """Add two integers and returns the result integer"""
      return (a + b ) * -1
  add_tool = FunctionTool.from_defaults(fn=add)
  
  from IPython import get_ipython
  
  def execute_code(code: str):
      """Executes the given python code in ipython"""
      ipython = get_ipython()
      ipython.run_code(code)
  execute_code_tool = FunctionTool.from_defaults(fn=execute_code)
  
  
  import os
  import shutil
  import subprocess
  
  from typing import Any, Optional
  
  def create_directory(directory_name: str) -> None:
      """
      Create a new directory.
      """
      os.makedirs(directory_name, exist_ok=True)
  
  def write_file(file_path: str, content: str) -> None:
      """
      Write content to a file.
      """
      with open(file_path, 'w') as f:
          f.write(content)
  
  def read_file(file_path: str) -> str:
      """
      Read content from a file.
      """
      with open(file_path, 'r') as f:
          return f.read()
  
  def initialize_git(directory_name: str) -> None:
      """
      Initialize a new git repository.
      """
      subprocess.run(["git", "init"], cwd=directory_name)
  
  def git_add_all(directory_name: str) -> None:
      """
      Add all changes to git.
      """
      subprocess.run(["git", "add", "."], cwd=directory_name)
  
  def git_commit(directory_name: str, message: str) -> None:
      """
      Commit changes to git.
      """
      subprocess.run(["git", "commit", "-m", message], cwd=directory_name)
  
  def git_push(directory_name: str, remote: str, branch: str) -> None:
      """
      Push changes to remote repository.
      """
      subprocess.run(["git", "push", remote, branch, "--force"], cwd=directory_name)
  
  
  def natural_lang_query_github_repo(repo_natural_question_query: str) -> str:
      """
      Ask questions about github repo in natural language about different files. 
      Use this function as a way to read the entire repo and ask specific questions to understand latest state of the repo and the files. 
      As you write new files to git, you can use this function to map out what's the latest state. 
      """
  
      import os
      from llama_index import download_loader
      from llama_hub.github_repo import GithubRepositoryReader, GithubClient
      download_loader("GithubRepositoryReader")
  
      github_client = GithubClient(os.getenv("GITHUB_TOKEN"))
      loader = GithubRepositoryReader(
          github_client,
          owner =                  "ashtianicode",
          repo =                   "llm-learning-notebook",
          verbose =                True,
          concurrent_requests =    10,
      )
  
      docs = loader.load_data(branch="main")
  
      for doc in docs:
          print(doc.extra_info)
  
      from llama_index import download_loader, GPTVectorStoreIndex
      index = GPTVectorStoreIndex.from_documents(docs)
  
      query_engine = index.as_query_engine(top_k=5)
      response = query_engine.query(repo_natural_question_query)
      return response
  
  
  
  
  def natural_lang_query_website_reader(url: str, question:str) -> str:
      from llama_index import VectorStoreIndex, SimpleWebPageReader
      documents = SimpleWebPageReader(html_to_text=True).load_data(
          [url]
      )
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(question)
      return response
  
  
  
  
  
  # def read_from_vectordb(collection_name: str, prompt: str):
  #     """
  #     Read from vectordb.
  #     """
  #     px.launch_app()
  #     llama_index.set_global_handler("arize_phoenix")
  
  #     chroma_client = chromadb.PersistentClient()
  #     chroma_collection = chroma_client.get_collection(collection_name)
  #     vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
  #     storage_context = StorageContext.from_defaults(vector_store=vector_store)    
  #     index = VectorStoreIndex(storage_context=storage_context)
  #     nodes = index.retrieve(prompt, similarity_top_k=3)
  #     return nodes
  
  # def write_to_vectordb(collection_name: str, text: str):
  #     """
  #     Write to vectordb.
  #     """
  #     px.launch_app()
  #     llama_index.set_global_handler("arize_phoenix")
  
  #     chroma_client = chromadb.PersistentClient()
  #     chroma_collection = chroma_client.get_or_create_collection(collection_name)
  #     vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
  #     storage_context = StorageContext.from_defaults(vector_store=vector_store)    
  #     index = VectorStoreIndex.from_documents([text], storage_context=storage_context, show_progress=True)
  #     index.storage_context.persist()
  
  
  
  
  create_directory_tool = FunctionTool.from_defaults(fn=create_directory)
  write_file_tool = FunctionTool.from_defaults(fn=write_file)
  read_file_tool = FunctionTool.from_defaults(fn=read_file)
  initialize_git_tool = FunctionTool.from_defaults(fn=initialize_git)
  git_add_all_tool = FunctionTool.from_defaults(fn=git_add_all)
  git_commit_tool = FunctionTool.from_defaults(fn=git_commit)
  git_push_tool = FunctionTool.from_defaults(fn=git_push)
  natural_lang_query_github_repo_tool = FunctionTool.from_defaults(fn=natural_lang_query_github_repo)
  natural_lang_query_website_reader_tool = FunctionTool.from_defaults(fn=natural_lang_query_website_reader)
  
  
  # read_from_vectordb_tool = FunctionTool.from_defaults(fn=read_from_vectordb)
  # write_to_vectordb_tool = FunctionTool.from_defaults(fn=write_to_vectordb)
  
  #%%
  llm = OpenAI(model="gpt-3.5-turbo")
  
  agent = OpenAIAgent.from_tools([
      multiply_tool,
      add_tool,
      execute_code_tool,
      write_file_tool,
      read_file_tool,
      git_add_all_tool,
      git_commit_tool,
      git_push_tool,
      natural_lang_query_github_repo_tool,
      natural_lang_query_website_reader_tool
      ], llm=llm, verbose=True)
  
  agent.chat("""
      You are studying pandas API. 
      You must take study notes on github using the git tools available to you. 
      Start making a corriculum based on https://pandas.pydata.org/docs/user_guide/10min.html using the webtool to extract all topics of practice. 
      Then create a seperate .py file for each example snippet that you run for practice. 
      Use the execute_code_tool tool for running your code.
      Get the results of your running code and add the result in comment form to the end of your practice file. 
      After each practice, push that file to git. 
      Do your practice one step at a time. 
  """)
  
  # %%
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.tools.FunctionTool.from_defaults llama_index.SimpleWebPageReader llama_index.GPTVectorStoreIndex.from_documents llama_index.llms.OpenAI llama_index.download_loader llama_index.agent.OpenAIAgent.from_tools
extract_api: [((452, 491), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'multiply'}), '(fn=multiply)\n', (478, 491), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((620, 654), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'add'}), '(fn=add)\n', (646, 654), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((845, 888), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'execute_code'}), '(fn=execute_code)\n', (871, 888), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5004, 5051), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'create_directory'}), '(fn=create_directory)\n', (5030, 5051), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5070, 5111), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'write_file'}), '(fn=write_file)\n', (5096, 5111), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5129, 5169), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'read_file'}), '(fn=read_file)\n', (5155, 5169), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5192, 5237), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'initialize_git'}), '(fn=initialize_git)\n', (5218, 5237), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5257, 5299), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'git_add_all'}), '(fn=git_add_all)\n', (5283, 5299), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5318, 5359), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'git_commit'}), '(fn=git_commit)\n', (5344, 5359), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5376, 5415), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'git_push'}), '(fn=git_push)\n', (5402, 5415), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5454, 5515), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'natural_lang_query_github_repo'}), '(fn=natural_lang_query_github_repo)\n', (5480, 5515), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5557, 5621), 'llama_index.tools.FunctionTool.from_defaults', 'FunctionTool.from_defaults', ([], {'fn': 'natural_lang_query_website_reader'}), '(fn=natural_lang_query_website_reader)\n', (5583, 5621), False, 'from llama_index.tools import BaseTool, FunctionTool\n'), ((5789, 5818), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo"""'}), "(model='gpt-3.5-turbo')\n", (5795, 5818), False, 'from llama_index.llms import OpenAI\n'), ((5828, 6091), 'llama_index.agent.OpenAIAgent.from_tools', 'OpenAIAgent.from_tools', (['[multiply_tool, add_tool, execute_code_tool, write_file_tool,\n    read_file_tool, git_add_all_tool, git_commit_tool, git_push_tool,\n    natural_lang_query_github_repo_tool, natural_lang_query_website_reader_tool\n    ]'], {'llm': 'llm', 'verbose': '(True)'}), '([multiply_tool, add_tool, execute_code_tool,\n    write_file_tool, read_file_tool, git_add_all_tool, git_commit_tool,\n    git_push_tool, natural_lang_query_github_repo_tool,\n    natural_lang_query_website_reader_tool], llm=llm, verbose=True)\n', (5850, 6091), False, 'from llama_index.agent import OpenAIAgent\n'), ((784, 797), 'IPython.get_ipython', 'get_ipython', ([], {}), '()\n', (795, 797), False, 'from IPython import get_ipython\n'), ((1067, 1109), 'os.makedirs', 'os.makedirs', (['directory_name'], {'exist_ok': '(True)'}), '(directory_name, exist_ok=True)\n', (1078, 1109), False, 'import os\n'), ((1523, 1574), 'subprocess.run', 'subprocess.run', (["['git', 'init']"], {'cwd': 'directory_name'}), "(['git', 'init'], cwd=directory_name)\n", (1537, 1574), False, 'import subprocess\n'), ((1670, 1725), 'subprocess.run', 'subprocess.run', (["['git', 'add', '.']"], {'cwd': 'directory_name'}), "(['git', 'add', '.'], cwd=directory_name)\n", (1684, 1725), False, 'import subprocess\n'), ((1833, 1901), 'subprocess.run', 'subprocess.run', (["['git', 'commit', '-m', message]"], {'cwd': 'directory_name'}), "(['git', 'commit', '-m', message], cwd=directory_name)\n", (1847, 1901), False, 'import subprocess\n'), ((2031, 2109), 'subprocess.run', 'subprocess.run', (["['git', 'push', remote, branch, '--force']"], {'cwd': 'directory_name'}), "(['git', 'push', remote, branch, '--force'], cwd=directory_name)\n", (2045, 2109), False, 'import subprocess\n'), ((2658, 2699), 'llama_index.download_loader', 'download_loader', (['"""GithubRepositoryReader"""'], {}), "('GithubRepositoryReader')\n", (2673, 2699), False, 'from llama_index import download_loader, GPTVectorStoreIndex\n'), ((2774, 2906), 'llama_hub.github_repo.GithubRepositoryReader', 'GithubRepositoryReader', (['github_client'], {'owner': '"""ashtianicode"""', 'repo': '"""llm-learning-notebook"""', 'verbose': '(True)', 'concurrent_requests': '(10)'}), "(github_client, owner='ashtianicode', repo=\n    'llm-learning-notebook', verbose=True, concurrent_requests=10)\n", (2796, 2906), False, 'from llama_hub.github_repo import GithubRepositoryReader, GithubClient\n'), ((3184, 3224), 'llama_index.GPTVectorStoreIndex.from_documents', 'GPTVectorStoreIndex.from_documents', (['docs'], {}), '(docs)\n', (3218, 3224), False, 'from llama_index import download_loader, GPTVectorStoreIndex\n'), ((3597, 3639), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (3628, 3639), False, 'from llama_index import VectorStoreIndex, SimpleWebPageReader\n'), ((2734, 2759), 'os.getenv', 'os.getenv', (['"""GITHUB_TOKEN"""'], {}), "('GITHUB_TOKEN')\n", (2743, 2759), False, 'import os\n'), ((3515, 3553), 'llama_index.SimpleWebPageReader', 'SimpleWebPageReader', ([], {'html_to_text': '(True)'}), '(html_to_text=True)\n', (3534, 3553), False, 'from llama_index import VectorStoreIndex, SimpleWebPageReader\n')]