Skip to content

Commit cd31ee9

Browse files
committed
* Add logging
* Add README * Add walkthrough notebook
1 parent a5ddea1 commit cd31ee9

File tree

18 files changed

+2571
-55
lines changed

18 files changed

+2571
-55
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Automatic Issues Triaging with Llama
2+
3+
This tool utilizes an off-the-shelf Llama model to analyze, generate insights, and create a report for better understanding of the state of a repository. It serves as a reference implementation for using Llama to develop custom reporting and data analytics applications.
4+
5+
## Features
6+
7+
The tool performs the following tasks:
8+
9+
* Fetches issue threads from a specified repository
10+
* Analyzes issue discussions and generates annotations such as category, severity, component affected, etc.
11+
* Categorizes all issues by theme
12+
* Synthesizes key challenges faced by users, along with probable causes and remediations
13+
* Generates a high-level executive summary providing insights on diagnosing and improving the developer experience
14+
15+
For a step-by-step look, check out the [walkthrough notebook](walkthrough.ipynb).
16+
17+
## Getting Started
18+
19+
20+
### Installation
21+
22+
```bash
23+
pip install -r requirements.txt
24+
```
25+
26+
### Setup
27+
28+
1. **API Keys and Model Service**: Set your GitHub token for API calls. Some privileged information may not be available if you don't have push-access to the target repository.
29+
2. **Model Configuration**: Set the appropriate values in the `model` section of [config.yaml](config.yaml) for using Llama via VLLM or Groq.
30+
3. **JSON Schemas**: Edit the output JSON schemas in [config.yaml](config.yaml) to ensure consistency in outputs. VLLM supports JSON-decoding via the `guided_json` generation argument, while Groq requires passing the schema in the system prompt.
31+
32+
### Running the Tool
33+
34+
```bash
35+
python triage.py --repo_name='meta-llama/llama-recipes' --start_date='2024-08-14' --end_date='2024-08-27'
36+
```
37+
38+
### Output
39+
40+
The tool generates:
41+
42+
* CSV files with `annotations`, `challenges`, and `overview` data, which can be persisted in SQL tables for downstream analyses and reporting.
43+
* Graphical matplotlib plots of repository traffic, maintenance activity, and issue attributes.
44+
* A PDF report for easier reading and sharing.
45+
46+
## Config
47+
48+
The tool's configuration is stored in [config.yaml](config.yaml). The following sections can be edited:
49+
50+
* **Github Token**: Use a token that has push-access on the target repo.
51+
* **model**: Specify the model service (`vllm` or `groq`) and set the endpoints and API keys as applicable.
52+
* **prompts**: For each of the 3 tasks Llama does in this tool, we specify a prompt and an output JSON schema:
53+
* `parse_issue`: Parsing and generating annotations for the issues
54+
* `assign_category`: Assigns each issue to a category specified in an enum in the corresponding JSON schema
55+
* `get_overview`: Generates a high-level executive summary and analysis of all the parsed and generated data
56+
57+
## Troubleshooting
58+
59+
* If you encounter issues with API calls, ensure that your GitHub token is set correctly and that you have the necessary permissions.
60+
* If you encounter issues with the model service, check the configuration values in [config.yaml](config.yaml).

recipes/use_cases/github_triage/config.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
tokens:
2-
github: <github token>
1+
github_token: <github token>
32
model:
43
use: groq
54
vllm:
65
endpoint: "http://localhost:8000/v1"
7-
key: token
86
model_id: "meta-llama/Meta-Llama-3.1-70B-Instruct"
97
groq:
108
key: <groq token>
119
model_id: llama-3.1-70b-versatile
1210

1311
prompts:
1412
parse_issue:
15-
system: You are an expert open-source maintainer of an AI open source project. Given some discussion threads, you must respond with a report in JSON. Your response should only contain English, and you may translate if you can.
13+
system: You are an expert maintainer of an open source project. Given some discussion threads, you must respond with a report in JSON. Your response should only contain English, and you may translate if you can.
1614
json_schema: '{
1715
"type": "object",
1816
"properties": {
@@ -60,7 +58,7 @@ prompts:
6058
"required": ["summary", "possible_causes", "remediations", "component", "sentiment", "issue_type", "severity", "op_expertise"]
6159
}'
6260
assign_category:
63-
system: "You are the lead maintainer of an AI open source project. Given a list of issues, generate a JSON that categorizes the issues by common themes. For every theme include a description and cite the relevant issue numbers. All issues must be categorized into at least one theme. Some themes you should use if applicable: Cloud Compute, Installation and Environment, Model Loading, Model Fine-tuning and Training, Model Conversion, Model Inference, Distributed Training and Multi-GPU, Performance and Optimization, Quantization and Mixed Precision, Documentation, CUDA Compatibility, Model Evaluation and Benchmarking, Miscellaneous, Invalid."
61+
system: "You are the lead maintainer of an open source project. Given a list of issues, generate a JSON that categorizes the issues by common themes. For every theme include a description and cite the relevant issue numbers. All issues must be categorized into at least one theme."
6462
json_schema: '{
6563
"type": "object",
6664
"properties": {

recipes/use_cases/github_triage/llm.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from openai import OpenAI
88
import groq
99

10-
log = logging.getLogger(__name__)
10+
logger = logging.getLogger(__name__)
11+
logger.addHandler(logging.StreamHandler())
1112
CFG = yaml.safe_load(open("config.yaml", "r"))
1213

1314
class LlamaVLLM():
@@ -47,7 +48,7 @@ class LlamaGroq():
4748
def __init__(self, key, model_id):
4849
self.model_id = model_id
4950
self.client = groq.Groq(api_key=key)
50-
print(f"Using Groq:{self.model_id} for inference")
51+
logger.debug(f"Using Groq:{self.model_id} for inference")
5152

5253
def chat(
5354
self,
@@ -78,13 +79,13 @@ def chat(
7879
output = completion.choices[0].message.content
7980
break
8081
except groq.RateLimitError as e:
81-
wait = response.headers['X-Ratelimit-Reset']
82+
wait = e.response.headers['X-Ratelimit-Reset']
8283
response = e.response
8384
print(e)
84-
print(f"waiting for {wait} to prevent ratelimiting")
85+
print(f"[groq] waiting for {wait} to prevent ratelimiting")
8586
time.sleep(wait)
86-
except:
87-
print(f"inference failed for input: {inputs}")
87+
except Exception as e:
88+
logger.error(f"INFERENCE FAILED with Error: {e.response.status_code}! for input:\n{inputs[-1]['content'][:300]}")
8889

8990
return output
9091

@@ -107,7 +108,6 @@ def run_llm_inference(
107108
Returns:
108109
- Union[str, List[str]]: The response(s) from the LLM.
109110
"""
110-
log.info(f"[run_llm_inference] {prompt_name}")
111111

112112
# initialize appropriate LLM accessor
113113
if CFG['model']['use'] == 'vllm':
@@ -117,6 +117,8 @@ def run_llm_inference(
117117
else:
118118
raise ValueError("Invalid model type in config.yaml")
119119

120+
logger.debug(f"Running `{prompt_name}` inference with {CFG['model']['use']}")
121+
120122
_batch = True
121123
if isinstance(inputs, str):
122124
_batch = False
@@ -150,7 +152,7 @@ def run_llm_inference(
150152
responses_json.append(json.loads(r, strict=False))
151153
continue
152154
except json.JSONDecodeError:
153-
log.error(f"Error decoding JSON: {r}")
155+
logger.error(f"Error decoding JSON: {r}")
154156
responses_json.append(None)
155157
responses = responses_json
156158

0 commit comments

Comments
 (0)