Compare commits

..

5 Commits
main ... ZHL

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Chameleon" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/AI-Writing-main/writing-assistant/templates" />
</list>
</option>
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AgentMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AskMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Ask2AgentMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EditMigrationStateService">
<option name="migrationStatus" value="COMPLETED" />
</component>
</project>

@ -0,0 +1,31 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="16">
<item index="0" class="java.lang.String" itemvalue="marshmallow-sqlalchemy" />
<item index="1" class="java.lang.String" itemvalue="sqlalchemy-utils" />
<item index="2" class="java.lang.String" itemvalue="Flask-WTF" />
<item index="3" class="java.lang.String" itemvalue="marshmallow" />
<item index="4" class="java.lang.String" itemvalue="mockldap" />
<item index="5" class="java.lang.String" itemvalue="apispec" />
<item index="6" class="java.lang.String" itemvalue="Flask-SQLAlchemy" />
<item index="7" class="java.lang.String" itemvalue="Flask-Login" />
<item index="8" class="java.lang.String" itemvalue="hiro" />
<item index="9" class="java.lang.String" itemvalue="WTForms" />
<item index="10" class="java.lang.String" itemvalue="email_validator" />
<item index="11" class="java.lang.String" itemvalue="Flask-JWT-Extended" />
<item index="12" class="java.lang.String" itemvalue="Flask-Limiter" />
<item index="13" class="java.lang.String" itemvalue="prison" />
<item index="14" class="java.lang.String" itemvalue="nose2" />
<item index="15" class="java.lang.String" itemvalue="Flask-Babel" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/RGproject.iml" filepath="$PROJECT_DIR$/.idea/RGproject.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -12,6 +12,7 @@ from typing import Dict, Any, Optional, List
from urllib.parse import urljoin
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from openai import OpenAI
# 确保正确的导入路径
current_dir = os.path.dirname(os.path.abspath(__file__))
@ -63,6 +64,7 @@ except Exception as e:
ANTHROPIC = "Anthropic"
GOOGLE = "Google"
LMSTUDIO = "LMStudio"
DEEPSEEK = "DeepSeek"
class LLMModel(BaseModel):
display_name: str
@ -160,6 +162,37 @@ class FastLLMClient:
return prompt
def _call_deepseek_api(self, prompt: str, model: LLMModel, max_tokens: int = 1000, **kwargs) -> str:
"""调用DeepSeek API通过openai包官方兼容方式"""
# 构建 system_message
messages = []
if kwargs.get('system_message'):
messages.append({"role": "system", "content": kwargs['system_message']})
messages.append({"role": "user", "content": prompt})
# 创建 OpenAI 客户端,指定 DeepSeek base_url
client = OpenAI(
api_key=getattr(model, "api_key", ""),
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model=model.model_name,
messages=messages,
temperature=kwargs.get('temperature', 0.7),
max_tokens=max_tokens,
stream=False
)
print("==================deepseek response===================")
#print(response.choices[0].message.content)
print("================deepseek response end=================")
result = response.model_dump()
return result['choices'][0]['message']['content']
def _call_openai_api(self, prompt: str, model: LLMModel, max_tokens: int = 1000,
**kwargs) -> str:
"""调用OpenAI API - 优化版本"""
@ -313,16 +346,18 @@ class FastLLMClient:
elif model.provider == ModelProvider.GOOGLE:
response = self._call_google_api(context_prompt, model, max_tokens, **kwargs)
elif model.provider == ModelProvider.LMSTUDIO:
# LMStudio使用OpenAI兼容API
response = self._call_openai_api(context_prompt, model, max_tokens, **kwargs)
elif model.provider == ModelProvider.DEEPSEEK:
response = self._call_deepseek_api(context_prompt, model, max_tokens, **kwargs)
else:
raise ValueError(f"不支持的模型供应商: {model.provider}")
elapsed_time = time.time() - start_time
print(f"API调用耗时: {elapsed_time:.2f}")
return response.strip()
return response.strip()
except requests.exceptions.Timeout:
raise Exception("API调用超时")
except requests.exceptions.ConnectionError:

@ -13,6 +13,7 @@ class ModelProvider(str, Enum):
ANTHROPIC = "Anthropic"
DEEPSEEK = "DeepSeek"
GEMINI = "Gemini"
GOOGLE = "Google"
GROQ = "Groq"
OPENAI = "OpenAI"
OLLAMA = "Ollama"

@ -9,6 +9,8 @@ import asyncio
import logging
from typing import Dict, List, Optional, Any
from config import get_config
import re
# 配置调试日志
logging.basicConfig(level=logging.DEBUG)
@ -41,14 +43,14 @@ class AIService:
if user_settings:
return user_settings
return self.default_settings
def _create_llm_model(self, settings: Dict) -> LLMModel:
"""创建LLM模型对象"""
try:
provider = ModelProvider(settings['provider'])
except ValueError:
provider = ModelProvider.OLLAMA
logger.warning(f"未知的provider: {settings['provider']}已回退到OLLAMA")
model = LLMModel(
display_name=settings['model'],
model_name=settings['model'],
@ -158,6 +160,8 @@ Requirements:
def analyze_content(self, content: str, stage: str, context: Dict,
user_settings: Optional[Dict] = None) -> Dict:
"""分析写作内容"""
settings = self._get_ai_settings(user_settings)
model = self._create_llm_model(settings)
@ -224,6 +228,8 @@ Provide constructive feedback that helps the student write like an American stud
json_mode=True, # 启用JSON模式
temperature=0.3 # 降低温度以提高准确性
)
# 尝试解析JSON响应
try:

@ -9,14 +9,14 @@
"grade": "初中",
"brainstorm_content": "",
"outline_content": "",
"writing_content": "",
"ai_feedback": "",
"final_score": 0,
"scores": "{\"brainstorm\": 0, \"outline\": 0, \"writing\": 0, \"highlight\": 0}",
"writing_content": "Generative AI are a hot topic. Some peoples thinks it make students lazy. Because they just use AI to do they homework. This is not completely true. Actually, if use correct, AI can helps student learning better. For example, when a student don't understand a concept, they can asks AI for explain. It give instant answer, more better than just search online. But, student must to think by themselves first. Rely on AI too much is bad. It can damaging they ability for independent thinking. So, the key is balance. We should use AI like a tool, not a replacement of our brain. In conclude, AI have both positive and negative affects. It is depend on how we uses it.",
"ai_feedback": "{\"writing_analysis\": {\"strengths\": [\"观点辩证学生能认识到AI的双面性既指出过度依赖的危害也肯定合理使用的价值\", \"结构完整:包含问题提出、正反论证和结论的基本框架\", \"立场明确:最终提出'关键在于平衡'的核心观点\", \"举例具体:用'不理解概念时询问AI'的案例支撑论点\"], \"issues\": [\"论点展开不足:缺乏分论点支撑,正反论证都停留在表面陈述\", \"学术规范缺失:没有明确的主题句和过渡词,段落间逻辑跳跃\", \"语言不地道:存在中式英语表达和语法错误\", \"论证深度不够:未涉及具体研究数据或教育理论支撑\", \"批判性思维薄弱未分析AI如何具体影响不同学习能力的学生\"], \"suggestions\": [{\"讲解\": \"建立清晰论点结构,使用主题句+支撑句模式\", \"示例\": \"While critics argue that generative AI fosters academic laziness, this perspective overlooks its potential as a cognitive tool when used intentionally. For instance, AI can serve as a 24/7 learning partner that provides customized explanations...\"}, {\"讲解\": \"增加学术过渡词和逻辑连接\", \"示例\": \"Conversely, unmonitored AI use may indeed undermine metacognitive skills. A study by Stanford University found that students who over-relied on AI for problem-solving showed decreased ability to...\"}, {\"讲解\": \"用具体案例替代泛泛而谈\", \"示例\": \"In Mr. Johnson's 8th-grade science class, students using AI for hypothesis refinement scored 23% higher on critical thinking assessments than those using traditional methods...\"}, {\"讲解\": \"强化批判性分析维度\", \"示例\": \"The central dilemma isn't whether to use AI, but how to design usage protocols that maximize its scaffolding function while minimizing dependency. Educators might consider...\"}, {\"讲解\": \"使用更地道的学术表达\", \"示例\": \"Rather than replacing human intellect, generative AI should function as a collaborative tool that amplifies our cognitive capabilities—much like calculators enhanced mathematical reasoning without eliminating the need to understand core principles.\"}], \"next_steps\": [\"学习美国中学议论文的经典五段式结构(引言-论点1-论点2-反论点-结论)\", \"收集关于AI教育影响的具体研究数据和权威来源\", \"练习使用学术过渡词however, furthermore, consequently等\", \"阅读《纽约时报》教育版相关文章,观察地道议论文表达\", \"尝试写作时先建立论证大纲,再展开具体段落\"]}}",
"final_score": 40,
"scores": "{\"brainstorm\": 0, \"outline\": 0, \"writing\": 2, \"highlight\": 2}",
"status": "writing",
"word_count": 0,
"word_count": 546,
"created_at": "2025-10-01T13:18:06.056827",
"updated_at": "2025-10-09T10:43:01.941600",
"updated_at": "2025-10-15T17:10:55.984866",
"completed_at": null
}
]

@ -6,10 +6,10 @@
"grade": "高中",
"subject": "英语",
"created_at": "2025-07-07T23:12:26.092924",
"ai_provider": "",
"ai_model": "",
"ai_api_key": "",
"ai_base_url": "",
"updated_at": "2025-10-09T10:43:25.409404"
"ai_provider": "DeepSeek",
"ai_model": "deepseek-chat",
"ai_api_key": "sk-ccdfd6d1973b45a084decf2654cf171a",
"ai_base_url": "https://api.deepseek.com",
"updated_at": "2025-10-15T17:05:01.345349"
}
]

@ -64,9 +64,9 @@
</div>
<!-- 写作内容区域 -->
<div class="writing-content">
<div class="row g-3">
<div class="col-xl-8 col-lg-7 col-md-8">
<div class="writing-content writing-flex">
<div class="writing-main">
<!-- 构思阶段 -->
<div class="stage-content active" id="brainstorm-stage">
<div class="stage-header">
@ -397,7 +397,7 @@
</div>
</div>
<div class="col-xl-4 col-lg-5 col-md-4">
<div class="ai-assistant-panel">
<!-- AI助手面板 -->
<div class="ai-assistant">
<div class="ai-header">
@ -424,7 +424,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
@ -445,6 +445,51 @@
{% block head %}
<style>
.writing-content.writing-flex {
display: flex;
gap: 1.5rem;
width: 100%;
}
.writing-main {
flex: 6 1 0;
min-width: 0;
}
.ai-assistant-panel {
flex: 4 1 0;
min-width: 0;
display: flex;
flex-direction: column;
}
.ai-assistant {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
position: sticky;
top: 20px;
height: auto; /* 改为自动高度 */
min-height: 400px; /* 适当的最小高度 */
display: flex;
flex-direction: column;
}
@media (max-width: 1200px) {
.writing-content.writing-flex {
flex-direction: column;
}
.writing-main,
.ai-assistant-panel {
flex: none;
width: 100%;
max-width: 100%;
}
}
.writing-container {
max-width: 1600px;
margin: 0 auto;
@ -586,6 +631,7 @@
padding: 6px 12px;
}
/*
.ai-assistant {
background: white;
border-radius: 10px;
@ -598,7 +644,7 @@
display: flex;
flex-direction: column;
}
*/
.ai-header {
margin-bottom: 15px;
text-align: center;

@ -0,0 +1,22 @@
{
"ai_model": {
"value": "gpt-3.5-turbo",
"description": "默认配置: ai_model",
"updated_at": "2025-10-14T19:10:47.462376"
},
"max_word_count": {
"value": 800,
"description": "默认配置: max_word_count",
"updated_at": "2025-10-14T19:10:47.476253"
},
"enable_ai_suggestions": {
"value": true,
"description": "默认配置: enable_ai_suggestions",
"updated_at": "2025-10-14T19:10:47.491171"
},
"auto_save_interval": {
"value": 30,
"description": "默认配置: auto_save_interval",
"updated_at": "2025-10-14T19:10:47.504964"
}
}

@ -0,0 +1,22 @@
[
{
"id": 1,
"user_id": 1,
"title": "写作项目 - 2025年10月14日 19:11",
"topic": "AI生成对学习的影响\n",
"article_type": "议论文",
"subject": "英语",
"grade": "大学",
"brainstorm_content": "",
"outline_content": "",
"writing_content": "Generative AI, such as large language models, are becoming increasingly popular. They offers students a powerful tool for complete homework and generating ideas. However, its impact on learning ability are a subject of intense debate.\n\nOn one hand, it is argued that AI hinder the development of critical thinking. When a student rely on AI to write essays, they doesn't engage in the rigorous process of research and analysis their own. This lead to a superficial understanding and a failure to develop their own voice. Furthermore, the convenience of AI means that less effort are put into mastering fundamental skills, such as grammar and structuring arguments.\n\nConversely, supporter of AI argues that it serve as a personalized tutor. It can explaining complex concepts in different ways until the student understands. Used responsibly, AI could helps a student to brainstorm and to organize their thoughts more better than before.\n\nIn conclusion, the effect of generative AI on learning ability depend not on the technology itself, but on how it is been used by the student. The key lies in using it as a supplement for one's own thinking, not as a replacement.",
"ai_feedback": "{\"writing_analysis\": {\"strengths\": [\"内容已提交\"], \"issues\": [\"AI分析格式异常\"], \"suggestions\": [\"建议重新分析\"], \"next_steps\": [\"继续完善内容\"], \"raw_response\": \"```json\\n{\\n \\\"strengths\\\": [\\n \\\"文章结构清晰,采用了标准的议论文三段式结构:引言-正反论证-结论\\\",\\n \\\"论点平衡同时探讨了AI对学习的积极和消极影响\\\",\\n \\\"结论有力,指出关键在于如何使用而非技术本身,体现了辩证思维\\\",\\n \\\"使用了适当的学术词汇如'critical thinking''personalized tutor'等\\\"\\n ],\\n \\n \\\"issues\\\": [\\n \\\"语法错误较多,特别是主谓一致问题(如'are'代替'is''doesn't'代替'don't'\\\",\\n \\\"用词不够精确自然,存在中式英语痕迹(如'more better'\\\",\\n \\\"缺乏具体的例子和数据支持论点,论证深度不足\\\",\\n \\\"过渡词使用单一,段落间衔接不够流畅\\\",\\n \\\"论点发展不够充分,缺乏对美国学术写作中预期的深度分析\\\"\\n ],\\n \\n \\\"suggestions\\\": [\\n {\\n \\\"讲解\\\": \\\"修正语法错误,特别注意主谓一致和动词形式\\\",\\n \\\"示例\\\": \\\"Original: 'They offers students a powerful tool...' → Revised: 'They offer students a powerful tool...'\\\"\\n },\\n {\\n \\\"讲解\\\": \\\"使用更地道的表达方式,避免直译中文思维\\\",\\n \\\"示例\\\": \\\"Original: 'more better than before' → Revised: 'more effectively than they could on their own'\\\"\\n },\\n {\\n \\\"讲解\\\": \\\"增加具体例子加强论证说服力\\\",\\n \\\"示例\\\": \\\"Instead of: 'AI hinder the development of critical thinking' → Try: 'When students use AI to generate entire essays, they miss opportunities to develop essential skills like evaluating source credibility or constructing logical arguments—as demonstrated in a recent Stanford study showing AI users scored 23% lower on critical thinking assessments.'\\\"\\n },\\n {\\n \\\"讲解\\\": \\\"使用更丰富的过渡词和短语\\\",\\n \\\"示例\\\": \\\"Instead of: 'Conversely...' → Try: 'On the other hand, proponents contend that...' or 'However, an alternative perspective suggests...'\\\"\\n },\\n {\\n \\\"讲解\\\": \\\"加强论点深度,加入更细致的分析\\\",\\n \\\"示例\\\": \\\"Instead of simply stating AI can be a tutor, elaborate: 'When used strategically, AI can function as a 24/7 learning assistant—adapting explanations to individual learning styles and providing immediate feedback that would be impossible in a traditional classroom setting.'\\\"\\n }\\n ],\\n \\n \\\"next_steps\\\": [\\n \\\"系统学习英语主谓一致规则,特别是第三人称单数形式\\\",\\n \\\"多阅读美国学生的议论文范文,注意观察他们的论证方式和语言风格\\\",\\n \\\"练习使用具体的例子、数据和引用研究来支持论点\\\",\\n \\\"建立个人写作清单,检查常见的语法错误和表达问题\\\",\\n \\\"尝试写作时先专注于内容深度,再回头修改语言表达\\\"\\n ]\\n}\"}}",
"final_score": 60,
"scores": "{\"brainstorm\": 0, \"outline\": 0, \"writing\": 3, \"highlight\": 3}",
"status": "writing",
"word_count": 974,
"created_at": "2025-10-14T19:14:23.761019",
"updated_at": "2025-10-20T11:38:29.972058",
"completed_at": null
}
]

@ -0,0 +1,15 @@
[
{
"id": 1,
"username": "267278466@qq.com",
"password_hash": "07d0a715a160482331a556b514bee739$fe094c2d3e40fad4e83c6b06aaa95976c68e325bd899a003e7a2928edfe0fce8",
"grade": "大学",
"subject": "英语",
"ai_provider": "DeepSeek",
"ai_model": "deepseek-chat",
"ai_api_key": "sk-7d6a7dc91af1425cb4c231f0b53da09a",
"ai_base_url": "https://api.deepseek.com",
"created_at": "2025-10-14T19:10:47.461150",
"updated_at": "2025-10-20T10:56:10.318204"
}
]
Loading…
Cancel
Save