mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
feat: 添加 UV 管理器支持以优化 SPLADE 安装流程
This commit is contained in:
20
1.18.0
20
1.18.0
@@ -1,17 +1,17 @@
|
||||
Collecting onnxruntime-directml
|
||||
Using cached onnxruntime_directml-1.23.0-cp310-cp310-win_amd64.whl (25.1 MB)
|
||||
Collecting protobuf
|
||||
Using cached protobuf-6.33.3-cp310-abi3-win_amd64.whl (436 kB)
|
||||
Collecting packaging
|
||||
Using cached packaging-25.0-py3-none-any.whl (66 kB)
|
||||
Collecting coloredlogs
|
||||
Using cached coloredlogs-15.0.1-py2.py3-none-any.whl (46 kB)
|
||||
Collecting flatbuffers
|
||||
Using cached flatbuffers-25.12.19-py2.py3-none-any.whl (26 kB)
|
||||
Collecting numpy>=1.21.6
|
||||
Using cached numpy-2.2.6-cp310-cp310-win_amd64.whl (12.9 MB)
|
||||
Collecting sympy
|
||||
Using cached sympy-1.14.0-py3-none-any.whl (6.3 MB)
|
||||
Collecting packaging
|
||||
Using cached packaging-25.0-py3-none-any.whl (66 kB)
|
||||
Collecting protobuf
|
||||
Using cached protobuf-6.33.2-cp310-abi3-win_amd64.whl (436 kB)
|
||||
Collecting flatbuffers
|
||||
Using cached flatbuffers-25.12.19-py2.py3-none-any.whl (26 kB)
|
||||
Collecting humanfriendly>=9.1
|
||||
Using cached humanfriendly-10.0-py2.py3-none-any.whl (86 kB)
|
||||
Collecting mpmath<1.4,>=1.1.0
|
||||
@@ -36,9 +36,9 @@ Installing collected packages: mpmath, flatbuffers, sympy, pyreadline3, protobuf
|
||||
Uninstalling pyreadline3-3.5.4:
|
||||
Successfully uninstalled pyreadline3-3.5.4
|
||||
Attempting uninstall: protobuf
|
||||
Found existing installation: protobuf 6.33.2
|
||||
Uninstalling protobuf-6.33.2:
|
||||
Successfully uninstalled protobuf-6.33.2
|
||||
Found existing installation: protobuf 6.33.3
|
||||
Uninstalling protobuf-6.33.3:
|
||||
Successfully uninstalled protobuf-6.33.3
|
||||
Attempting uninstall: packaging
|
||||
Found existing installation: packaging 25.0
|
||||
Uninstalling packaging-25.0:
|
||||
@@ -59,4 +59,4 @@ Installing collected packages: mpmath, flatbuffers, sympy, pyreadline3, protobuf
|
||||
Found existing installation: onnxruntime-directml 1.23.0
|
||||
Uninstalling onnxruntime-directml-1.23.0:
|
||||
Successfully uninstalled onnxruntime-directml-1.23.0
|
||||
Successfully installed coloredlogs-15.0.1 flatbuffers-25.12.19 humanfriendly-10.0 mpmath-1.3.0 numpy-2.2.6 onnxruntime-directml-1.23.0 packaging-25.0 protobuf-6.33.2 pyreadline3-3.5.4 sympy-1.14.0
|
||||
Successfully installed coloredlogs-15.0.1 flatbuffers-25.12.19 humanfriendly-10.0 mpmath-1.3.0 numpy-2.2.6 onnxruntime-directml-1.23.0 packaging-25.0 protobuf-6.33.3 pyreadline3-3.5.4 sympy-1.14.0
|
||||
|
||||
@@ -10,6 +10,10 @@ import {
|
||||
} from '../../../tools/codex-lens.js';
|
||||
import type { GpuMode } from '../../../tools/codex-lens.js';
|
||||
import { loadLiteLLMApiConfig } from '../../../config/litellm-api-config-manager.js';
|
||||
import {
|
||||
isUvAvailable,
|
||||
createCodexLensUvManager,
|
||||
} from '../../../utils/uv-manager.js';
|
||||
import type { RouteContext } from '../types.js';
|
||||
import { extractJSON } from './utils.js';
|
||||
|
||||
@@ -631,9 +635,73 @@ export async function handleCodexLensSemanticRoutes(ctx: RouteContext): Promise<
|
||||
try {
|
||||
const { gpu } = body as { gpu?: unknown };
|
||||
const useGpu = typeof gpu === 'boolean' ? gpu : false;
|
||||
const packageName = useGpu ? 'codex-lens[splade-gpu]' : 'codex-lens[splade]';
|
||||
const extras = useGpu ? ['splade-gpu'] : ['splade'];
|
||||
|
||||
// Use pip to install the SPLADE extras
|
||||
// Priority: Use UV if available (faster, better dependency resolution)
|
||||
if (await isUvAvailable()) {
|
||||
console.log('[SPLADE Install] Using UV for installation...');
|
||||
const uv = createCodexLensUvManager();
|
||||
|
||||
// Ensure venv exists
|
||||
if (!uv.isVenvValid()) {
|
||||
console.log('[SPLADE Install] Venv not valid, creating...');
|
||||
const venvResult = await uv.createVenv();
|
||||
if (!venvResult.success) {
|
||||
throw new Error(`Failed to create venv: ${venvResult.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Find local codex-lens package
|
||||
const { existsSync } = await import('fs');
|
||||
const { join, dirname } = await import('path');
|
||||
const { fileURLToPath } = await import('url');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Look for local codex-lens package
|
||||
const possiblePaths = [
|
||||
join(__dirname, '..', '..', '..', '..', '..', 'codex-lens'),
|
||||
join(__dirname, '..', '..', '..', '..', '..', '..', 'codex-lens'),
|
||||
join(process.cwd(), 'codex-lens'),
|
||||
];
|
||||
|
||||
let codexLensPath: string | null = null;
|
||||
for (const p of possiblePaths) {
|
||||
if (existsSync(join(p, 'pyproject.toml'))) {
|
||||
codexLensPath = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (codexLensPath) {
|
||||
// Install from local project with extras
|
||||
const result = await uv.installFromProject(codexLensPath, extras);
|
||||
if (result.success) {
|
||||
return {
|
||||
success: true,
|
||||
message: `SPLADE installed successfully via UV (${useGpu ? 'GPU' : 'CPU'} mode)`,
|
||||
duration: result.duration
|
||||
};
|
||||
}
|
||||
console.log('[SPLADE Install] UV install failed, falling back to pip:', result.error);
|
||||
} else {
|
||||
// Install from PyPI with extras
|
||||
const packageSpec = `codex-lens[${extras.join(',')}]`;
|
||||
const result = await uv.install([packageSpec]);
|
||||
if (result.success) {
|
||||
return {
|
||||
success: true,
|
||||
message: `SPLADE installed successfully via UV from PyPI (${useGpu ? 'GPU' : 'CPU'} mode)`,
|
||||
duration: result.duration
|
||||
};
|
||||
}
|
||||
console.log('[SPLADE Install] UV install failed, falling back to pip:', result.error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Use pip for installation
|
||||
console.log('[SPLADE Install] Using pip fallback...');
|
||||
const packageName = useGpu ? 'codex-lens[splade-gpu]' : 'codex-lens[splade]';
|
||||
const { promisify } = await import('util');
|
||||
const execFilePromise = promisify(require('child_process').execFile);
|
||||
|
||||
@@ -643,7 +711,7 @@ export async function handleCodexLensSemanticRoutes(ctx: RouteContext): Promise<
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `SPLADE installed successfully (${useGpu ? 'GPU' : 'CPU'} mode)`,
|
||||
message: `SPLADE installed successfully via pip (${useGpu ? 'GPU' : 'CPU'} mode)`,
|
||||
output: result.stdout
|
||||
};
|
||||
} catch (err: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user