|
@@ -1,5 +1,5 @@
|
|
import os, json, time, asyncio
|
|
import os, json, time, asyncio
|
|
-from base_config import ai_key, path
|
|
|
|
|
|
+from base_config import ai_key, path, file_summary_app_id, commit_summary_app_id, filter_code_files_app_id, analysis_results_app_id
|
|
from fastapi import APIRouter, BackgroundTasks
|
|
from fastapi import APIRouter, BackgroundTasks
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
from pydantic import BaseModel
|
|
from pydantic import BaseModel
|
|
@@ -40,9 +40,8 @@ def generate_repo_path(uuid, repo_url):
|
|
|
|
|
|
async def file_summary(content):
|
|
async def file_summary(content):
|
|
response = Application.call(
|
|
response = Application.call(
|
|
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
|
|
|
|
api_key=ai_key,
|
|
api_key=ai_key,
|
|
- app_id='ef50d70cd4074a899a09875e6a6e36ea',
|
|
|
|
|
|
+ app_id=file_summary_app_id,
|
|
prompt=content)
|
|
prompt=content)
|
|
if response.status_code == HTTPStatus.OK:
|
|
if response.status_code == HTTPStatus.OK:
|
|
try:
|
|
try:
|
|
@@ -59,9 +58,8 @@ async def file_summary(content):
|
|
|
|
|
|
async def commit_summary(content):
|
|
async def commit_summary(content):
|
|
response = Application.call(
|
|
response = Application.call(
|
|
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
|
|
|
|
api_key=ai_key,
|
|
api_key=ai_key,
|
|
- app_id='88426cc2301b44bea5d28d41d187ebf2',
|
|
|
|
|
|
+ app_id=commit_summary_app_id,
|
|
prompt=content)
|
|
prompt=content)
|
|
if response.status_code == HTTPStatus.OK:
|
|
if response.status_code == HTTPStatus.OK:
|
|
try:
|
|
try:
|
|
@@ -78,9 +76,8 @@ async def commit_summary(content):
|
|
|
|
|
|
def filter_code_files(prompt):
|
|
def filter_code_files(prompt):
|
|
response = Application.call(
|
|
response = Application.call(
|
|
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
|
|
|
|
api_key=ai_key,
|
|
api_key=ai_key,
|
|
- app_id='b0725a23eafd4422bfa7d5eff278af7c',
|
|
|
|
|
|
+ app_id=filter_code_files_app_id,
|
|
prompt=prompt)
|
|
prompt=prompt)
|
|
if response.status_code == HTTPStatus.OK:
|
|
if response.status_code == HTTPStatus.OK:
|
|
try:
|
|
try:
|
|
@@ -102,9 +99,8 @@ def analysis_results(local_path,path):
|
|
for line_num, line in enumerate(f, start=1):
|
|
for line_num, line in enumerate(f, start=1):
|
|
prompt+=f"{line_num}\t{line}"
|
|
prompt+=f"{line_num}\t{line}"
|
|
response = Application.call(
|
|
response = Application.call(
|
|
- # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
|
|
|
|
api_key=ai_key,
|
|
api_key=ai_key,
|
|
- app_id='b6edb4f5ff1c49f9855af27b14a0e8b4',
|
|
|
|
|
|
+ app_id=analysis_results_app_id,
|
|
prompt=prompt)
|
|
prompt=prompt)
|
|
if response.status_code == HTTPStatus.OK:
|
|
if response.status_code == HTTPStatus.OK:
|
|
try:
|
|
try:
|
|
@@ -153,7 +149,6 @@ async def get_code_files(path):
|
|
chunks = [files[i * 500: (i + 1) * 500]
|
|
chunks = [files[i * 500: (i + 1) * 500]
|
|
for i in range(0, len(files) // 500 + 1)]
|
|
for i in range(0, len(files) // 500 + 1)]
|
|
# 提交所有批次任务
|
|
# 提交所有批次任务
|
|
- # futures = [executor.submit(process_batch1, chunk) for chunk in chunks]
|
|
|
|
tasks = [process_batch1(chunk) for chunk in chunks]
|
|
tasks = [process_batch1(chunk) for chunk in chunks]
|
|
futures = await asyncio.gather(*tasks, return_exceptions=True)
|
|
futures = await asyncio.gather(*tasks, return_exceptions=True)
|
|
# 实时获取已完成任务的结果
|
|
# 实时获取已完成任务的结果
|
|
@@ -244,7 +239,6 @@ async def summaryCommit(request: RequestCommit, background_tasks: BackgroundTask
|
|
repo_commit_hash=repo_commit.repo_hash
|
|
repo_commit_hash=repo_commit.repo_hash
|
|
print(f"开始提交仓库: {repo_name}")
|
|
print(f"开始提交仓库: {repo_name}")
|
|
await Commit_Summary_Tasks.filter(id=request.task_id).update(start_time=int(time.time() * 1000))
|
|
await Commit_Summary_Tasks.filter(id=request.task_id).update(start_time=int(time.time() * 1000))
|
|
- # commit_content = Repo(local_path).git.log('-1', '-p', '--pretty=format:%h %s')
|
|
|
|
commit_content = Repo(local_path).git.diff(f"{repo_commit_hash}^", repo_commit_hash)
|
|
commit_content = Repo(local_path).git.diff(f"{repo_commit_hash}^", repo_commit_hash)
|
|
background_tasks.add_task(commit_task,commit_content, request.task_id)
|
|
background_tasks.add_task(commit_task,commit_content, request.task_id)
|
|
return {"code": 200, "msg": "添加提交任务成功"}
|
|
return {"code": 200, "msg": "添加提交任务成功"}
|