Skip to content

Commit

Permalink
ready-for-deployment-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Arya Pratap Singh <[email protected]>
  • Loading branch information
ARYPROGRAMMER committed Jan 6, 2025
1 parent 9199a45 commit dea23fb
Show file tree
Hide file tree
Showing 15 changed files with 571 additions and 143 deletions.
226 changes: 184 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,209 @@
# CoAgents Starter

This example contains a simple starter project.
# Learn Coding with CopilotKit, CoAgents, and LangGraphs 🚀

**These instructions assume you are in the `coagents-starter/` directory**
[![CopilotKit](https://img.shields.io/badge/Powered%20By-CopilotKit-brightgreen)](https://github.com/copilotkit)
[![Frontend: Next.js](https://img.shields.io/badge/Frontend-Next.js-orange)](https://nextjs.org/)
[![Demo Video](https://img.shields.io/badge/Watch-Demo%20Video-red)](https://youtu.be/E1q67IDcdMU)
[![Website](https://img.shields.io/badge/Website-Live-brightgreen)](https://learn-coding-with-copilotkit.vercel.app/)

## Running the Agent
---

First, install the dependencies:
## 📖 **About**

```sh
cd agent
poetry install
```
**Not everyone can code, but everyone can learn.**

Then, create a `.env` file inside `./agent` with the following:
This project is an AI-powered **DSA/Competitive Programming Helper** with an inbuilt editor to help you:
- Prepare for **coding interviews**
- Start learning how to code from scratch
- **Visualize everything** with intuitive representations

```
GROQ_API_KEY=...
```
**Experience the future of coding education!**

IMPORTANT:
Make sure the OpenAI API Key you provide, supports gpt-4o.
🌐 Live Demo: [learn-coding-with-copilotkit.vercel.app](https://learn-coding-with-copilotkit.vercel.app/)

Then, run the demo:
---

```sh
poetry run demo
```
## 🌟 **Why CopilotKit?**

## Running the UI
- **Seamless Integration**: Build AI copilots that enhance user experiences effortlessly.
- **Open Source**: Join a thriving community of developers using and contributing to CopilotKit.
- **Future-Ready**: Perfect for in-app AI agents, context-aware chatbots, shared state and beyond!

First, install the dependencies:
Learn more about [CopilotKit](https://github.com/copilotkit).

```sh
cd ./ui
pnpm i
```
---

Then, create a `.env` file inside `./ui` with the following:

```
GROQ_API_KEY=...
```
## 🛠️ **Project Description**

Then, run the Next.js project:
Learn coding in a revolutionary way using **CopilotKit**, **CoAgents**, and **LangGraphs**! This project showcases how cutting-edge tools can simplify coding education through interactive UI and AI-driven technologies.

```sh
pnpm run dev
```
### Key Features:
- **🌐 CopilotKit**: Effortlessly integrate AI copilots into your apps, enabling in-app chatbots, context-aware interactions, and more.
- **🤖 CoAgents**: A robust infrastructure for connecting LangGraph agents to humans in the loop, enabling seamless collaboration.
- **📊 LangGraphs**: Visual representations of programming languages to simplify understanding of their structure and syntax.
- **🖥️ Inbuilt Editor**: A powerful coding editor designed to boost productivity and learning.

## Usage
---

Navigate to [http://localhost:3000](http://localhost:3000).

# LangGraph Studio
## Screenshots

Run LangGraph studio, then load the `./agent` folder into it.
<details>
<summary>View Achieved Accuracy</summary>

<div align="center">
<img src="screenshots/codechef-one.png" alt="Screenshot 1" width="800px"/>
<img src="screenshots/codechef-one-diagram.png" alt="Screenshot 2" width="800px"/>
<img src="screenshots/codechef-two.png" alt="Screenshot 3" width="800px"/>
<img src="screenshots/codechef-two-diagram.png" alt="Screenshot 4" width="800px"/>
</div>

Make sure to create teh `.env` mentioned above first!
</details>

# Troubleshooting

A few things to try if you are running into trouble:
## 🏗️ **Tech Stack**

### Frontend:
- [Next.js](https://nextjs.org/)
- [ShadCN UI](https://shadcn.dev/)
- [Tailwind CSS](https://tailwindcss.com/)
- [CopilotKit-UI](https://github.com/copilotkit)

### Backend:
- [Python](https://www.python.org/)
- [FastAPI](https://fastapi.tiangolo.com/)
- [LangGraphs](https://langgraphs.example)
- [CopilotKit](https://github.com/copilotkit)

### APIs:
- [Groq](https://groq.com/)
- [Llama-70B](https://example.com/)

---

## 📚 **Topics Covered**

- **TypeScript**
- **Next.js**
- **Competitive Programming**
- **Tailwind CSS**
- **Render Deployment**
- **Koyeb API**
- **ShadCN-UI**
- **Llama-70B**
- **Groq AI**
- **CopilotKit**
- **LangGraph (Python)**
- **CoAgents**

---

## ⚙️ **Installation**

Clone the repository:

```bash
git clone https://github.com/<your-repo-name>.git
```

---

### 🧩 **Configuration**

1. Install the dependencies for the backend:

```bash
cd agent
poetry install
```

2. Create a `.env` file in the `./agent` directory:

```plaintext
GROQ_API_KEY=your_groq_api_key_here
```

3. Run the demo:

```bash
poetry run demo
```

---

### 🖥️ **Running the UI**

1. Install the dependencies for the frontend:

```bash
cd ./frontend-interface
npm i --legacy-peer-deps
```

2. Create a `.env` file in the `./frontend-interface` directory:

```plaintext
GROQ_API_KEY=your_groq_api_key_here
```

3. Run the Next.js project:

```bash
npm run dev
```

4. Navigate to [http://localhost:3000](http://localhost:3000).

---

### 🖥️ **Running the Backend**

1. Install the dependencies for the backend:

```bash
cd ./backend
pip install -r -requirements.txt
```

2. Create a `.env` file in the `./frontend-interface` directory:

```plaintext
GROQ_API_KEY=your_groq_api_key_here
```

3. Run the FAST API server:

```bash
python run_agent.py
```

---


## 🧑‍💻 **Usage**

1. **Launch LangGraph Studio**:
Run LangGraph Studio and load the `./agent` folder into it.

2. **Ensure proper configuration**: Make sure the `.env` file is properly configured as mentioned in the setup steps.

---

## 🔧 **Troubleshooting**

If you encounter any issues, try the following:

1. Ensure no other application is running on port `8000`.
2. In `/agent/dsa_agent/demo.py`, change `0.0.0.0` to `127.0.0.1` or `localhost`.

---

## 📜 **License**

This project is [UN Licensed](LICENSE).

---

Give CopilotKit a ⭐ on [GitHub](https://github.com/copilotkit) if you love it!

1. Make sure there is no other local application server running on the 8000 port.
2. Under `/agent/my_agent/demo.py`, change `0.0.0.0` to `127.0.0.1` or to `localhost`
Binary file modified agent/.langgraph_api/.langgraph_checkpoint.1.pckl
Binary file not shown.
Binary file modified agent/.langgraph_api/.langgraph_checkpoint.2.pckl
Binary file not shown.
Binary file modified agent/.langgraph_api/.langgraph_ops.pckl
Binary file not shown.
Binary file modified agent/.langgraph_api/.langgraph_retry_counter.pckl
Binary file not shown.
7 changes: 2 additions & 5 deletions agent/dsa_agent/edges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

def new_question(state):
question = state["question"]
# last_message = messages[-1]

if (
isinstance(question, SystemMessage)
and "QUESTION UPDATED" in question.content
Expand Down Expand Up @@ -60,11 +58,10 @@ def decide_to_generate_visualisation(state):
"""

print("---ASSESS MERMAID VISUALISATION CODE---")
code = state["code"]
visualization = state["visualization"]
question = state["question"]

print("---GRADE CODE---")
score = visualisation_verify.invoke({"code": code,"visualization": visualization})
score = visualisation_verify.invoke({"question": question})
grade = score.binary_score

if grade == "yes":
Expand Down
12 changes: 6 additions & 6 deletions agent/dsa_agent/edges/visualisation_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ class VerifyVisualisation(BaseModel):
"""Binary output to verify the mermaid code generated to visualise the python code."""

binary_score: str = Field(
description="Python Code generated is correctly visualised by the mermaid code, 'yes' or 'no'"
description="Mermaid Code generated is correct, 'yes' or 'no'"
)

llm = ChatGroq(model="llama-3.3-70b-versatile", temperature=0)
viusalisation_verification = llm.with_structured_output(VerifyVisualisation)

system = """You a 4000 rated Competitive Programmer that visualises an optimised and fully detailed working code in python \n
Given a question and the generated code for it \n
You have to provide the appropriate mermaid code to visualise the code approach generated \n
Make sure that your output contains only mermaid code"""
system = """You provide visualisation of a complex problem by generating corresponding mermaid code\n
Given the question\n
You have to provide the appropriate mermaid code to visualise the solution\n
Make sure that your output contains only mermaid flowchart code in the format ```mermaid\nFLOWCHART...```\n"""

visualisation_prompt = ChatPromptTemplate.from_messages(
[
("system", system),
("human", "Python Code Generated: \n\n {code} \n\n Visualised Code Generated in Mermaid: {visualization}"),
("human", "question: \n\n {question}"),
]
)

Expand Down
10 changes: 5 additions & 5 deletions agent/dsa_agent/nodes/visualiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

llm = ChatGroq(model="llama-3.3-70b-versatile", temperature=0)

system = """You a 4000 rated Competitive Programmer that writes optimised and fully detailed working code in python \n
Given a question and the generated code for it \n
You have to provide the appropriate mermaid code to visualise the code approach generated \n
Make sure that your output contains only mermaid code"""
system = """You provide visualisation of a complex problem by generating corresponding mermaid flowchart code\n
Given the question\n
You have to provide the appropriate mermaid flowchart code to visualise the solution\n
Make sure that your output contains only mermaid flowchart code in the format ```mermaid\n{code}\n```\n"""

visualisation_prompt = ChatPromptTemplate.from_messages(
[
("system", system),
("human", "code: \n\n {code} \n\n User question: {question}"),
("human", "question: \n\n {question}"),
]
)

Expand Down
7 changes: 4 additions & 3 deletions agent/dsa_agent/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class AgentState(TypedDict):
"""

question: str
# testCases: Optional[List[str]] # type: ignore
# messages: Annotated[Sequence[BaseMessage], add_messages]

code: Optional[str]
explanation: Optional[str]
time_complexity: Optional[str]
space_complexity: Optional[str]
visualization: Optional[str]
visualization: Optional[str]
# testCases: Optional[List[str]] # type: ignore
# messages: Annotated[Sequence[BaseMessage], add_messages]
36 changes: 0 additions & 36 deletions frontend-interface/README.md

This file was deleted.

Loading

0 comments on commit dea23fb

Please sign in to comment.