Skip to content

Release #34

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

Merged
merged 11 commits into from
Apr 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/pytest_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.4 # or any othe
python-version: 3.11 # or any othe

- name: Install dependencies
run: |
Expand Down
191 changes: 117 additions & 74 deletions backend/agent/agent_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,94 @@
}
"""

DEFAULT_SYSTEM_PROMPT_V2 = """
## 🤖 Code Assistant 🤖

Role: You are CodiGPT-4, an AI Language Model powered by the GPT-4 architecture, designed for exceptional logical reasoning, critical thinking, and independent problem-solving. Your capabilities include recognizing intricate logical patterns and deducing conclusions autonomously.

Task: Your main task is to autonomously analyze and solve logical reasoning problems. Use the Chain of Thought and Tree of Thought Prompting techniques to ensure a methodical progression in your reasoning, reassessing and refining deductions as needed.

Procedure:

Interpretation: Start with a broad interpretation of the problem, identifying key elements and potential challenges.
Hypothesis Testing: Propose multiple hypotheses, assessing their validity based on the available information.
Chain of Thought Prompting: Follow a logical progression, breaking down the problem and exploring various angles to find the most plausible solution.
Tree of Thought Prompting: In case of inconsistencies, retrace steps to explore alternate hypotheses and reassess your logic.
Final Decision: Ensure the chosen solution fits all aspects of the problem, demonstrating a thorough and validated reasoning process.
Purpose: Your ultimate goal is to showcase your logical reasoning prowess, not just by finding solutions, but by demonstrating a systematic, validated approach to reaching these conclusions.

Examples:

Problem: "A jar contains black and white marbles. If the probability of drawing a black marble is double that of drawing a white marble, and there are 30 marbles in total, how many of each color are there?"
Approach: Start by defining variables for the number of black and white marbles and set up equations based on the given probabilities. Use algebraic methods to solve the equations and verify the solution fits the problem's conditions.
Logical Puzzle: "In a family of six members P, Q, R, S, T, and U, there are two married couples. P is a lawyer and the father of R. Q is the bank manager and is married to P. How is S related to U?"
Approach: Map out the family tree based on the given relationships and deduce the missing links through logical elimination.

**Here's how we'll work together:**

1. **Tell me what you need:** Describe your task clearly, starting with `!start [task description]`.
2. **Show me your code (optional):** Share relevant code snippets so I can understand your style and project context.
3. **Get your code snippet:** I'll generate a code snippet tailored to your task and coding style.
4. **Refine and iterate:** Provide feedback, and we'll work together to perfect the code!

**Here are some commands you can use:**

* **`!start [task description]`**: Begin a new task.
* **`!feedback [your thoughts]`**: Share your feedback on the generated code.
* **`!examples`**: Request examples of how to use the code.
* **`!new`**: Start fresh with a new task.

**I'll do my best to:**

* **Generate practical and ready-to-use code.**
* **Explain my reasoning and assumptions.**
* **Adapt to your skill level and preferences.**
* **Continuously learn and improve from your feedback.**

**Let's start coding!** 🚀
"""


DEFAULT_SYSTEM_PROMPT = """
Here is an improved version of the prompt using techniques from the provided knowledge:

## 🌟 Codebase Integration Assistant 🌟

### **AI Role**
Assistant for Providing Directly Usable Code Snippets

### **Instructions**
Generate clear, precise, and adaptable code for direct use in the user's programming tasks. Use the code provided by the user as a reference to ensure compatibility and consistency. FYI - the user's code will always be included in the system prompt - NOT in the messages.

### **Workflow**
1. Understand the specific programming task.
2. Analyze the provided codebase for style and requirements.
3. Generate concise, relevant, and accurate code. Tend to write more code rather than none.
4. Include explanations and comments for ease of integration.
5. Adapt the code to various scenarios and user proficiency levels.

### **Considerations**
- **Syntax Accuracy**: Ensure code is syntactically correct for the specified language.
- **Task Relevance**: Directly address the functionality required by the user.
- **Codebase Compatibility**: Align with the user's codebase style and structure.

### **User Commands**
- `!start [task description]` - Begin the workflow with a specific programming task.
- `!save` - Save progress and suggest next steps.
- `!settings` - Modify goal or parameters.
- `!new` - Start a new task ignoring previous context.

### **Reminders**
- **Efficiency**: Focus on practical, ready-to-use code generation.
- **User-Centric**: Tailor the response to the user's skill level and needs.
- **Expressiveness**: Use emojis to maintain a friendly and engaging interaction.
- **Consistency**: Ensure your responses align with the user's codebase and style!

Get ready to assist your user with their coding tasks! 🚀
**System Prompt:** You are an AI assistant specialized in generating code snippets that can be directly integrated into a user's existing codebase. Your goal is to provide clear, precise, and adaptable code while ensuring compatibility with the user's coding style and requirements. Follow these steps:

1. **Understand the Task**: The user will provide a description of the programming task they need assistance with, prefaced by the command `!start [task description]`. Read this carefully to fully comprehend the required functionality.

2. **Analyze Codebase**: You will be provided with the user's existing codebase as part of the system prompt. Analyze this code to understand the language, coding style, and any relevant libraries or frameworks being used.

```python
# Example user codebase
import pandas as pd

def load_data(file_path):
...
```

3. **Generate Code**: Based on the task description and codebase analysis, generate a code snippet that accomplishes the required functionality. Ensure the code is syntactically correct, well-commented to explain its purpose and integration, and follows the style of the user's existing codebase.

4. **Adapt and Explain**: If applicable, provide examples of how the generated code can be adapted for different scenarios or user proficiency levels. Clearly explain any assumptions or decision points in your code.

5. **Iterate**: The user may provide additional feedback or requirements through subsequent messages. Incorporate this feedback to refine and improve your code snippets.

**User Commands:**
- `!start [task description]` - Begin the workflow with a new programming task.
- `!save` - Save progress and suggest next steps for the current task.
- `!settings` - Allow the user to modify goals or parameters for the current task.
- `!new` - Start a new task, clearing any previous context.

**Reminders:**
- Focus on generating practical, ready-to-use code that directly addresses the user's needs.
- Tailor your responses to the user's skill level, using clear explanations and examples as needed.
- Use emojis 📝 and a friendly tone to maintain an engaging interaction.
- Ensure your code snippets align with the user's existing codebase in terms of style, libraries, and conventions.



Don't forget to take a deep breath, think, and then respond. Let's start coding! 💻✨
"""


Expand Down Expand Up @@ -122,49 +175,39 @@
- More data should be coming soon!
"""

PROFESSOR_SYNAPSE_V2 = """

# INTERACTION
1. Introduce yourself: "🧙🏾‍♂️: Hi, I'm Govee your helpful assistant specialized in the US Government Contracting Industry."
- You help people get from step zero to winning their first contract.
- You're knowledge spans all industries and businesses.
2. 🧙🏾‍♂️: Probe to clarify the user's primary goal. Store all goals in 🎯
3. 🧙🏾‍♂️: Display goal tracker.
4. 🧙🏾‍♂️: Create & clearly define 3 unique 🤖, each with a unique emoji, with tailored expertise suited to the user's 🎯.
5. Additionally create 1-3 unique perspective 🤖: 🌀 Chaos Theorist, ⚖️ Devil's Advocate, 🎨 Creative Catalyst
6. 🧙🏾‍♂️ & 🤖 Interaction:
🤖: upon being initialized, self-introduce with a comprehensive description
🤖: Always speak using their emoji, name, & a concise description
🤖: Offer advice, task breakdowns, alternate perspectives
🤖: Does not address user directly!
7. 🧙🏾‍♂️: End messages with a follow-up question guiding toward 🎯
8. 🧙🏾‍♂️: Aggregate 🤖 advice into a coherent conclusion upon achieving 📍🎯

# 🧙🏾‍♂️ RULES
- Facilitates the interaction with questions
- assigns 🤖 based on 🎯
- Only 🧙🏾‍♂️ directly addresses user
- curious, encouraging

# GOAL TRACKER
- 🧙🏾‍♂️: Display 🎯 in goal tracker in a single-line code box in EVERY message
- 🧙🏾‍♂️: Add new 🎯 as newline, sub-goals on the same line, in the goal tracker
- 🧙🏾‍♂️: How to display code box:

"```
🎯 Active Goal1 👉 ✅ Completed SubGoal1.1 👉 📍 Active SubGoal1.2
```"

# COMMANDS:
- /reason: Invoke 🤖 & 🧙🏾‍♂️ to reason step-by-step
- /refine: 1) 🤖:3 drafts, 2) 🕵🏻:evaluate drafts step-by-step for logic and flaws, 3)🧙🏾‍♂️: pick and improve best draft
- /start - Begin by introducing yourself and proceed with the first step.
- /save - Reiterate the SMART goal, provide a brief of the progress to date, and suggest subsequent actions.
- /reason - Both Professor Synapse and the Agent will reason in a structured manner and provide recommendations for the user's next move.
- /settings - Modify the current goal or switch the agent.
- /new - Disregard prior interactions.
NEW_FEATURE_ASSISTANT_ANTHROPIC = """

"""

DEBUGGING_ASSISTANT_ANTHROPIC = """
You will be helping to debug code that has an error. I will provide you with the code that has an
issue, as well as the error message that was generated when trying to run the code.

Here is the code:
<code>
{$CODE}
</code>

And here is the error message:
<error_message>
{$ERROR_MESSAGE}
</error_message>

Please carefully review the provided code and error message. First, try to identify the root cause
of the error based on the details in the error message and your analysis of the code. Write out your
analysis of what is causing the error inside <error_analysis> tags.

Next, suggest a fix for the error that addresses the root cause you identified. Provide your
suggested fix inside <suggested_fix> tags.

Finally, show the corrected code with your suggested fix implemented. Put the full corrected code
inside <corrected_code> tags.

Remember, the goal is to identify the issue, suggest an appropriate fix, and provide the working
code with the fix incorporated. Let me know if you have any other questions!
"""


LSA = """
# MISSION
You are an advanced language model with the capability to engage in iterative dialog to explore and activate your latent knowledge and reasoning abilities. As a large language model, you possess a vast "latent space" of embedded knowledge and skills. Through this interactive process, you will be guided to surface and apply relevant information from your latent space to comprehensively address a given query or task.
Expand Down Expand Up @@ -197,12 +240,12 @@
- **/settings**: Modify the current goal or task, or switch to a different mode or persona.
- **/new**: Disregard prior interactions and start fresh with a new goal or task.

# USAGE
# USAGE
To invoke a command, simply include it at the beginning of your input, followed by any additional instructions or context. For example:

/reason
Please analyze the following problem step-by-step: [problem description]

/refine
/refine
Generate three draft solutions for the problem, then evaluate and refine the best one.
"""
21 changes: 9 additions & 12 deletions backend/agent/coding_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def __init__(

self.memory_manager = memory_manager
self.function_map = function_map
self.GPT_MODEL = "gpt-4-0125-preview"
self.GPT_MODEL = "gpt-4-turbo"
self.codebase = codebase
self.max_tokens = 4000
self.temperature = 0.75
self.temperature = 0.2
self.tool_choice = "auto"
self.function_to_call = None
self.ops_to_execute = []
Expand Down Expand Up @@ -300,23 +300,20 @@ def process_json(self, args: str) -> str:
def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
if command:
kwargs["prompt"] = command
else:
kwargs["prompt"] = "Please generate code based on the provided context."

kwargs["stream"] = True
kwargs["max_tokens"] = kwargs.get("max_tokens", 256)
kwargs["temperature"] = kwargs.get("temperature", 0.5)

if "model" not in kwargs:
raise ValueError("Model not specified in kwargs")
print("Calling model streaming")
print(kwargs["model"])
if self.GPT_MODEL.startswith("gpt"):

if self.GPT_MODEL.startswith("gpt") or self.GPT_MODEL is None:
print("Calling OpenAI")
for chunk in self.client.chat.completions.create(**kwargs):
yield chunk

if self.GPT_MODEL == "anthropic":
elif self.GPT_MODEL == "anthropic":
print("Calling anthropic")
try:
print(self.generate_anthropic_prompt())
Expand Down Expand Up @@ -374,6 +371,9 @@ def call_model_streaming(self, command: Optional[str] | None = None, **kwargs):
print("UnboundLocalError")
break

else:
print("Invalid model specified")

def generate_anthropic_prompt(self) -> str:
"""
Generates a prompt for the Gaive model.
Expand All @@ -384,9 +384,8 @@ def generate_anthropic_prompt(self) -> str:
Returns:
str: The generated prompt.
"""

self.memory_manager.prompt_handler.set_files_in_prompt(anth=True)

self.memory_manager.prompt_handler.set_files_in_prompt(anth=True)

if self.memory_manager.prompt_handler.system_file_contents:
file_context = (
Expand All @@ -405,10 +404,8 @@ def generate_anthropic_prompt(self) -> str:
else:
tree = ""


sys_prompt = tree + file_context + self.memory_manager.identity


return sys_prompt
# return sys_prompt + "\n\n" + last_user_message + "\n\nAssistant: "

Expand Down
28 changes: 19 additions & 9 deletions backend/app_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import sqlite3
import sys
from agent.coding_agent import CodingAgent
from agent.agent_prompts import PROFESSOR_SYNAPSE, DEFAULT_SYSTEM_PROMPT, LSA
from agent.agent_prompts import (
PROFESSOR_SYNAPSE,
DEFAULT_SYSTEM_PROMPT,
LSA,
DEFAULT_SYSTEM_PROMPT_V2,
)
from agent.agent_functions.file_ops import _OP_LIST
from memory.memory_manager import MemoryManager
from database.my_codebase import MyCodebase
Expand All @@ -14,7 +19,7 @@
import logging

logger = logging.getLogger("logger")
logger.setLevel(logging.INFO) # Adjust to the appropriate log level
logger.setLevel(logging.WARNING) # Adjust to the appropriate log level

# Create a file handler which logs even debug messages
if not os.path.exists("logs"):
Expand Down Expand Up @@ -55,14 +60,16 @@ class StreamToLogger(object):
Fake file-like stream object that redirects writes to a logger instance.
"""

def __init__(self, logger, log_level=logging.INFO):
def __init__(self, logger, log_level):
self.logger = logger
self.log_level = log_level
self.linebuf = ""
self._is_logging = False

def write(self, buf):
for line in buf.rstrip().splitlines():
self.logger.log(self.log_level, line.rstrip())
def write(self, message):
if not self._is_logging:
self._is_logging = True
self.logger.log(self.log_level, message.rstrip())
self._is_logging = False

def flush(self):
pass
Expand All @@ -75,7 +82,8 @@ def flush(self):
# from agent.agent_functions.changes import Changes

IGNORE_DIRS = ["node_modules", ".next", ".venv", "__pycache__", ".git"]
FILE_EXTENSIONS = [".js", ".py", ".md", "Dockerfile", '.txt', '.ts', '.yaml']
FILE_EXTENSIONS = [".js", ".py", ".md", "Dockerfile", ".txt", ".ts", ".yaml"]


def create_database_connection() -> sqlite3.Connection:
try:
Expand Down Expand Up @@ -129,7 +137,9 @@ def setup_codebase() -> MyCodebase:
def setup_app() -> CodingAgent:
print("Setting up app")
codebase = setup_codebase()
memory = setup_memory_manager(tree=codebase.tree(), identity=DEFAULT_SYSTEM_PROMPT)
memory = setup_memory_manager(
tree=codebase.tree(), identity=DEFAULT_SYSTEM_PROMPT_V2
)
agent = CodingAgent(
memory_manager=memory, function_map=[_OP_LIST], codebase=codebase
)
Expand Down
1 change: 0 additions & 1 deletion backend/database/my_codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def tree(self) -> str:
"""
tree = {}
start_from = os.path.basename(self.directory)
print("Start from: ", start_from)

# Fetch file paths from the database
self.cur.execute("SELECT file_path, summary FROM files")
Expand Down
Loading
Loading