# Project export: case-GPT

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: TreeHacks 2024
- Tagline: case-gpt: Revolutionize your consulting interviews with our AI-powered interactive agent. Practice real-time case solving and improve your skills with personalized feedback.
- Devpost: https://devpost.com/software/case-gpt
- GitHub: https://github.com/adke/case-GPT
- Video: https://www.youtube.com/embed/pF7xf0_bN3g?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Team: 2 GitHub contributor(s) — Abhyuday Singh (3 commits), Adish Shah (2 commits)

## Devpost submission (written by the team)

### Inspiration

The inspiration for Case-GPT arose from the desire to create a realistic and interactive platform for practicing consulting casing interviews. Combining a passion for artificial intelligence and professional development, the goal was to provide individuals with a low-pressure environment to hone their problem-solving skills and receive real-time feedback.

### What it does

Case-GPT acts as an AI-powered interviewer, engaging in interactive casing interviews with human participants. The AI presents business cases, asks probing questions, and evaluates responses. Participants analyze problems, develop solutions, and communicate recommendations. The AI dynamically adapts its questioning based on responses, providing a realistic simulation.

### How we built it

Case-GPT was built using natural language processing (NLP) techniques and open artificial intelligence models, leveraging Meta's LLama-2 model fine-tuned and prompt engineered for casing interviews. The frontend interface utilized web technologies like HTML, CSS, and JavaScript, while we used Endpoint API calls to the LLM using together-ai for scalability.

### Challenges we ran into

Preparing the LLModel to simulate human interviewer behavior presented a significant challenge. Designing training data and ensuring relevant question generation were key tasks. Integrating frontend and backend components, particularly handling real-time interactions, posed technical challenges. The biggest challenge was with pivoting to Open sourced models after being repeatedly rate limited by Azure OpenAI models as our initial idea was to build with GPT and Whisper for a real interview experience.

### Accomplishments we're proud of

We're proud to have developed a semi-sophisticated AI platform offering a realistic environment for practicing casing interviews. Case-GPT enables users to gain confidence and proficiency in addressing complex business problems. The seamless integration of AI technology and user interface design resulted in a polished and user-friendly experience, and people can now practice casing interviews which specifically require people to sit with another person to practice.

### What we learned

Developing this project provided valuable insights into natural language processing and machine learning technologies. We learned to effectively leverage pre-trained language models and fine-tune them for specific applications. Experience in frontend and backend development, LLMs, and user experience design was also gained.

### What's next

for case-gpt Future plans for Case-GPT include expanding case study availability - particularly so by finetuning the LLM to learn from being given a case then framing questions by itself, and integrating additional learning resources. Collaboration with consulting firms and educational institutions aims to incorporate Case-GPT into training programs, benefiting more individuals seeking effective interview practice. In our analysis of this market, there were a handful of companies trying to do something similar but they are not scaled enough that their chatbot self learns while interacting with the user.

## README (from the GitHub repository)

# Case-GPT
##### By Adish Shah and Abhyuday Singh

## Inspiration
#### The inspiration for Case-GPT arose from the desire to create a realistic and interactive platform for practicing consulting casing interviews. Combining a passion for artificial intelligence and professional development, the goal was to provide individuals with a low-pressure environment to hone their problem-solving skills and receive real-time feedback when practicing for job interviews.

## What it does
#### Case-GPT acts as an AI-powered interviewer, engaging in interactive casing interviews with human participants. The AI presents business cases, asks probing questions, and evaluates responses. Participants analyze problems, develop solutions, and communicate recommendations. The AI dynamically adapts its questioning based on those user-given responses, providing a realistic simulation.

## How we built it
#### Case-GPT was built using natural language processing (NLP) techniques and open artificial intelligence models, leveraging Meta's LLama-2 model which was fine-tuned and prompt engineered for casing interviews. We used api endpoints to call the LLM from together-ai for scalability.

## What's next for case-gpt
#### Future plans for Case-GPT include expanding case study availability - particularly so by finetuning the LLM to learn from being given a case then framing questions by itself, and integrating additional learning resources. Possible collaboration with consulting firms and educational institutions can also aim improve Case-GPT by bringing more relevant training data to the model, benefiting more individuals seeking effective interview practice.

## More Information
#### More details about this project can be found from the following link:
#### https://devpost.com/software/case-gpt


## Detected evidence (automated analysis)

Indexed codebase: 5 recognized source files, 11 KB.
- Python (language) — detected in the code
- JavaScript (language) — claimed on Devpost, not found in the code
- Next.js (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (7 of 7)

```
interview_chatbot/case_interview_chatbot_treehacks.py
interview_chatbot/clarifying_questions_database.py
interview_chatbot/framework_database.py
interview_chatbot/main.py
interview_chatbot/requirements.txt
LICENSE
README.md
```

### Dependencies

- interview_chatbot/requirements.txt: taipy@==3.0.0

### Recent commits (newest first)

- Update README.md
- Update README.md
- Update main.py
- Update main.py
- Update case_interview_chatbot_treehacks.py
- Added caseGPT model
- Initial commit

## Key source files (fetched from GitHub, selected and truncated for size)

### interview_chatbot/requirements.txt

```
taipy==3.0.0
```

### interview_chatbot/main.py

```python
import requests
from taipy.gui import Gui, State
import json
from clarifying_questions_database import clarifying_questions
from framework_database import framework_list

context = "Welcome to our case interview practice session. Today's case involves a retail company experiencing declining sales in its flagship store. The company suspects changing consumer preferences and increased competition from online retailers may be contributing factors."
conversation = {
    "Conversation": [context]
}
current_user_message = ""

API_URL = 'https://api.together.xyz/v1/chat/completions'
headers={
    "Authorization": "Bearer f0f8fe90841d6b1e22ee9f9649962f2ebf402a89bd037483c8a2e4a5e6732256",
}

def get_response(prompt: str) -> str:
    endpoint = 'https://api.together.xyz/v1/chat/completions'
    res = requests.post(endpoint, json={
        "model": "meta-llama/Llama-2-70b-chat-hf",
        "max_tokens": 512,
        "prompt": f"[INST] {prompt} [/INST]",
        "temperature": 0.0,
        "top_p": 0.7,
        "top_k": 50,
        "repetition_penalty": 1,
        "stop": [
            "[/INST]",
            "</s>"
        ],
        "repetitive_penalty": 1,
        "update_at": "2024-02-17T19:01:39.423Z"
    }, headers={
        "Authorization": "Bearer f0f8fe90841d6b1e22ee9f9649962f2ebf402a89bd037483c8a2e4a5e6732256",
    })
    output = res.json()['choices'][0]['message']['content']
    return output

def send_message(state: State) -> None:
    """
    Send the user's message to the API and update the conversation.

    Args:
        - state: The current state of the app.
    """
    global current_step
    
    # Add the user's message to the context
    state.context += f"Human: \n {state.current_user_message}\n\n AI:"
    
    # Check the current step in the conversation
    if current_step == 0:
        # Welcome message and ask for user input
        case_prompt = "Welcome to our case interview practice session. Today's case involves a retail company experiencing declining sales in its flagship store. The company suspects changing consumer preferences and increased competition from online retailers may be contributing factors."
        state.context += case_prompt
        state.context += "\nPlease provide your input:"
        current_step += 1
    elif current_step == 1:
        # Get user input and classify the case
        question = "Now, can you please restate your understanding of the case and classify it into one of the following casing categories: Market Entry, Product Launch, Operational Efficiency, Financial Analysis, or Other?"
        state.context += question
        current_step += 1
    elif current_step == 2:
        # Check if user input is in the correct category
        if "Operational Efficiency" not in state.current_user_message:
            state.context += "This is not the correct category, please try again"
        else:
            state.context += "That's the correct approach, go ahead and explain your framework"
            current_step += 1
    elif current_step == 3:
        # Check if framework is valid
        if not any(framework in state.current_user_message for framework in framework_list):
            state.context += f"The following framework {state.current_user_message} is not valid, please try again"
        else:
            state.context += "Your framework aligns with the operational efficiency focus. Please proceed with your analysis, making sure you provide the drivers for your framework."
            current_step += 1
    elif current_step == 4:
        # Provide a concise follow-up response to the analysis
        prompt_3 = f"Provide a concise follow-up response to {state.current_user_message} and ensure that the same information as {state.current_user_message} is not mentioned in the follow-up response"
        framework_response = get_response(prompt_3)
        state.context += framework_response
        state.context += "------------------------------------------------------------------------\n"
        state.context += "Awesome, now to finish off let's summarize the entire case"
        current_step += 1
    elif current_step == 5:
        # Rate the submitted summary
        gold_summary = "The company's declining sales are attributed to changing consumer preferences and increased competition from online retailers. To address this, we will implement targeted marketing campaigns, enhance the customer loyalty program, and optimize inventory levels to meet demand fluctuations"
        res_prompt = f"Now rate the submitted summary: {state.current_user_message} vs our gold standard summary: {gold_summary}"
        rating = get_response(res_prompt)
        state.context += rating
    
    # Update the conversation
    conv = state.conversation._dict.copy()
    conv["Conversation"] += [state.current_user_message, state.context]
    state.conversation = conv
    
    # Clear the input field
    state.current_user_message = ""

# Initialize the current step variable
current_step = 0

# Run the Taipy GUI
page = f"""
<|{conversation}|table|show_all|width=100%|>
<|{current_user_message}|input|label=Write your message here...|on_action=send_message|class_name=fullwidth|>
"""

if __name__ == "__main__":
    Gui(page).run(dark_mode=True, title="Taipy Chat")


```

### interview_chatbot/framework_database.py

```python
framework_list = [
      "customer segmentation",
      "biggest cost drivers",
      "possible M&A",
  ]
```

### interview_chatbot/clarifying_questions_database.py

```python
clarifying_questions = [
      "What is the geographic location of the flagship store?: Downtown Detroit",\
      "Can you provide more details about the retail company's target demographic?: The retail company targets middle to upper-income consumers aged 25-45",\
      "How long has the company been experiencing declining sales?: For about past 3 years",\
  ]
```

### interview_chatbot/case_interview_chatbot_treehacks.py

```python
import json
import requests
from clarifying_questions_database import clarifying_questions
from framework_database import framework_list

def get_response(prompt):
  endpoint = 'https://api.together.xyz/v1/chat/completions'
  res = requests.post(endpoint, json={
      "model": "meta-llama/Llama-2-70b-chat-hf",
      "max_tokens": 512,
      "prompt": f"[INST] {prompt} [/INST]",
      "temperature": 0.0,
      "top_p": 0.7,
      "top_k": 50,
      "repetition_penalty": 1,
      "stop": [
          "[/INST]",
          "</s>"
      ],
      "repetitive_penalty": 1,
      "update_at": "2024-02-17T19:01:39.423Z"
  }, headers={
      "Authorization": "Bearer API Key",
  })
  output = res.json()['choices'][0]['message']['content']
  print(output)

def retailDeclineCase():

  case_prompt = "Welcome to our case interview practice session. Today's case involves a retail company experiencing declining sales in its flagship store. The company suspects changing consumer preferences and increased competition from online retailers may be contributing factors."
  print(case_prompt)
  human_input = input()

  question = "Now, can you please restate your understanding of the case and classify it into one of the following casing categories: Market Entry, Product Launch, Operational Efficiency, Financial Analysis, or Other?"
  prompt_2 = f"If {human_input} is a question in {clarifying_questions}, answer it without answering other questions in {clarifying_questions}, be as concise as possible"
  response_api = get_response(prompt_2)
  print(response_api)
  print(question)

  human_input = input()

  while "Operational Efficiency" not in human_input:
    print("This is not the correct category, please try again")
    human_input = input()

  print("That's the correct approach, go ahead and explain your framework")
  framework = input()


  while (framework_list[0] or framework_list[1] or framework_list[2]) not in framework:
    print(f"The following framework {framework} is not valid, please try again")
    framework = input()

  print("Your framework aligns with the operational efficiency focus. Please proceed with your analysis, making sure you provide the drivers for your framework.")

  analysis = input()

  prompt_3 = f"Provide a concise follow-up response to {analysis} and ensure that the same information as {analysis} is not mentioned in the follow-up response"

  framework_response = get_response(prompt_3)
  print(framework_response)
  print("------------------------------------------------------------------------")
  print("Awesome, now to finish off let's summarize the entire case")
  summarized = input()
  gold_summary = "The company's declining sales are attributed to changing consumer preferences and increased competition from online retailers. To address this, we will implement targeted marketing campaigns, enhance the customer loyalty program, and optimize inventory levels to meet demand fluctuations"
  res_prompt = f"Now rate the submitted summary: {summarized} vs our gold standard summary: {gold_summary}"
  rating = get_response(res_prompt)
  print(rating)


def main():
    retailDeclineCase()

if __name__=="__main__":
    main()


```