-
Notifications
You must be signed in to change notification settings - Fork 0
PROWEB-35 改成使用Gemini #31
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the AI service from OpenAI to Google's Gemini API for analyzing programming question difficulty. The change replaces the OpenAI client with Gemini's GenerativeAI and adds comprehensive question management functionality.
- Replaces OpenAI API integration with Google Gemini API
- Adds question creation and update functionality with database persistence
- Implements difficulty evaluation storage with question association
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
ai/views.py
Outdated
|
||
return JsonResponse({'result': difficulty_content}) | ||
#難度判斷 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has inconsistent indentation with extra spaces before the hash symbol. Should be '# 難度判斷' to match standard Python comment formatting.
#難度判斷 | |
# 難度判斷 |
Copilot uses AI. Check for mistakes.
ai/views.py
Outdated
tag_objects = QuestionTag.objects.filter(id__in=tags) | ||
question.tags.set(tag_objects) | ||
except Exception as e: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silent exception handling with 'pass' makes debugging difficult. Consider logging the exception or returning a meaningful error response to help identify issues during question creation.
pass | |
logging.exception("Error creating question or setting topics/tags") | |
return JsonResponse({'error': f'Error creating question: {str(e)}'}, status=500) |
Copilot uses AI. Check for mistakes.
ai/views.py
Outdated
question.tags.set(tag_objects) | ||
except Exception as e: | ||
pass | ||
# 建立評估與題目的關聯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has inconsistent indentation with extra spaces before the hash symbol. Should be '# 建立評估與題目的關聯' to match standard Python comment formatting.
# 建立評估與題目的關聯 | |
# 建立評估與題目的關聯 |
Copilot uses AI. Check for mistakes.
ai/views.py
Outdated
user_id = data.get('user_id') or request.user.id if hasattr(request, 'user') else None | ||
if user_id: | ||
try: | ||
from accounts.models import User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import statements should be placed at the top of the file rather than inside functions. Consider moving this import to the top with other imports for better code organization and potential performance benefits.
from accounts.models import User |
Copilot uses AI. Check for mistakes.
ai/views.py
Outdated
topic_objects = Topic.objects.filter(id__in=topics) | ||
question.topics.set(topic_objects) | ||
if tags: | ||
from questions.models import QuestionTag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import statements should be placed at the top of the file rather than inside functions. Consider moving this import to the top with other imports for better code organization and potential performance benefits.
from questions.models import QuestionTag | |
topic_objects = Topic.objects.filter(id__in=topics) | |
question.topics.set(topic_objects) | |
if tags: |
Copilot uses AI. Check for mistakes.
ai/views.py
Outdated
topic_objects = Topic.objects.filter(id__in=topics) | ||
question.topics.set(topic_objects) | ||
if tags: | ||
from questions.models import QuestionTag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import statements should be placed at the top of the file rather than inside functions. Consider moving this import to the top with other imports for better code organization and potential performance benefits.
from questions.models import QuestionTag |
Copilot uses AI. Check for mistakes.
0201dd0
to
392993d
Compare
1.將OPENAI換成Gemini 2.修正會重複創建題目的錯誤
1.將OPENAI換成Gemini