Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: support vertex ai #4487

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

✨ feat: support vertex ai #4487

wants to merge 1 commit into from

Conversation

arvinxx
Copy link
Contributor

@arvinxx arvinxx commented Oct 25, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-database ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 4:01pm
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 4:01pm

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.53%. Comparing base (ad3a154) to head (05754da).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4487      +/-   ##
==========================================
+ Coverage   92.48%   92.53%   +0.05%     
==========================================
  Files         511      512       +1     
  Lines       36614    36867     +253     
  Branches     3388     3387       -1     
==========================================
+ Hits        33862    34115     +253     
  Misses       2752     2752              
Flag Coverage Δ
app 92.53% <100.00%> (+0.05%) ⬆️
server 97.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lobehubbot
Copy link
Member

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Comment on lines 272 to 274
const sensenovaAccessKeySecret = apiKeyManager.pick(
payload?.sensenovaAccessKeySecret || SENSENOVA_ACCESS_KEY_SECRET,
);

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI 7 days ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, the crypto module provides a method crypto.randomInt that can be used to generate cryptographically secure random integers. This method will be used to securely select an index for the API keys.

  • General Fix: Replace Math.random() with crypto.randomInt to ensure the randomness is cryptographically secure.
  • Detailed Fix: Modify the pick method in src/server/modules/AgentRuntime/apiKeyManager.ts to use crypto.randomInt instead of Math.random().
  • Specific Changes:
    • Import the crypto module.
    • Replace the line using Math.random() with a call to crypto.randomInt.
Suggested changeset 1
src/server/modules/AgentRuntime/apiKeyManager.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/server/modules/AgentRuntime/apiKeyManager.ts b/src/server/modules/AgentRuntime/apiKeyManager.ts
--- a/src/server/modules/AgentRuntime/apiKeyManager.ts
+++ b/src/server/modules/AgentRuntime/apiKeyManager.ts
@@ -1,2 +1,3 @@
 import { getLLMConfig } from '@/config/llm';
+import { randomInt } from 'crypto';
 
@@ -39,3 +40,3 @@
     if (this._mode === 'turn') index = store.index++ % store.keyLen;
-    if (this._mode === 'random') index = Math.floor(Math.random() * store.keyLen);
+    if (this._mode === 'random') index = randomInt(store.keyLen);
 
EOF
@@ -1,2 +1,3 @@
import { getLLMConfig } from '@/config/llm';
import { randomInt } from 'crypto';

@@ -39,3 +40,3 @@
if (this._mode === 'turn') index = store.index++ % store.keyLen;
if (this._mode === 'random') index = Math.floor(Math.random() * store.keyLen);
if (this._mode === 'random') index = randomInt(store.keyLen);

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -100,6 +102,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
Ai360Provider,
TaichuProvider,
SiliconCloudProvider,
VertexAIProvider,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方也应该放到google下面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants