Skip to content

Conversation

BigPouw
Copy link
Collaborator

@BigPouw BigPouw commented Aug 20, 2025

1.將OPENAI換成Gemini

Copy link

@Copilot Copilot AI left a 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})
#難度判斷
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
#難度判斷
# 難度判斷

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
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
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
# 建立評估與題目的關聯
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
# 建立評估與題目的關聯
# 建立評估與題目的關聯

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
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
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
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
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
Copy link
Preview

Copilot AI Aug 20, 2025

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.

Suggested change
from questions.models import QuestionTag

Copilot uses AI. Check for mistakes.

@BigPouw BigPouw force-pushed the PROWEB-35 branch 4 times, most recently from 0201dd0 to 392993d Compare August 26, 2025 03:02
1.將OPENAI換成Gemini
2.修正會重複創建題目的錯誤
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants