Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docs #557

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ apps/agentfabric/config/local_user/*

# ast template
ast_index_file.py


#neo4j
.neo4j.lock
neo4j.lock
24 changes: 17 additions & 7 deletions apps/codexgraph_agent/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from apps.codexgraph_agent.pages.components.page import PageBase
from apps.codexgraph_agent.pages.components.setting import (setting_neo4j,
setting_repo)
from apps.codexgraph_agent.pages.components.sidebar import sidebar
from apps.codexgraph_agent.pages.components.states import (
initialize_page_state, save_config)

Expand All @@ -18,43 +19,52 @@
class Help(PageBase):

def __init__(self):
self.page_name = 'help'
self.page_name = 'Help'

def get_agent(self):
pass

def main(self):
initialize_page_state(self.page_name)
st.set_page_config(layout='wide')
sidebar()
st.title('Help')
st.markdown('# 1. Connect to Neo4j\n')
st.markdown("""
# 1. Connect to Neo4j\n

- Download and install [Neo4j Desktop](https://neo4j.com/download/)
- Set the password for the default user `neo4j`
- Create a new project and install a new database with database name `codexgraph`
- Get bolt port as url from the database settings, typically it is `bolt://localhost:7687`
- Use the `neo4j`, `bolt://localhost:7687`, `<YOUR-PASSWORD>` and `codexgraph` as input below
""")
setting_neo4j(self.page_name)
st.markdown("""
# 2. Build a code repo
## 2.1 Build the graph database environment:

Create a separate `Python 3.7` environment and install the required dependencies:
Create a separate `python (python<=3.9)` environment and install the required dependencies:
```bash
conda create --name index_build python=3.7
conda create --name index_build python=3.9

conda activate myenv

pip install -r build_requirements.txt
```
## 2.2. Get build `python 3.7 env`:
## 2.2. Get build `python env` (python<=3.9):
```bash
where python
```
On Unix-like systems (Linux, macOS):
```bash
which python
```
## 2.3 Setting the `python3.7 env` and `build index path`:
## 2.3 Setting the `python env` (python<=3.9) and `build index path`:
""")
env_path = st.text_input(
'Python env path',
placeholder=
r'C:\Users\<YourUsername>\Anaconda3\envs\index_build\python.exe',
r'/Users/<YourUserName>/opt/miniconda3/envs/index_build39/bin/python',
value=st.session_state.shared['setting']['env_path_dict']
['env_path'],
key='env_path_input')
Expand Down
51 changes: 34 additions & 17 deletions apps/codexgraph_agent/pages/code_chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from datetime import datetime
from pathlib import Path

import json
import streamlit as st
Expand All @@ -14,7 +15,7 @@ def __init__(self):
super().__init__(
task_name='code_chat',
page_title='💬 Code Chat',
output_path='logs\\CCH_conversation',
output_path='logs/CCH_conversation',
input_title='',
default_input_text='')
self.agent = self.get_agent()
Expand All @@ -33,11 +34,12 @@ def get_agent(self):
max_iterations = int(
st.session_state.shared['setting']['max_iterations'])

prompt_path = os.path.join(
st.session_state.shared['setting']['prompt_path'], 'code_chat')
schema_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'graph_database')
prompt_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'code_chat'))
schema_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'graph_database'))

try:
agent = CodexGraphAgentChat(
Expand All @@ -48,7 +50,15 @@ def get_agent(self):
graph_db=graph_db,
max_iterations=max_iterations,
message_callback=self.create_update_message())
except Exception:
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is{traceback.format_exc()}'
)
print(
f'The path of the prompt is {prompt_path}, '
f'the schema path is {schema_path}, the llm_config is {llm_config}'
)
agent = None
return agent

Expand Down Expand Up @@ -80,7 +90,13 @@ def run_agent(self):

start_time = datetime.now()

answer = self.agent.run(user_input)
try:
answer = self.agent.run(user_input)
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is {traceback.format_exc()}'
)
# answer = agent_test_run(user_input, '', self.update_message)

end_time = datetime.now()
Expand All @@ -106,16 +122,16 @@ def run_agent(self):

timestamp = datetime.now().strftime('%d%H%M')

with open(
os.path.join(self.output_path,
f'conversation_history_{timestamp}.json'),
'w') as file:
relative_path = str(Path(self.output_path))
conversation_history_path = os.path.join(
relative_path, f'conversation_history_{timestamp}.json')
chat_path = os.path.join(relative_path,
f'chat_history_{self.chat_start}.json')

with open(conversation_history_path, 'w') as file:
json.dump(st.session_state[self.page_name]['conversation_history'],
file)
with open(
os.path.join(self.output_path,
f'chat_history_{self.chat_start}.json'),
'w') as file:
with open(chat_path, 'w') as file:
json.dump(st.session_state[self.page_name]['chat'], file)

def body(self):
Expand All @@ -135,7 +151,8 @@ def body(self):
self.reload_history_message(
st.session_state[self.page_name]['setting']['history_path'])

if user_input := st.chat_input(placeholder='input any question...'):
if user_input := st.chat_input(
placeholder='input any question about this repo...'):
if user_input:
st.session_state[self.page_name]['input_text'] = user_input
self.run_agent()
Expand Down
30 changes: 21 additions & 9 deletions apps/codexgraph_agent/pages/code_commenter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import streamlit as st
from apps.codexgraph_agent.pages.components.page import (PageBase,
Expand All @@ -12,9 +13,11 @@ def __init__(self):
super().__init__(
task_name='code_commenter',
page_title='📝 Code Commenter',
output_path='logs\\CC_conversation',
output_path='logs/CC_conversation',
input_title='Code needing comments',
default_input_text='Please input the code that requires comments')
default_input_text=
'Please copy and paste the code snippet that requires comments here.'
)
self.agent = self.get_agent()

def get_agent(self):
Expand All @@ -30,12 +33,12 @@ def get_agent(self):
max_iterations = int(
st.session_state.shared['setting']['max_iterations'])

prompt_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'code_commenter')
schema_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'graph_database')
prompt_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'code_commenter'))
schema_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'graph_database'))

try:
agent = CodexGraphAgentCommenter(
Expand All @@ -46,7 +49,16 @@ def get_agent(self):
graph_db=graph_db,
max_iterations=max_iterations,
message_callback=self.create_update_message())
except Exception:
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is{traceback.format_exc()}'
)
print(
f'The path of the prompt is {prompt_path}, '
f'the schema path is {schema_path}, the llm_config is {llm_config}'
)

agent = None
return agent

Expand Down
27 changes: 19 additions & 8 deletions apps/codexgraph_agent/pages/code_debugger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import streamlit as st
from apps.codexgraph_agent.pages.components.page import (PageBase,
Expand All @@ -12,10 +13,10 @@ def __init__(self):
super().__init__(
task_name='code_debugger',
page_title='🛠️ Code Debugger',
output_path='logs\\CD_conversation',
output_path='logs/CD_conversation',
input_title='Bug Issue',
default_input_text=(
'Please input the code snippet and describe the bug '
'Please copy and paste the code snippet and describe the bug '
'or issue you are facing. '
'Include any error messages if available.'))
self.agent = self.get_agent()
Expand All @@ -33,11 +34,12 @@ def get_agent(self):
max_iterations = int(
st.session_state.shared['setting']['max_iterations'])

prompt_path = os.path.join(
st.session_state.shared['setting']['prompt_path'], 'code_debugger')
schema_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'graph_database')
prompt_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'code_debugger'))
schema_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'graph_database'))

try:
agent = CodexGraphAgentDebugger(
Expand All @@ -48,7 +50,16 @@ def get_agent(self):
graph_db=graph_db,
max_iterations=max_iterations,
message_callback=self.create_update_message())
except Exception:
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is{traceback.format_exc()}'
)
print(
f'The path of the prompt is {prompt_path}, '
f'the schema path is {schema_path}, the llm_config is {llm_config}'
)

agent = None
return agent

Expand Down
25 changes: 17 additions & 8 deletions apps/codexgraph_agent/pages/code_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import streamlit as st
from apps.codexgraph_agent.pages.components.page import (PageBase,
Expand All @@ -12,7 +13,7 @@ def __init__(self):
super().__init__(
task_name='code_generator',
page_title='🔧 Code Generator',
output_path='logs\\CG_conversation',
output_path='logs/CG_conversation',
input_title='New Requirements',
default_input_text=
'Please input the requirements or specifications for the new feature or module you need.'
Expand All @@ -33,12 +34,12 @@ def get_agent(self):
max_iterations = int(
st.session_state.shared['setting']['max_iterations'])

prompt_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'code_generator')
schema_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'graph_database')
prompt_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'code_generator'))
schema_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'graph_database'))

try:
agent = CodexGraphAgentGenerator(
Expand All @@ -49,7 +50,15 @@ def get_agent(self):
graph_db=graph_db,
max_iterations=max_iterations,
message_callback=self.create_update_message())
except Exception:
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is{traceback.format_exc()}'
)
print(
f'The path of the prompt is {prompt_path}, '
f'the schema path is {schema_path}, the llm_config is {llm_config}'
)
agent = None
return agent

Expand Down
32 changes: 20 additions & 12 deletions apps/codexgraph_agent/pages/code_unittester.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import streamlit as st
from apps.codexgraph_agent.pages.components.page import (PageBase,
Expand All @@ -12,12 +13,11 @@ def __init__(self):
super().__init__(
task_name='code_unittester',
page_title='🔍 Code Unit Tester',
output_path='logs\\CU_conversation',
output_path='logs/CU_conversation',
input_title='Code needing unittest',
default_input_text=(
'Please input the code for which you need unit tests. '
'Include any specific scenarios or edge cases you want to test.'
))
default_input_text=
('Please copy and paste the code snippet for which you need unit tests. '
'Include any specific scenarios or edge cases you want to test.'))
self.agent = self.get_agent()

def get_agent(self):
Expand All @@ -33,12 +33,12 @@ def get_agent(self):
max_iterations = int(
st.session_state.shared['setting']['max_iterations'])

prompt_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'code_unittester')
schema_path = os.path.join(
st.session_state.shared['setting']['prompt_path'],
'graph_database')
prompt_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'code_unittester'))
schema_path = str(
Path(st.session_state.shared['setting']['prompt_path']).joinpath(
'graph_database'))

try:
agent = CodexGraphAgentUnitTester(
Expand All @@ -49,7 +49,15 @@ def get_agent(self):
graph_db=graph_db,
max_iterations=max_iterations,
message_callback=self.create_update_message())
except Exception:
except Exception as e:
import traceback
print(
f'The e is {e}, while the traceback is{traceback.format_exc()}'
)
print(
f'The path of the prompt is {prompt_path}, '
f'the schema path is {schema_path}, the llm_config is {llm_config}'
)
agent = None
return agent

Expand Down
Loading
Loading