Skip to content
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

feat: 프로젝트 제목 정밀 추론 #50

Merged
merged 1 commit into from
Dec 24, 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
20 changes: 11 additions & 9 deletions app/services/api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def process_repository(template, repo_url, githubID, githubName, requirements):
project_summary = create_project_summary(final_code_summary, final_pr_summary, final_commit_summary, githubID, repo_url, requirements)
simplified_summary = simplify_project_info(project_summary, requirements)
first_commit_date, latest_commit_date = create_repo_start_end_date(repo_url)
# project_title = create_project_title(settings.openai_api_key, settings.gh_token, repo_url, requirements)
project_title = create_project_title(settings.openai_api_key, settings.gh_token, repo_url, requirements)

# STAR 템플릿인 경우에만 추가 데이터 가져오기
if template == "STAR":
Expand All @@ -59,7 +59,8 @@ def process_repository(template, repo_url, githubID, githubName, requirements):

if template == "BASIC":
project_data = Project(
projectName=simplified_summary.projectName,
# projectName=simplified_summary.projectName,
projectName=project_title,
projectStartedAt=first_commit_date,
projectEndedAt=latest_commit_date,
skillSet=simplified_summary.skillSet,
Expand All @@ -68,8 +69,8 @@ def process_repository(template, repo_url, githubID, githubName, requirements):
)
elif template == "STAR":
project_data = StarProject(
projectName=simplified_summary.projectName,
# projectName=project_title,
# projectName=simplified_summary.projectName,
projectName=project_title,
projectStartedAt=first_commit_date,
projectEndedAt=latest_commit_date,
skillSet=simplified_summary.skillSet,
Expand All @@ -79,7 +80,8 @@ def process_repository(template, repo_url, githubID, githubName, requirements):
)
elif template == "GITFOLIO":
project_data = GitfolioProject(
projectName=simplified_summary.projectName,
# projectName=simplified_summary.projectName,
projectName=project_title,
projectStartedAt=first_commit_date,
projectEndedAt=latest_commit_date,
skillSet=simplified_summary.skillSet,
Expand Down Expand Up @@ -149,7 +151,7 @@ def create_trouble_shooting(openai_api_key, code_summary, pr_summary, commit_sum
trouble_shooting = generate_trouble_shooting(openai_api_key, code_summary, pr_summary, commit_summary, requirements)
return trouble_shooting

# # 프로젝트 제목 생성
# def create_project_title(openai_api_key, gh_token, repo_url, requirements):
# project_title = generate_project_title(openai_api_key, gh_token, repo_url, requirements)
# return project_title
# 프로젝트 제목 생성
def create_project_title(openai_api_key, gh_token, repo_url, requirements):
project_title = generate_project_title(openai_api_key, gh_token, repo_url, requirements)
return project_title
16 changes: 10 additions & 6 deletions app/services/github_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,13 @@ def get_github_profile_and_repos(gh_token):
print(f"Error while fetching GitHub profile and repositories: {e}")
return "사용자 GitHub 프로필 요약 정보가 없습니다.", "사용자 GitHub 프로젝트 정보를 가져올 수 없습니다."

# 프로젝트 제목 생성 정보
def project_title_candidate(gh_token, repo_url):
try:
# GitHub API 클라이언트 초기화
g = Github(gh_token)

# 레포지토리 이름 추출
repo_name = "/".join(repo_url.rstrip('/').split('/')[-2:])
repo_name = "/".join(str(repo_url).rstrip('/').split('/')[-2:])
repo = g.get_repo(repo_name)

# 제목 후보 1: 레포지토리 이름
Expand All @@ -292,13 +291,14 @@ def project_title_candidate(gh_token, repo_url):
# 제목 후보 2: README 첫 줄
try:
readme_content = repo.get_readme().decoded_content.decode("utf-8")
title_candidate_2 = readme_content.splitlines()[0] if readme_content else ""
# 첫 줄 가져오고 '#' 및 앞뒤 공백 제거
title_candidate_2 = readme_content.splitlines()[0].lstrip('#').strip() if readme_content else ""
print(f"Title Candidate 2 (README First Line): {title_candidate_2}")
except Exception as e:
print(f"Error fetching README content: {e}")
title_candidate_2 = ""

# 제목 후보 3 : topic
# 제목 후보 3: topic
try:
topics = repo.get_topics() # 토픽 리스트 가져오기
title_candidate_3 = ", ".join(topics) if topics else ""
Expand All @@ -307,11 +307,15 @@ def project_title_candidate(gh_token, repo_url):
print(f"Error fetching topics: {e}")
title_candidate_3 = ""

return title_candidate_1, title_candidate_2, title_candidate_3
return {
"title_candidate_1": title_candidate_1,
"title_candidate_2": title_candidate_2,
"title_candidate_3": title_candidate_3,
}

except Exception as e:
print(f"Error creating project name: {e}")
return "프로젝트 제목을 생성할 수 없습니다."
return {"title_candidate_1": "", "title_candidate_2": "", "title_candidate_3": ""}

# star기법에 사용될 깃허브 데이터
def get_repository_data(gh_token, repo_url):
Expand Down
67 changes: 10 additions & 57 deletions app/services/gpt_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from openai import OpenAI
import anthropic
from app.config.settings import settings
from app.dto.resume_dto import GptProject, ResumeResponseDto, ProjectTitleDto, RoleAndTaskDto, TroubleShootingDto, StarDto
from app.services.github_service import get_github_profile_and_repos, project_title_candidate
Expand Down Expand Up @@ -329,49 +328,6 @@ def resume_update(openai_api_key, requirements, selected_text, context_data, pro
except Exception as e:
print(f"Error modifying resume with GPT: {e}")
return context_data # 오류 발생 시 기존 데이터 반환

def generate_resume_update(anthropic_api_key, requirements, selected_text, context_data, prompt):
try:
# 선택된 텍스트가 없을 때 처리
if not selected_text or not selected_text.strip():
print("Error: Selected text is empty or missing.")
return context_data # 오류 발생 시 기존 데이터 반환

# 수정 요구사항이 없을 때 처리
if not requirements or not requirements.strip():
print("Error: User request (requirements) is empty or missing.")
return context_data # 오류 발생 시 기존 데이터 반환

# 수정 요청
print("이력서 수정")

# Anthropic API 호출
client = anthropic.Anthropic(api_key=anthropic_api_key)
response = client.completions.create(
model="claude-3.5",
max_tokens_to_sample=500,
temperature=0.7,
prompt=(
f"You are a professional resume modification assistant. Your task is to update the following `selected_text` "
f"based on the `requirements` provided, considering the `context_data`. "
f"Ensure that the updated text aligns with the style and tone of the original text.\n\n"
f"Context Data:\n{json.dumps(context_data, indent=4)}\n\n"
f"Selected Text:\n{selected_text}\n\n"
f"User Request:\n{requirements}\n\n"
f"Sample summary format: {prompt}.\n\n"
f"Please update the selected text based on the instructions provided."
)
)

# 응답 텍스트 추출
response_text = response.completion.strip()

# 업데이트된 이력서 반환
return response_text

except Exception as e:
print(f"Error modifying resume with Claude: {e}")
return context_data # 오류 발생 시 기존 데이터 반환

# 이력서 제목 생성
def generate_project_title(openai_api_key, gh_token, repo_url, prompt=settings.project_title_prompt):
Expand All @@ -385,8 +341,9 @@ def generate_project_title(openai_api_key, gh_token, repo_url, prompt=settings.p
# 후보 검증 및 최종 제목 결정
if title_candidate_1 == title_candidate_2:
print("Title Candidate 1 and 2 are identical.")
title = {"projectTitle": title_candidate_1}
return title
# title = {"projectTitle": title_candidate_1}
# return title
return title_candidate_1

print("프로젝트 제목을 추론합니다.")

Expand All @@ -399,8 +356,10 @@ def generate_project_title(openai_api_key, gh_token, repo_url, prompt=settings.p
"role": "system",
"content": (
"You are a professional assistant tasked with deciding the best project title. "
"Evaluate the provided title candidates and choose the most appropriate one. "
"Focus on clarity, relevance, and alignment with typical project naming conventions."
"1. Be a single, clear, and concise word."
"2. Reflect the essence or purpose of the project."
"3. Avoid multi-word phrases, additional context, or unnecessary details. "
"Return only the single-word title as plain text."
)
},
{
Expand Down Expand Up @@ -436,19 +395,13 @@ def generate_project_title(openai_api_key, gh_token, repo_url, prompt=settings.p
print(f"Final Response Text: {response_text}")

# ProjectTitleDto 객체로 반환
return response_text
return response_text.projectTitle


except Exception as e:
print(f"Error modifying resume with GPT: {e}")
return {
"projectTitle": "",
"title_candidates": {
"title_candidate_1": "",
"title_candidate_2": "",
"title_candidate_3": ""
}
}
return {"projectTitle": "Untitled"}


# 맡은 업무 생성
def generate_role_and_task(openai_api_key, code_summary, pr_summary, commit_summary, requirements, prompt=settings.role_and_task_prompt):
Expand Down
Loading