Skip to content

Commit

Permalink
Merge pull request #189 from aitok-ai/main
Browse files Browse the repository at this point in the history
Sync from main to release/zhao.toatu.com for  release 2024-04-01a

All tests passed
  • Loading branch information
jinzishuai authored Apr 1, 2024
2 parents 1b17969 + aa083e3 commit 0ff78cd
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 27 deletions.
52 changes: 40 additions & 12 deletions api/app/clients/tools/AzureAiSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,67 @@ class AzureAISearch extends Tool {
const getValue = (fieldNames, defaultValue) => {
for (const name of fieldNames) {
const value = fields[name] || process.env[name];
if (value !== undefined && value !== null) return value;
if (value !== undefined && value !== null) {
return value;
}
}
return defaultValue;
};

this.serviceEndpoint = getValue(['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'], this.getServiceEndpoint());
this.indexName = getValue(['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'], this.getIndexName());
this.apiKey = getValue(['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'], this.getApiKey());
this.apiVersion = getValue(['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'], AzureAISearch.DEFAULT_API_VERSION);
this.queryType = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE'], AzureAISearch.DEFAULT_QUERY_TYPE);
this.top = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'], AzureAISearch.DEFAULT_TOP);
this.serviceEndpoint = getValue(
['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'],
this.getServiceEndpoint(),
);
this.indexName = getValue(
['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'],
this.getIndexName(),
);
this.apiKey = getValue(
['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'],
this.getApiKey(),
);
this.apiVersion = getValue(
['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'],
AzureAISearch.DEFAULT_API_VERSION,
);
this.queryType = getValue(
[
'AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE',
'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE',
],
AzureAISearch.DEFAULT_QUERY_TYPE,
);
this.top = getValue(
['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'],
AzureAISearch.DEFAULT_TOP,
);
this.select = this.getSelect();
}

initializeClient() {
this.client = new SearchClient(this.serviceEndpoint, this.indexName, new AzureKeyCredential(this.apiKey), { apiVersion: this.apiVersion });
// eslint-disable-next-line max-len
this.client = new SearchClient(
this.serviceEndpoint,
this.indexName,
new AzureKeyCredential(this.apiKey),
{ apiVersion: this.apiVersion },
);
}

name = 'azure-ai-search';

description =
'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';
description = 'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';

async _call(query) {
try {
const searchOptions = {
queryType: this.queryType,
top: this.top,
select: this.select
select: this.select,
};

const searchResults = await this.client.search(query, searchOptions);
return JSON.stringify(searchResults.results.map(result => result.document));
return JSON.stringify(searchResults.results.map((result) => result.document));
} catch (error) {
console.error(`Azure AI Search request failed: ${error}`);
return 'There was an error with Azure AI Search.';
Expand Down
52 changes: 40 additions & 12 deletions api/app/clients/tools/structured/AzureAISearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,51 @@ class AzureAISearch extends StructuredTool {
const getValue = (fieldNames, defaultValue) => {
for (const name of fieldNames) {
const value = fields[name] || process.env[name];
if (value !== undefined && value !== null) return value;
if (value !== undefined && value !== null) {
return value;
}
}
return defaultValue;
};

this.serviceEndpoint = getValue(['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'], this.getServiceEndpoint());
this.indexName = getValue(['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'], this.getIndexName());
this.apiKey = getValue(['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'], this.getApiKey());
this.apiVersion = getValue(['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'], AzureAISearch.DEFAULT_API_VERSION);
this.queryType = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE'], AzureAISearch.DEFAULT_QUERY_TYPE);
this.top = getValue(['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'], AzureAISearch.DEFAULT_TOP);
this.serviceEndpoint = getValue(
['AZURE_AI_SEARCH_SERVICE_ENDPOINT', 'AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT'],
this.getServiceEndpoint(),
);
this.indexName = getValue(
['AZURE_AI_SEARCH_INDEX_NAME', 'AZURE_COGNITIVE_SEARCH_INDEX_NAME'],
this.getIndexName(),
);
this.apiKey = getValue(
['AZURE_AI_SEARCH_API_KEY', 'AZURE_COGNITIVE_SEARCH_API_KEY'],
this.getApiKey(),
);
this.apiVersion = getValue(
['AZURE_AI_SEARCH_API_VERSION', 'AZURE_COGNITIVE_SEARCH_API_VERSION'],
AzureAISearch.DEFAULT_API_VERSION,
);
this.queryType = getValue(
[
'AZURE_AI_SEARCH_SEARCH_OPTION_QUERY_TYPE',
'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_QUERY_TYPE',
],
AzureAISearch.DEFAULT_QUERY_TYPE,
);
this.top = getValue(
['AZURE_AI_SEARCH_SEARCH_OPTION_TOP', 'AZURE_COGNITIVE_SEARCH_SEARCH_OPTION_TOP'],
AzureAISearch.DEFAULT_TOP,
);
this.select = this.getSelect();
}

initializeClient() {
this.client = new SearchClient(this.serviceEndpoint, this.indexName, new AzureKeyCredential(this.apiKey), { apiVersion: this.apiVersion });
// eslint-disable-next-line max-len
this.client = new SearchClient(
this.serviceEndpoint,
this.indexName,
new AzureKeyCredential(this.apiKey),
{ apiVersion: this.apiVersion },
);
}

initializeSchema() {
Expand All @@ -44,20 +73,19 @@ class AzureAISearch extends StructuredTool {

name = 'azure-ai-search';

description =
'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';
description = 'Use the \'azure-ai-search\' tool to retrieve search results relevant to your input';

async _call(data) {
const { query } = data;
try {
const searchOptions = {
queryType: this.queryType,
top: this.top,
select: this.select
select: this.select,
};

const searchResults = await this.client.search(query, searchOptions);
return JSON.stringify(searchResults.results.map(result => result.document));
return JSON.stringify(searchResults.results.map((result) => result.document));
} catch (error) {
console.error(`Azure AI Search request failed: ${error}`);
return 'There was an error with Azure AI Search.';
Expand Down
3 changes: 2 additions & 1 deletion api/server/routes/ask/openAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ router.post('/', validateEndpoint, buildEndpointOption, setHeaders, async (req,
});
let dailyQuota = quota[endpointOption.modelOptions.model].toFixed(0);
if (messagesCount >= dailyQuota) {
// TODO: this error message should be implemented by the client based on locale
throw new Error(
`超出了您的使用额度(${endpointOption.modelOptions.model}模型每天${dailyQuota}条消息)。由于需要支付越来越多、每月上万元的API费用,如果您经常使用我们的服务,请通过此网页购买更多额度、支持我们持续提供GPT服务:https://iaitok.com 目前限时半价优惠每月60元`,
`超出了您的使用额度(${endpointOption.modelOptions.model}模型每天${dailyQuota}条消息)。由于需要支付越来越多、每月上万元的API费用,如果您经常使用我们的服务,请打开“我的主页”进行购买,支持我们持续提供GPT服务`,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions api/server/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ router.get('/', async function (req, res) {
serverDomain: process.env.DOMAIN_SERVER || 'http://localhost:3080',
registrationEnabled: isEnabled(process.env.ALLOW_REGISTRATION),
socialLoginEnabled: isEnabled(process.env.ALLOW_SOCIAL_LOGIN),
proMemberPaymentURL: process.env.PRO_MEMBER_PAYMENT_URL,
emailEnabled:
(!!process.env.EMAIL_SERVICE || !!process.env.EMAIL_HOST) &&
!!process.env.EMAIL_USERNAME &&
Expand Down
36 changes: 34 additions & 2 deletions client/src/components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Tabs, TabsList, TabsTrigger } from '../ui/Tabs';
import { cn } from '~/utils';
import useDocumentTitle from '~/hooks/useDocumentTitle';
import { useNavigate, useParams } from 'react-router-dom';
import { TUser, useFollowUserMutation, useGetUserByIdQuery } from 'librechat-data-provider';
import {
TUser,
useFollowUserMutation,
useGetStartupConfig,
useGetUserByIdQuery,
} from 'librechat-data-provider';
import { useAuthContext } from '~/hooks/AuthContext';
import LikedConversations from './LikedConversation';
import { useRecoilValue } from 'recoil';
Expand Down Expand Up @@ -34,11 +39,14 @@ function ProfileContent() {
const { userId = '' } = useParams();
const { user, token } = useAuthContext();
const localize = useLocalize();
let lang = localStorage.getItem('lang');
lang = lang ? lang.substring(0, 2) : 'en';
const navigate = useNavigate();
useDocumentTitle('Profile');

const getUserByIdQuery = useGetUserByIdQuery(userId);
const followUserMutation = useFollowUserMutation();
const { data: startupConfig } = useGetStartupConfig();

const defaultClasses = 'p-2 rounded-md min-w-[75px] font-normal text-xs';
const defaultSelected = cn(
Expand Down Expand Up @@ -460,11 +468,35 @@ function ProfileContent() {
<div className="pl-7">
{localize('com_ui_pro_member_expired_at')}: {proMemberExpiredAt.getFullYear()}-
{proMemberExpiredAt.getMonth() + 1}-{proMemberExpiredAt.getDate()}
<button
type="submit"
className="rounded bg-green-500 px-4 py-1 text-white hover:bg-green-600"
onClick={() =>
window.open(
`${startupConfig?.proMemberPaymentURL}?locale=${lang}&prefilled_email=${profileUser?.email}`,
)
}
>
{localize('com_ui_renewal_pro_member')}
</button>
</div>
</div>
) : (
<div className="w-full rounded-lg p-6 dark:text-gray-200">
<div className="pl-7">{localize('com_ui_free_member')}</div>
<div className="pl-7">
{localize('com_ui_free_member')}
<button
type="submit"
className="rounded bg-green-500 px-4 py-1 text-white hover:bg-green-600"
onClick={() =>
window.open(
`${startupConfig?.proMemberPaymentURL}?locale=${lang}&prefilled_email=${profileUser?.email}`,
)
}
>
{localize('com_ui_become_pro_member')}
</button>
</div>
</div>
)
) : (
Expand Down
2 changes: 2 additions & 0 deletions client/src/localization/languages/Eng.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default {
com_ui_followers: 'Followers',
com_ui_following: 'Following',
com_ui_pro_member_expired_at: 'Pro Member. Expired On',
com_ui_become_pro_member: 'become pro member',
com_ui_renewal_pro_member: 'renewal pro member',
com_ui_free_member: 'Free Member',
com_ui_about_yourself: 'About Yourself',
com_ui_profession: 'Profession',
Expand Down
2 changes: 2 additions & 0 deletions client/src/localization/languages/Zh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default {
com_ui_followers: '粉丝',
com_ui_following: '关注',
com_ui_pro_member_expired_at: 'Pro用户. 过期日期',
com_ui_become_pro_member: '成为专业会员',
com_ui_renewal_pro_member: '续期专业会员',
com_ui_free_member: '免费用户',
com_ui_about_yourself: '关于自己',
com_ui_profession: '职业',
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export type TStartupConfig = {
emailEnabled: boolean;
checkBalance: boolean;
customFooter?: string;
proMemberPaymentURL: string;
};

export type TRefreshTokenResponse = {
Expand Down

0 comments on commit 0ff78cd

Please sign in to comment.