Merge pull request #8 from Yanyutin753/good

fix logger info update files
This commit is contained in:
Vinlic科技 2024-04-02 11:10:01 +08:00 committed by GitHub
commit 26e1735795
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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)
);
if(imageUrls.length == 0)
if (imageUrls.length == 0)
throw new APIException(EX.API_IMAGE_GENERATION_FAILED);
return imageUrls;
@ -452,29 +452,27 @@ async function generateImages(
* @param messages gpt系列消息格式
*/
function extractRefFileUrls(messages: any[]) {
return messages.reduce((urls, message) => {
if (_.isArray(message.content)) {
message.content.forEach((v) => {
if (!_.isObject(v) || !["file", "image_url"].includes(v["type"]))
return;
// glm-free-api支持格式
if (
v["type"] == "file" &&
_.isObject(v["file_url"]) &&
_.isString(v["file_url"]["url"])
)
urls.push(v["file_url"]["url"]);
// 兼容gpt-4-vision-preview API格式
else if (
v["type"] == "image_url" &&
_.isObject(v["image_url"]) &&
_.isString(v["image_url"]["url"])
)
urls.push(v["image_url"]["url"]);
});
}
const urls = [];
// 如果没有消息,则返回[]
if (!messages.length) {
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;
// glm-free-api支持格式
if (v['type'] == 'file' && _.isObject(v['file_url']) && _.isString(v['file_url']['url']))
urls.push(v['file_url']['url']);
// 兼容gpt-4-vision-preview API格式
else if (v['type'] == 'image_url' && _.isObject(v['image_url']) && _.isString(v['image_url']['url']))
urls.push(v['image_url']['url']);
});
}
logger.info("本次请求上传:" + urls.length + "个文件");
return urls;
}
/**
@ -489,8 +487,16 @@ function extractRefFileUrls(messages: any[]) {
* @param messages gpt系列消息格式
*/
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 =
messages.reduce((content, message) => {
validMessages.reduce((content, message) => {
if (_.isArray(message.content)) {
return (
message.content.reduce((_content, v) => {
@ -1002,8 +1008,8 @@ async function receiveImages(
throw new Error(`Stream response invalid: ${event.data}`);
if (!convId && result.conversation_id)
convId = result.conversation_id;
if(result.status == "intervene")
throw new APIException(EX.API_CONTENT_FILTERED);
if (result.status == "intervene")
throw new APIException(EX.API_CONTENT_FILTERED);
if (result.status != "finish") {
result.parts.forEach(part => {
const { content } = part;