temp: 暂存
This commit is contained in:
parent
482c63bab2
commit
cfdf2ba00d
@ -37,6 +37,7 @@
|
||||
"@babel/preset-env": "^7.25.4",
|
||||
"@babel/preset-typescript": "^7.24.7",
|
||||
"@kevisual/ai-graph": "workspace:^",
|
||||
"@kevisual/ai-lang": "workspace:^",
|
||||
"@types/semver": "^7.5.8",
|
||||
"dayjs": "^1.11.13",
|
||||
"dts-bundle-generator": "^9.5.1",
|
||||
|
34
packages/ai-lang/package.json
Normal file
34
packages/ai-lang/package.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@kevisual/ai-lang",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main2": "dist/index.js",
|
||||
"main": "src/index.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"watch": "rollup -c -w"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@abearxiong/router": "0.0.1-alpha.36",
|
||||
"@abearxiong/use-config": "^0.0.2",
|
||||
"@langchain/core": "^0.3.3",
|
||||
"@langchain/langgraph": "^0.2.9",
|
||||
"@langchain/langgraph-checkpoint-mongodb": "^0.0.3",
|
||||
"@langchain/ollama": "^0.1.0",
|
||||
"@langchain/openai": "^0.3.2",
|
||||
"mongodb": "^6.9.0",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^28.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||
"@rollup/plugin-typescript": "^12.1.0",
|
||||
"@types/node": "^22.7.2",
|
||||
"rollup": "^4.22.4",
|
||||
"ts-lib": "^0.0.5"
|
||||
}
|
||||
}
|
24
packages/ai-lang/rollup.config.js
Normal file
24
packages/ai-lang/rollup.config.js
Normal file
@ -0,0 +1,24 @@
|
||||
// rollup.config.js
|
||||
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
/**
|
||||
* @type {import('rollup').RollupOptions}
|
||||
*/
|
||||
export default {
|
||||
input: 'src/index.ts', // TypeScript 入口文件
|
||||
output: {
|
||||
file: 'dist/index.js', // 输出文件
|
||||
format: 'es', // 输出格式设置为 ES 模块
|
||||
},
|
||||
plugins: [
|
||||
resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块
|
||||
// commonjs(),
|
||||
typescript({
|
||||
allowImportingTsExtensions: true,
|
||||
noEmit: true,
|
||||
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
||||
],
|
||||
external: ['ws']
|
||||
};
|
31
packages/ai-lang/src/agent/index.ts
Normal file
31
packages/ai-lang/src/agent/index.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
||||
import { MemorySaver } from '@langchain/langgraph';
|
||||
import { ChatOllama } from '@langchain/ollama';
|
||||
import { ChatOpenAI } from '@langchain/openai';
|
||||
import { checkpointer } from '../module/save.ts';
|
||||
import { HumanMessage } from '@langchain/core/messages';
|
||||
export { HumanMessage };
|
||||
// const agentModel = new ChatOllama({ temperature: 0, model: 'llama3.1:8b', baseUrl: 'http://mz.zxj.im:11434' });
|
||||
export const agentModelBakllava = new ChatOllama({ temperature: 0, model: 'bakllava:latest', baseUrl: 'http://mz.zxj.im:11434' });
|
||||
export const agentModel = new ChatOllama({ temperature: 0, model: 'qwen2.5:14b', baseUrl: 'http://mz.zxj.im:11434' });
|
||||
export const agentModelOpenAI = new ChatOpenAI(
|
||||
{ temperature: 0, model: 'gpt-4o', apiKey: 'sk-GJE6I8OJWDr2ErFBD4C4706a65Ad4cD9B596Cf7c76943e45' },
|
||||
{
|
||||
baseURL: 'https://oneapi.on-ai.ai/v1',
|
||||
},
|
||||
);
|
||||
|
||||
const agentCheckpointer = checkpointer;
|
||||
|
||||
export const agent = createReactAgent({
|
||||
llm: agentModel,
|
||||
tools: [],
|
||||
checkpointSaver: agentCheckpointer,
|
||||
});
|
||||
export const agentLlava = createReactAgent({
|
||||
llm: agentModelBakllava,
|
||||
tools: [],
|
||||
checkpointSaver: agentCheckpointer,
|
||||
});
|
||||
|
||||
export const agentOpenAI = createReactAgent({ llm: agentModelOpenAI, tools: [], checkpointSaver: agentCheckpointer });
|
12
packages/ai-lang/src/app.ts
Normal file
12
packages/ai-lang/src/app.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { App } from '@abearxiong/router';
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
|
||||
const config = useConfig();
|
||||
console.log('config in ai-lang', config);
|
||||
|
||||
export const app = new App({
|
||||
serverOptions: {
|
||||
path: '/api/lang',
|
||||
},
|
||||
});
|
||||
|
1
packages/ai-lang/src/index.ts
Normal file
1
packages/ai-lang/src/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './app.ts'
|
4
packages/ai-lang/src/module/mongo.ts
Normal file
4
packages/ai-lang/src/module/mongo.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
const { mongo } = useConfig<{ host: string; password: string; username: string }>();
|
||||
export const client = new MongoClient(`mongodb://${mongo.username}:${mongo.password}@${mongo.host}`, {});
|
4
packages/ai-lang/src/module/save.ts
Normal file
4
packages/ai-lang/src/module/save.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { MongoDBSaver } from '@langchain/langgraph-checkpoint-mongodb';
|
||||
import { client } from './mongo.ts';
|
||||
|
||||
export const checkpointer = new MongoDBSaver({ client });
|
10
packages/ai-lang/src/routes/agent.ts
Normal file
10
packages/ai-lang/src/routes/agent.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { app } from '../app.ts';
|
||||
import { agent, HumanMessage } from '../agent/index.ts';
|
||||
app
|
||||
.route('ai', 'chat')
|
||||
.define(async (ctx) => {
|
||||
const { message } = ctx.query;
|
||||
const response = await agent.invoke({ messages: [new HumanMessage(message)] }, { configurable: { thread_id: '44' } });
|
||||
ctx.body = response;
|
||||
})
|
||||
.addTo(app);
|
32
packages/ai-lang/tsconfig.json
Normal file
32
packages/ai-lang/tsconfig.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"target": "esnext",
|
||||
"noImplicitAny": false,
|
||||
"outDir": "./dist",
|
||||
"sourceMap": false,
|
||||
"allowJs": true,
|
||||
"newLine": "LF",
|
||||
"baseUrl": "./",
|
||||
"typeRoots": [
|
||||
"node_modules/@types",
|
||||
],
|
||||
"declaration": true,
|
||||
"noEmit": false,
|
||||
"allowImportingTsExtensions": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "NodeNext",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"esModuleInterop": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [],
|
||||
}
|
822
pnpm-lock.yaml
generated
822
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,10 @@
|
||||
import { useConfig } from '@abearxiong/use-config';
|
||||
import { app } from './app.ts';
|
||||
import './route.ts'
|
||||
import './route.ts';
|
||||
const config = useConfig();
|
||||
|
||||
import { app as aiApp } from '@kevisual/ai-lang/src/index.ts';
|
||||
//
|
||||
export { aiApp };
|
||||
export { app };
|
||||
app.listen(config.port, () => {
|
||||
console.log(`server is running at http://localhost:${config.port}`);
|
||||
|
@ -74,9 +74,25 @@ app
|
||||
const { nodes = [] } = data;
|
||||
let flag = false;
|
||||
const newNodes = nodes.map((item) => {
|
||||
if (item.id === nodeData.id) {
|
||||
const nodeItem = nodeData;
|
||||
if (item.id === nodeItem.id) {
|
||||
flag = true;
|
||||
return nodeData;
|
||||
const { data, ...rest } = nodeItem;
|
||||
const { style, ...restData } = data || {};
|
||||
const newNodeItem = {
|
||||
...item,
|
||||
...rest,
|
||||
data: {
|
||||
...item?.data,
|
||||
...restData,
|
||||
style: {
|
||||
...item?.data?.style,
|
||||
...style,
|
||||
},
|
||||
},
|
||||
};
|
||||
console.log('newNodeItem', newNodeItem);
|
||||
return newNodeItem;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
@ -81,6 +81,6 @@ module.exports = {
|
||||
errorDetails: true,
|
||||
all: false,
|
||||
errors: true,
|
||||
warnings: true,
|
||||
warnings: false,
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user