Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
戒酒的李白
2025-02-12 01:45:45 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
82089852c9151e99f9e9ea2419f342e4d9bcd50f
82089852
1 parent
12a8732b
Supports integration of two models from DeepSeek for analysis!
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
6 deletions
README-CN.md
README.md
utils/ai_analyzer.py
README-CN.md
View file @
8208985
...
...
@@ -42,7 +42,10 @@
-
[
MySQL
](
https://www.mysql.com/
)
数据库
-
[
Conda
](
https://docs.conda.io/en/latest/
)
(可选,用于环境管理)
-
合法的微博账号(用于数据采集)
-
OpenAI API密钥或Anthropic(Claude)API密钥(用于AI分析功能)
-
以下API密钥中至少需要一个(用于AI分析功能):
-
OpenAI API密钥
-
Anthropic(Claude)API密钥
-
DeepSeek API密钥
### 安装步骤
...
...
@@ -78,10 +81,18 @@
# Anthropic API配置(使用Claude模型必需)
export ANTHROPIC_API_KEY="你的anthropic密钥"
# DeepSeek API配置(使用DeepSeek模型必需)
export DEEPSEEK_API_KEY="你的deepseek密钥"
```
注意:至少需要配置一个API密钥才能使用AI分析功能。
支持的AI模型:
- OpenAI:GPT-3.5-Turbo、GPT-4
- Anthropic:Claude-3(Opus、Sonnet、Haiku)
- DeepSeek:DeepSeek-V3(deepseek-chat)、DeepSeek-R1(deepseek-reasoner)
5. 启动Flask应用:
```
bash
...
...
@@ -106,6 +117,7 @@
-
**[TensorFlow](https://www.tensorflow.org/)**
或
**[PyTorch](https://pytorch.org/)**
- 深度学习框架,用于高级模型开发。
-
**[OpenAI GPT](https://openai.com/)**
- 先进的语言模型,用于文本分析。
-
**[Anthropic Claude](https://www.anthropic.com/)**
- 智能AI模型,用于复杂文本分析。
-
**[DeepSeek](https://deepseek.com/)**
- 先进的中英双语AI模型。
## 🤝 贡献
...
...
README.md
View file @
8208985
...
...
@@ -40,7 +40,10 @@ Follow the steps below to run the project on your system.
-
[
MySQL
](
https://www.mysql.com/
)
Database
-
[
Conda
](
https://docs.conda.io/en/latest/
)
(
optional,
for environment management)
-
A valid Weibo account (for data collection)
-
OpenAI API key or Anthropic (Claude) API key for AI analysis features
-
At least one of the following API keys for AI analysis features:
-
OpenAI API key
-
Anthropic (Claude) API key
-
DeepSeek API key
### Installation Steps
...
...
@@ -76,10 +79,18 @@ Follow the steps below to run the project on your system.
# For Anthropic API (Required for Claude models)
export ANTHROPIC_API_KEY="your-anthropic-key"
# For DeepSeek API (Required for DeepSeek models)
export DEEPSEEK_API_KEY="your-deepseek-key"
```
Note: At least one API key must be configured to use AI analysis features.
Supported AI Models:
- OpenAI: GPT-3.5-Turbo, GPT-4
- Anthropic: Claude-3 (Opus, Sonnet, Haiku)
- DeepSeek: DeepSeek-V3 (deepseek-chat), DeepSeek-R1 (deepseek-reasoner)
6. Start the Flask application:
```
bash
...
...
@@ -104,6 +115,7 @@ The Weibo Public Opinion Analysis and Prediction System employs a range of moder
-
**[TensorFlow](https://www.tensorflow.org/)**
或
**[PyTorch](https://pytorch.org/)**
- Deep learning frameworks used for advanced model development.
-
**[OpenAI GPT](https://openai.com/)**
- Advanced language models for text analysis.
-
**[Anthropic Claude](https://www.anthropic.com/)**
- AI models for sophisticated text analysis.
-
**[DeepSeek](https://deepseek.com/)**
- Advanced Chinese-English bilingual AI models.
## 🤝 Contribution
...
...
utils/ai_analyzer.py
View file @
8208985
...
...
@@ -11,14 +11,21 @@ class AIAnalyzer:
# 从环境变量获取API密钥
self
.
openai_key
=
os
.
getenv
(
'OPENAI_API_KEY'
)
self
.
claude_key
=
os
.
getenv
(
'ANTHROPIC_API_KEY'
)
self
.
deepseek_key
=
os
.
getenv
(
'DEEPSEEK_API_KEY'
)
if
not
self
.
openai_key
and
not
self
.
claude_key
:
raise
ValueError
(
"请至少设置一个API密钥 (OPENAI_API_KEY 或 ANTHROPIC_API_KEY)"
)
if
not
any
([
self
.
openai_key
,
self
.
claude_key
,
self
.
deepseek_key
]):
raise
ValueError
(
"请至少设置一个API密钥 (OPENAI_API_KEY, ANTHROPIC_API_KEY 或 DEEPSEEK_API_KEY)"
)
if
self
.
openai_key
:
openai
.
api_key
=
self
.
openai_key
if
self
.
claude_key
:
self
.
claude_client
=
anthropic
.
Anthropic
(
api_key
=
self
.
claude_key
)
if
self
.
deepseek_key
:
# 配置DeepSeek API
self
.
deepseek_client
=
openai
.
OpenAI
(
api_key
=
self
.
deepseek_key
,
base_url
=
"https://api.deepseek.com/v1"
)
# 支持的模型列表
self
.
supported_models
=
{
...
...
@@ -35,7 +42,11 @@ class AIAnalyzer:
'claude-3-haiku-20240307'
:
{
'provider'
:
'anthropic'
,
'max_tokens'
:
2000
,
'cost_per_1k'
:
0.0025
},
'claude-2.1'
:
{
'provider'
:
'anthropic'
,
'max_tokens'
:
100000
,
'cost_per_1k'
:
0.008
},
'claude-2.0'
:
{
'provider'
:
'anthropic'
,
'max_tokens'
:
100000
,
'cost_per_1k'
:
0.008
},
'claude-instant-1.2'
:
{
'provider'
:
'anthropic'
,
'max_tokens'
:
100000
,
'cost_per_1k'
:
0.0015
}
'claude-instant-1.2'
:
{
'provider'
:
'anthropic'
,
'max_tokens'
:
100000
,
'cost_per_1k'
:
0.0015
},
# DeepSeek 模型
'deepseek-chat'
:
{
'provider'
:
'deepseek'
,
'max_tokens'
:
4000
,
'cost_per_1k'
:
0.002
},
# DeepSeek-V3
'deepseek-reasoner'
:
{
'provider'
:
'deepseek'
,
'max_tokens'
:
4000
,
'cost_per_1k'
:
0.003
}
# DeepSeek-R1
}
# 不同深度的分析提示词
...
...
@@ -129,13 +140,20 @@ class AIAnalyzer:
model_type
,
max_tokens
)
el
se
:
# anthropic
el
if
provider
==
'anthropic'
:
result
=
await
self
.
_analyze_with_claude
(
messages_text
,
system_prompt
,
model_type
,
max_tokens
)
elif
provider
==
'deepseek'
:
result
=
await
self
.
_analyze_with_deepseek
(
messages_text
,
system_prompt
,
model_type
,
max_tokens
)
if
result
:
all_results
.
extend
(
result
)
...
...
@@ -235,6 +253,32 @@ class AIAnalyzer:
logging
.
error
(
f
"Claude API调用失败: {e}"
)
return
[]
async
def
_analyze_with_deepseek
(
self
,
messages_text
:
str
,
system_prompt
:
str
,
model
:
str
,
max_tokens
:
int
)
->
List
[
Dict
]:
"""使用DeepSeek API进行分析"""
try
:
response
=
await
self
.
deepseek_client
.
chat
.
completions
.
create
(
model
=
model
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
system_prompt
},
{
"role"
:
"user"
,
"content"
:
f
"请分析以下消息:
\n
{messages_text}"
}
],
temperature
=
0.3
,
max_tokens
=
max_tokens
,
response_format
=
{
"type"
:
"json_object"
}
# 强制JSON响应格式
)
result
=
json
.
loads
(
response
.
choices
[
0
]
.
message
.
content
)
if
isinstance
(
result
,
dict
)
and
'analysis_results'
in
result
:
return
result
[
'analysis_results'
]
else
:
logging
.
error
(
f
"DeepSeek API返回格式不正确: {response.choices[0].message.content}"
)
return
[]
except
Exception
as
e
:
logging
.
error
(
f
"DeepSeek API调用失败: {e}"
)
return
[]
def
format_analysis_for_display
(
self
,
analysis
:
Dict
)
->
Dict
:
"""将分析结果格式化为前端显示格式"""
base_result
=
{
...
...
Please
register
or
login
to post a comment