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
666ghj
2025-10-08 23:01:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
960608cee9660ba32ade96e91d609718887b2606
960608ce
1 parent
45bffb38
Migrate Forum Host and Keyword Optimizer to use OpenAI client.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
68 deletions
ForumEngine/llm_host.py
InsightEngine/tools/keyword_optimizer.py
ForumEngine/llm_host.py
View file @
960608c
...
...
@@ -3,8 +3,7 @@
使用硅基流动的Qwen3模型作为论坛主持人,引导多个agent进行讨论
"""
import
requests
import
json
from
openai
import
OpenAI
import
sys
import
os
from
typing
import
List
,
Dict
,
Any
,
Optional
...
...
@@ -39,13 +38,17 @@ class ForumHost:
api_key: 硅基流动API密钥,如果不提供则从配置文件读取
"""
self
.
api_key
=
api_key
or
GUIJI_QWEN3_API_KEY
self
.
base_url
=
"https://api.siliconflow.cn/v1/chat/completions"
self
.
model
=
"Qwen/Qwen3-235B-A22B-Instruct-2507"
# 使用更大的模型
if
not
self
.
api_key
:
raise
ValueError
(
"未找到硅基流动API密钥,请在config.py中设置GUIJI_QWEN3_API_KEY"
)
# 记录历史发言,避免重复
self
.
client
=
OpenAI
(
api_key
=
self
.
api_key
,
base_url
=
"https://api.siliconflow.cn/v1"
)
self
.
model
=
"Qwen/Qwen3-235B-A22B-Instruct-2507"
# Use larger model variant
# Track previous summaries to avoid duplicates
self
.
previous_summaries
=
[]
def
generate_host_speech
(
self
,
forum_logs
:
List
[
str
])
->
Optional
[
str
]:
...
...
@@ -204,43 +207,23 @@ class ForumHost:
@with_graceful_retry
(
SEARCH_API_RETRY_CONFIG
,
default_return
=
{
"success"
:
False
,
"error"
:
"API服务暂时不可用"
})
def
_call_qwen_api
(
self
,
system_prompt
:
str
,
user_prompt
:
str
)
->
Dict
[
str
,
Any
]:
"""调用Qwen API"""
headers
=
{
"Authorization"
:
f
"Bearer {self.api_key}"
,
"Content-Type"
:
"application/json"
}
data
=
{
"model"
:
self
.
model
,
"messages"
:
[
{
"role"
:
"system"
,
"content"
:
system_prompt
},
{
"role"
:
"user"
,
"content"
:
user_prompt
}
],
"max_tokens"
:
14639
,
"temperature"
:
0.6
,
"top_p"
:
0.9
}
try
:
response
=
requests
.
post
(
self
.
base_url
,
headers
=
headers
,
json
=
data
,
timeout
=
300
# 超时设置300s
response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
self
.
model
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
system_prompt
},
{
"role"
:
"user"
,
"content"
:
user_prompt
}
],
max_tokens
=
14639
,
temperature
=
0.6
,
top_p
=
0.9
,
)
response
.
raise_for_status
()
result
=
response
.
json
()
if
"choices"
in
result
and
len
(
result
[
"choices"
])
>
0
:
content
=
result
[
"choices"
][
0
][
"message"
][
"content"
]
if
response
.
choices
:
content
=
response
.
choices
[
0
]
.
message
.
content
return
{
"success"
:
True
,
"content"
:
content
}
else
:
return
{
"success"
:
False
,
"error"
:
"API返回格式异常"
}
except
requests
.
exceptions
.
Timeout
:
return
{
"success"
:
False
,
"error"
:
"API请求超时"
}
except
requests
.
exceptions
.
RequestException
as
e
:
return
{
"success"
:
False
,
"error"
:
f
"网络请求错误: {str(e)}"
}
except
Exception
as
e
:
return
{
"success"
:
False
,
"error"
:
f
"API调用异常: {str(e)}"
}
...
...
InsightEngine/tools/keyword_optimizer.py
View file @
960608c
...
...
@@ -3,7 +3,7 @@
使用Qwen AI将Agent生成的搜索词优化为更适合舆情数据库查询的关键词
"""
import
requests
from
openai
import
OpenAI
import
json
import
sys
import
os
...
...
@@ -46,11 +46,15 @@ class KeywordOptimizer:
api_key: 硅基流动API密钥,如果不提供则从配置文件读取
"""
self
.
api_key
=
api_key
or
GUIJI_QWEN3_API_KEY
self
.
base_url
=
"https://api.siliconflow.cn/v1/chat/completions"
self
.
model
=
"Qwen/Qwen3-30B-A3B-Instruct-2507"
if
not
self
.
api_key
:
raise
ValueError
(
"未找到硅基流动API密钥,请在config.py中设置GUIJI_QWEN3_API_KEY"
)
self
.
client
=
OpenAI
(
api_key
=
self
.
api_key
,
base_url
=
"https://api.siliconflow.cn/v1"
)
self
.
model
=
"Qwen/Qwen3-30B-A3B-Instruct-2507"
def
optimize_keywords
(
self
,
original_query
:
str
,
context
:
str
=
""
)
->
KeywordOptimizationResponse
:
"""
...
...
@@ -178,35 +182,22 @@ class KeywordOptimizer:
@with_graceful_retry
(
SEARCH_API_RETRY_CONFIG
,
default_return
=
{
"success"
:
False
,
"error"
:
"关键词优化服务暂时不可用"
})
def
_call_qwen_api
(
self
,
system_prompt
:
str
,
user_prompt
:
str
)
->
Dict
[
str
,
Any
]:
"""调用Qwen API"""
headers
=
{
"Authorization"
:
f
"Bearer {self.api_key}"
,
"Content-Type"
:
"application/json"
}
data
=
{
"model"
:
self
.
model
,
"messages"
:
[
{
"role"
:
"system"
,
"content"
:
system_prompt
},
{
"role"
:
"user"
,
"content"
:
user_prompt
}
],
"max_tokens"
:
10000
,
"temperature"
:
0.7
}
try
:
response
=
requests
.
post
(
self
.
base_url
,
headers
=
headers
,
json
=
data
,
timeout
=
30
)
response
.
raise_for_status
()
result
=
response
.
json
()
if
"choices"
in
result
and
len
(
result
[
"choices"
])
>
0
:
content
=
result
[
"choices"
][
0
][
"message"
][
"content"
]
response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
self
.
model
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
system_prompt
},
{
"role"
:
"user"
,
"content"
:
user_prompt
}
],
max_tokens
=
10000
,
temperature
=
0.7
,
)
if
response
.
choices
:
content
=
response
.
choices
[
0
]
.
message
.
content
return
{
"success"
:
True
,
"content"
:
content
}
else
:
return
{
"success"
:
False
,
"error"
:
"API返回格式异常"
}
except
requests
.
exceptions
.
RequestException
as
e
:
return
{
"success"
:
False
,
"error"
:
f
"网络请求错误: {str(e)}"
}
except
Exception
as
e
:
return
{
"success"
:
False
,
"error"
:
f
"API调用异常: {str(e)}"
}
...
...
Please
register
or
login
to post a comment