Skip to content

Commit

Permalink
Merge pull request #81 from resum-ai/feat/resume
Browse files Browse the repository at this point in the history
Feat/resume
  • Loading branch information
yjoonjang authored Apr 10, 2024
2 parents e94e8d6 + c212726 commit a59b3bb
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 60 deletions.
2 changes: 1 addition & 1 deletion memos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
urlpatterns = [
path("", views.PostMemoView.as_view(), name="post_memo"),
path("all", views.GetAllMemoView.as_view(), name="get_all_memos"),
path("memo/<int:pk>", views.GetMemoDetailView.as_view(), name="memo-detail"),
path("<int:pk>", views.GetMemoDetailView.as_view(), name="memo-detail"),
path("update/<int:pk>", views.UpdateMemoView.as_view(), name="scrap-memo"),
path("delete/<int:pk>", views.DeleteMemoView.as_view(), name="delete-memo"),
path("search", views.SearchMemoView.as_view(), name="search-memo"),
Expand Down
42 changes: 42 additions & 0 deletions resume/migrations/0003_resume_question_chathistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.0.3 on 2024-04-10 06:52

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("resume", "0002_resume_position"),
]

operations = [
migrations.AddField(
model_name="resume",
name="question",
field=models.TextField(default="테스트질문"),
preserve_default=False,
),
migrations.CreateModel(
name="ChatHistory",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"resume",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="resume.resume"
),
),
],
),
]
18 changes: 18 additions & 0 deletions resume/migrations/0004_alter_resume_due_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-04-10 07:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("resume", "0003_resume_question_chathistory"),
]

operations = [
migrations.AlterField(
model_name="resume",
name="due_date",
field=models.CharField(max_length=32, null=True),
),
]
18 changes: 18 additions & 0 deletions resume/migrations/0005_alter_resume_due_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-04-10 07:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("resume", "0004_alter_resume_due_date"),
]

operations = [
migrations.AlterField(
model_name="resume",
name="due_date",
field=models.DateField(null=True),
),
]
5 changes: 3 additions & 2 deletions resume/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ class Resume(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=255) # 제목이 곧 지원하려는 기업명과 동일함
position = models.CharField(max_length=255) # 지원하려는 기업의 지원하려는 직무
content = models.TextField()
due_date = models.DateTimeField(null=True)
question = models.TextField() # 작성하려는 자소서에서 답변할 질문
content = models.TextField() # 질문에 대한 답변 = contents
due_date = models.DateField(null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_finished = models.BooleanField(default=False)
Expand Down
1 change: 1 addition & 0 deletions resume/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Meta:
fields = (
"title",
"position",
"question",
"content",
"due_date",
"created_at",
Expand Down
3 changes: 2 additions & 1 deletion resume/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
path("all", views.GetAllResumeView.as_view(), name="get_all_resume"),
path("guidelines", views.GetGuidelinesView.as_view(), name="get_guidelines"),
path("generate", views.GenerateResumeView.as_view(), name="generate_resume"),
path("", views.PostResumeView.as_view(), name="post_resume"),
# path("", views.PostResumeView.as_view(), name="post_resume"),
path("update/<int:id>", views.UpdateResumeView.as_view(), name="update_resume"),
path("scrap/<int:id>", views.ScrapResumeView.as_view(), name="scrap_resume"),
path("chat", views.ChatView.as_view(), name="chat"),
path("<int:pk>", views.GetResumeView.as_view(), name="update_resume"),
]
2 changes: 1 addition & 1 deletion resume/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import environ

from pinecone import Pinecone
# from utils.openai_call import get_embedding
from utils.openai_call import get_embedding

from langchain_community.chat_models import ChatOpenAI
from langchain.chains import ConversationChain
Expand Down
154 changes: 99 additions & 55 deletions resume/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,25 @@ class GenerateResumeView(APIView):
summary="자기소개서 생성",
description="답변을 기반으로 자기소개서를 생성합니다.",
responses={
200: inline_serializer(
name="GenerateResumeResponse",
fields={
"result": serializers.CharField(),
},
)
200: PostResumeSerializer
},
parameters=[
OpenApiParameter(
name="title",
type=str,
description="자소서 제목",
),
OpenApiParameter(
name="position",
type=str,
description="지원하려는 직무",
),
OpenApiParameter(
name="due_date",
type=str,
style="date",
description="공고 마감기한. 그냥 str 형식으로 \"2024-04-10\" 이렇게 보내주삼",
),
OpenApiParameter(
name="question",
type=str,
Expand Down Expand Up @@ -150,24 +161,14 @@ class GenerateResumeView(APIView):
],
)
def post(self, request):
serializer = PostResumeSerializer(data=request.data)

# 데이터 유효성 검사
if serializer.is_valid():
# 유효한 데이터의 경우, 자소서 저장
serializer.save(
user=request.user
) # 현재 로그인한 사용자를 메모의 user 필드에 저장
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
# 데이터가 유효하지 않은 경우, 에러 메시지 반환
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

question = request.GET.get("question")
guidelines = request.GET.get("guidelines")
answers = request.GET.get("answers")
free_answer = request.GET.get("free_answer")
favor_info = request.GET.get("favor_info")
title = request.data["title"]
position = request.data["position"]
due_date = request.data["due_date"]
question = request.data["question"]
guidelines = request.data["guidelines"]
answers = request.data["answers"]
free_answer = request.data["free_answer"]
favor_info = request.data["favor_info"]

# 답변을 guideline + answer + free_answer로 구성
total_answer = ""
Expand Down Expand Up @@ -201,47 +202,89 @@ def post(self, request):

# 자소서 생성
generated_self_introduction = get_chat_openai(prompt)
generated_self_introduction_json = {"result": generated_self_introduction}

return JsonResponse(generated_self_introduction_json, status=200)


class PostResumeView(APIView):
permission_classes = [IsAuthenticated]

@extend_schema(
summary="자기소개서 등록",
description="자기소개서를 등록합니다.",
responses={200: PostResumeSerializer},
request={
"application/json": {
"type": "object",
"properties": {
"title": {"type": "string"},
"position": {"type": "string"},
"content": {"type": "string"},
"due_date": {"type": "string"},
},
},
},
)
def post(self, request):
serializer = PostResumeSerializer(data=request.data)
serializer = PostResumeSerializer(data={
"title": title,
"position": position,
"question": question,
"content": generated_self_introduction,
"due_date": due_date,
"is_finished": False,
"is_liked": False
})

# 데이터 유효성 검사
if serializer.is_valid():
# 유효한 데이터의 경우, 자소서 저장
serializer.save(
saved_instance = serializer.save(
user=request.user
) # 현재 로그인한 사용자를 메모의 user 필드에 저장
return Response(serializer.data, status=status.HTTP_201_CREATED)
) # 현재 로그인한 사용자를 자소서의 user 필드에 저장
return Response({"id": saved_instance.id}, status=status.HTTP_201_CREATED)
else:
# 데이터가 유효하지 않은 경우, 에러 메시지 반환
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


# class PostResumeView(APIView):
# permission_classes = [IsAuthenticated]
#
# @extend_schema(
# summary="자기소개서 등록",
# description="자기소개서를 등록합니다.",
# responses={200: PostResumeSerializer},
# request={
# "application/json": {
# "type": "object",
# "properties": {
# "title": {"type": "string"},
# "position": {"type": "string"},
# "content": {"type": "string"},
# "due_date": {"type": "string"},
# },
# },
# },
# )
# def post(self, request):
# serializer = PostResumeSerializer(data=request.data)
#
# # 데이터 유효성 검사
# if serializer.is_valid():
# # 유효한 데이터의 경우, 자소서 저장
# serializer.save(
# user=request.user
# ) # 현재 로그인한 사용자를 메모의 user 필드에 저장
# return Response(serializer.data, status=status.HTTP_201_CREATED)
# else:
# # 데이터가 유효하지 않은 경우, 에러 메시지 반환
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

class GetResumeView(APIView):
permission_classes = [IsAuthenticated]

def get_object(self, pk, user):
try:
resume = Resume.objects.get(pk=pk)
# 메모를 작성한 유저와 현재 요청 유저가 동일한지 확인
if resume.user != user:
raise Http404("해당 메모에 접근할 권한이 없습니다.")
return resume
except resume.DoesNotExist:
raise Http404

@extend_schema(
summary="특정 자소서를 받아옵니다.",
description="사용자가 작성한 특정 자소서의 디테일을 받아옵니다.",
responses={200: PostResumeSerializer},
)
def get(self, request, pk, format=None):
print(pk)
resume = self.get_object(pk, request.user)
serializer = PostResumeSerializer(resume)
return Response(serializer.data, status=status.HTTP_200_OK)


class UpdateResumeView(APIView):
permission_classes = [IsAuthenticated] # 인증된 사용자만 접근 가능하도록 설정
permission_classes = [IsAuthenticated]

@extend_schema(
summary="자기소개서 업데이트",
Expand Down Expand Up @@ -320,7 +363,8 @@ def post(self, request):
query = request.data.query
chatbot_answer = run_llm(query=query)

return Response(
return JsonResponse(
{"answer": chatbot_answer},
status=status.HTTP_200_OK,
)
)

0 comments on commit a59b3bb

Please sign in to comment.