Skip to content

Commit 2c38c55

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 6a17e74 + 8989916 commit 2c38c55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+52120
-250
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ module.exports = {
132132
},
133133
],
134134
},
135+
{
136+
files: './config/translations/**/*.ts',
137+
parser: '@typescript-eslint/parser',
138+
parserOptions: {
139+
project: './config/translations/tsconfig.json',
140+
},
141+
},
135142
{
136143
files: ['./packages/data-provider/specs/**/*.ts'],
137144
parserOptions: {

.github/workflows/frontend-review.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
#github action to run unit tests for frontend with jest
21
name: Frontend Unit Tests
2+
33
on:
4-
# push:
5-
# branches:
6-
# - main
7-
# - dev
8-
# - release/*
94
pull_request:
105
branches:
116
- main
@@ -14,9 +9,10 @@ on:
149
paths:
1510
- 'client/**'
1611
- 'packages/**'
12+
1713
jobs:
18-
tests_frontend:
19-
name: Run frontend unit tests
14+
tests_frontend_ubuntu:
15+
name: Run frontend unit tests on Ubuntu
2016
timeout-minutes: 60
2117
runs-on: ubuntu-latest
2218
steps:
@@ -35,4 +31,26 @@ jobs:
3531

3632
- name: Run unit tests
3733
run: npm run test:ci --verbose
38-
working-directory: client
34+
working-directory: client
35+
36+
tests_frontend_windows:
37+
name: Run frontend unit tests on Windows
38+
timeout-minutes: 60
39+
runs-on: windows-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Use Node.js 20.x
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: 20
46+
cache: 'npm'
47+
48+
- name: Install dependencies
49+
run: npm ci
50+
51+
- name: Build Client
52+
run: npm run frontend:ci
53+
54+
- name: Run unit tests
55+
run: npm run test:ci --verbose
56+
working-directory: client

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ coverage
2121
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2222
.grunt
2323

24+
# translation services
25+
config/translations/stores/*
26+
client/src/localization/languages/*_missing_keys.json
27+
2428
# Compiled Dirs (http://nodejs.org/api/addons.html)
2529
build/
2630
dist/

Dockerfile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
# 基础镜像
1+
# v0.7.1
2+
3+
# Base node image
24
FROM node:lts AS base
35

6+
RUN apk add g++ make py3-pip
7+
RUN npm install -g node-gyp
8+
RUN apk --no-cache add curl
9+
10+
RUN mkdir -p /app && chown node:node /app
11+
WORKDIR /app
12+
13+
USER node
14+
15+
COPY --chown=node:node . .
16+
417
# 数据提供者构建
518
FROM base AS data-provider-build
619
WORKDIR /app/packages/data-provider
@@ -15,7 +28,16 @@ WORKDIR /app/client
1528
COPY ./client/ ./
1629
# 从数据提供者构建阶段复制到客户端的 node_modules
1730
COPY --from=data-provider-build /app/packages/data-provider /app/client/node_modules/librechat-data-provider
18-
RUN npm install
31+
32+
# Allow mounting of these files, which have no default
33+
# values.
34+
RUN touch .env
35+
RUN npm config set fetch-retry-maxtimeout 600000
36+
RUN npm config set fetch-retries 5
37+
RUN npm config set fetch-retry-mintimeout 15000
38+
RUN npm install --no-audit
39+
40+
# React client build
1941
ENV NODE_OPTIONS="--max-old-space-size=2048"
2042
RUN npm run build
2143

Dockerfile.multi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# v0.7.1
1+
# v0.7.2
22

33
# Build API, Client and Data Provider
44
FROM node:20-alpine AS base

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ Please consult the breaking changes before updating.
103103

104104
<p align="center">
105105
<a href="https://trendshift.io/repositories/4685" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4685" alt="danny-avila%2FLibreChat | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
106-
</p>
107-
106+
<a
107+
href="https://runacap.com/ross-index/q1-24/"
108+
target="_blank"
109+
rel="noopener"
110+
>
111+
<img
112+
style="width: 260px; height: 56px"
113+
src="https://runacap.com/wp-content/uploads/2024/04/ROSS_badge_white_Q1_2024.svg"
114+
alt="ROSS Index - Fastest Growing Open-Source Startups in Q1 2024 | Runa Capital"
115+
width="260"
116+
height="56"
117+
/>
118+
</a>
108119
<a href="https://star-history.com/#danny-avila/LibreChat&Date">
109120
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=danny-avila/LibreChat&type=Date&theme=dark" onerror="this.src='https://api.star-history.com/svg?repos=danny-avila/LibreChat&type=Date'" />
110121
</a>
122+
</p>
111123

112124
---
113125

api/app/clients/AnthropicClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const {
77
} = require('librechat-data-provider');
88
const { encodeAndFormat } = require('~/server/services/Files/images/encode');
99
const {
10-
titleFunctionPrompt,
11-
parseTitleFromPrompt,
1210
truncateText,
1311
formatMessage,
12+
titleFunctionPrompt,
13+
parseParamFromPrompt,
1414
createContextHandlers,
1515
} = require('./prompts');
1616
const spendTokens = require('~/models/spendTokens');
@@ -748,7 +748,7 @@ class AnthropicClient extends BaseClient {
748748
context: 'title',
749749
});
750750
const text = response.content[0].text;
751-
title = parseTitleFromPrompt(text);
751+
title = parseParamFromPrompt(text, 'title');
752752
} catch (e) {
753753
logger.error('[AnthropicClient] There was an issue generating the title', e);
754754
}

api/app/clients/prompts/titlePrompts.js

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,64 @@ Submit a brief title in the conversation's language, following the parameter des
5959
</tool_description>
6060
</tools>`;
6161

62-
/**
63-
* Parses titles from title functions based on the provided prompt.
64-
* @param {string} prompt - The prompt containing the title function.
65-
* @returns {string} The parsed title. "New Chat" if no title is found.
66-
*/
67-
function parseTitleFromPrompt(prompt) {
68-
const titleRegex = /<title>(.+?)<\/title>/;
69-
const titleMatch = prompt.match(titleRegex);
62+
const genTranslationPrompt = (
63+
translationPrompt,
64+
) => `In this environment you have access to a set of tools you can use to translate text.
65+
66+
You may call them like this:
67+
<function_calls>
68+
<invoke>
69+
<tool_name>$TOOL_NAME</tool_name>
70+
<parameters>
71+
<$PARAMETER_NAME>$PARAMETER_VALUE</$PARAMETER_NAME>
72+
...
73+
</parameters>
74+
</invoke>
75+
</function_calls>
7076
71-
if (titleMatch && titleMatch[1]) {
72-
const title = titleMatch[1].trim();
77+
Here are the tools available:
78+
<tools>
79+
<tool_description>
80+
<tool_name>submit_translation</tool_name>
81+
<description>
82+
Submit a translation in the target language, following the parameter description and its language closely.
83+
</description>
84+
<parameters>
85+
<parameter>
86+
<name>translation</name>
87+
<type>string</type>
88+
<description>${translationPrompt}
89+
ONLY include the generated translation without quotations, nor its related key</description>
90+
</parameter>
91+
</parameters>
92+
</tool_description>
93+
</tools>`;
7394

74-
// // Capitalize the first letter of each word; Note: unnecessary due to title case prompting
75-
// const capitalizedTitle = title.replace(/\b\w/g, (char) => char.toUpperCase());
95+
/**
96+
* Parses specified parameter from the provided prompt.
97+
* @param {string} prompt - The prompt containing the desired parameter.
98+
* @param {string} paramName - The name of the parameter to extract.
99+
* @returns {string} The parsed parameter's value or a default value if not found.
100+
*/
101+
function parseParamFromPrompt(prompt, paramName) {
102+
const paramRegex = new RegExp(`<${paramName}>([\\s\\S]+?)</${paramName}>`);
103+
const paramMatch = prompt.match(paramRegex);
76104

77-
return title;
105+
if (paramMatch && paramMatch[1]) {
106+
return paramMatch[1].trim();
78107
}
79108

80-
return 'New Chat';
109+
if (prompt && prompt.length) {
110+
return `NO TOOL INVOCATION: ${prompt}`;
111+
}
112+
return `No ${paramName} provided`;
81113
}
82114

83115
module.exports = {
84116
langPrompt,
85117
titleInstruction,
86118
createTitlePrompt,
87119
titleFunctionPrompt,
88-
parseTitleFromPrompt,
120+
parseParamFromPrompt,
121+
genTranslationPrompt,
89122
};

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@librechat/backend",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "",
55
"scripts": {
66
"start": "echo 'please run this from the root directory'",

api/server/middleware/buildEndpointOption.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ async function buildEndpointOption(req, res, next) {
4242
return handleError(res, { text: 'Model spec mismatch' });
4343
}
4444

45+
if (
46+
currentModelSpec.preset.endpoint !== EModelEndpoint.gptPlugins &&
47+
currentModelSpec.preset.tools
48+
) {
49+
return handleError(res, {
50+
text: `Only the "${EModelEndpoint.gptPlugins}" endpoint can have tools defined in the preset`,
51+
});
52+
}
53+
4554
const isValidModelSpec = enforceModelSpec(currentModelSpec, parsedBody);
4655
if (!isValidModelSpec) {
4756
return handleError(res, { text: 'Model spec mismatch' });

0 commit comments

Comments
 (0)