Skip to content

Commit

Permalink
connect to llm #226
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Feb 4, 2025
1 parent 4919c3f commit cab5fbf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import List

from langchain_core.prompts import PromptTemplate, ChatPromptTemplate
Expand All @@ -23,11 +24,12 @@ class BadPracticeList(BaseModel):
bad_practices: List[BadPractice] = Field(description="A list of bad practices detected in a pull request.")


def detectbadpractices(pull_requests: PullRequest) -> BadPracticeList:
with open("./prompts/pullrequest_badpractice_detector.txt", "r") as f:
def detectbadpractices(title, description) -> BadPracticeList:
prompt_path = Path(__file__).parent / "prompts" / "pullrequest_badpractice_detector.txt"
with open(prompt_path, "r", encoding="utf-8") as f:
prompt_text = f.read()
prompt_template = ChatPromptTemplate.from_template(prompt_text)
prompt = prompt_template.invoke(title=pull_requests.title, description=pull_requests.description)
prompt = prompt_template.invoke({"title": title, "description": description})
structured_llm = model.with_structured_output(BadPracticeList)
response = structured_llm.invoke(prompt)
return response
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ GUIDELINES:
REQUIREMENTS:
1. Identify and describe all bad practices in the pull request title and description.
2. Provide a clear title and a brief and concise description for each detected bad practice.
3. Return a list of all detected bad practices in the pull request. Return multiple bad practices if necessary.
4. Use clear and concise language to describe the bad practices.
5. Keep titles consistent between detections so that the same bad practice is identified in the same way.
6. Multiple runs on the same title and description should return the same results if nothing has changed.

Pull Request Title: {title}
Pull Request Description: {description}
19 changes: 15 additions & 4 deletions server/intelligence-service/app/routers/detector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from typing import List

from fastapi import APIRouter
from ..detector.bad_practice_detector import PullRequest, detectbadpractices, BadPracticeList
from openai import BaseModel

from ..detector.bad_practice_detector import PullRequest, detectbadpractices, BadPracticeList, BadPractice

router = APIRouter(prefix="/detector", tags=["detector"])

class DetectorRequest(BaseModel):
title: str
description: str

class DetectorResponse(BaseModel):
bad_practices: List[BadPractice]

@router.post(
"/",
response_model=BadPracticeList,
response_model=DetectorResponse,
summary="Detect bad practices given rules.",
)
def detect(request: PullRequest):
return detectbadpractices(request)
def detect(request: DetectorRequest):
return detectbadpractices(request.title, request.description)

0 comments on commit cab5fbf

Please sign in to comment.