fix logger info update files

This commit is contained in:
Yanyutin753 2024-04-02 11:04:23 +08:00
parent 30bfa2aa88
commit 1af80ca83a
2 changed files with 80 additions and 26 deletions

48
.github/workflows/sync.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: Upstream Sync
permissions:
contents: write
issues: write
actions: write
on:
schedule:
- cron: '0 * * * *' # every hour
workflow_dispatch:
jobs:
sync_latest_from_upstream:
name: Sync latest commits from upstream repo
runs-on: ubuntu-latest
if: ${{ github.event.repository.fork }}
steps:
- uses: actions/checkout@v4
- name: Clean issue notice
uses: actions-cool/issues-helper@v3
with:
actions: 'close-issues'
labels: '🚨 Sync Fail'
- name: Sync upstream changes
id: sync
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4
with:
upstream_sync_repo: LLM-Red-Team/glm-free-api
upstream_sync_branch: master
target_sync_branch: master
target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set
test_mode: false
- name: Sync check
if: failure()
uses: actions-cool/issues-helper@v3
with:
actions: 'create-issue'
title: '🚨 同步失败 | Sync Fail'
labels: '🚨 Sync Fail'
body: |
Due to a change in the workflow file of the LLM-Red-Team/glm-free-api upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the detailed [Tutorial][tutorial-en-US] for instructions.
由于 LLM-Red-Team/glm-free-api 上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次,

View File

@ -429,7 +429,7 @@ async function generateImages(
console.error(err) console.error(err)
); );
if(imageUrls.length == 0) if (imageUrls.length == 0)
throw new APIException(EX.API_IMAGE_GENERATION_FAILED); throw new APIException(EX.API_IMAGE_GENERATION_FAILED);
return imageUrls; return imageUrls;
@ -452,29 +452,27 @@ async function generateImages(
* @param messages gpt系列消息格式 * @param messages gpt系列消息格式
*/ */
function extractRefFileUrls(messages: any[]) { function extractRefFileUrls(messages: any[]) {
return messages.reduce((urls, message) => { const urls = [];
if (_.isArray(message.content)) { // 如果没有消息,则返回[]
message.content.forEach((v) => { if (!messages.length) {
if (!_.isObject(v) || !["file", "image_url"].includes(v["type"])) return urls;
}
// 只获取最新的消息
const lastMessage = messages[messages.length - 1];
if (_.isArray(lastMessage.content)) {
lastMessage.content.forEach(v => {
if (!_.isObject(v) || !['file', 'image_url'].includes(v['type']))
return; return;
// glm-free-api支持格式 // glm-free-api支持格式
if ( if (v['type'] == 'file' && _.isObject(v['file_url']) && _.isString(v['file_url']['url']))
v["type"] == "file" && urls.push(v['file_url']['url']);
_.isObject(v["file_url"]) &&
_.isString(v["file_url"]["url"])
)
urls.push(v["file_url"]["url"]);
// 兼容gpt-4-vision-preview API格式 // 兼容gpt-4-vision-preview API格式
else if ( else if (v['type'] == 'image_url' && _.isObject(v['image_url']) && _.isString(v['image_url']['url']))
v["type"] == "image_url" && urls.push(v['image_url']['url']);
_.isObject(v["image_url"]) &&
_.isString(v["image_url"]["url"])
)
urls.push(v["image_url"]["url"]);
}); });
} }
logger.info("本次请求上传:" + urls.length + "个文件");
return urls; return urls;
}, []);
} }
/** /**
@ -489,8 +487,16 @@ function extractRefFileUrls(messages: any[]) {
* @param messages gpt系列消息格式 * @param messages gpt系列消息格式
*/ */
function messagesPrepare(messages: any[], refs: any[]) { function messagesPrepare(messages: any[], refs: any[]) {
// 只保留最新消息以及不包含"type": "image_url"或"type": "file"的消息
let validMessages = messages.filter((message, index) => {
if (index === messages.length - 1) return true;
if (!Array.isArray(message.content)) return true;
// 不含"type": "image_url"或"type": "file"的消息保留
return !message.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type'])));
});
const content = const content =
messages.reduce((content, message) => { validMessages.reduce((content, message) => {
if (_.isArray(message.content)) { if (_.isArray(message.content)) {
return ( return (
message.content.reduce((_content, v) => { message.content.reduce((_content, v) => {
@ -1002,7 +1008,7 @@ async function receiveImages(
throw new Error(`Stream response invalid: ${event.data}`); throw new Error(`Stream response invalid: ${event.data}`);
if (!convId && result.conversation_id) if (!convId && result.conversation_id)
convId = result.conversation_id; convId = result.conversation_id;
if(result.status == "intervene") if (result.status == "intervene")
throw new APIException(EX.API_CONTENT_FILTERED); throw new APIException(EX.API_CONTENT_FILTERED);
if (result.status != "finish") { if (result.status != "finish") {
result.parts.forEach(part => { result.parts.forEach(part => {