feat: add neo4j

This commit is contained in:
2024-09-25 14:02:45 +08:00
parent 4cbc72def7
commit 25c055b490
16 changed files with 554 additions and 113 deletions

29
src/modules/neo4j.ts Normal file
View File

@@ -0,0 +1,29 @@
import Neode from 'neode';
import { useConfig } from '@abearxiong/use-config';
type NeodeConfig = {
uri: string;
username: string;
password: string;
};
const { neo4j } = useConfig<{ neo4j: NeodeConfig }>('neo4j');
const { uri, username, password } = neo4j;
// 设置连接配置
// const neode = new Neode('bolt://localhost:7687', 'neo4j', 'your_password');
export const neode = new Neode(uri, username, password);
const testConnect = async () => {
// 连接成功
// 尝试执行简单的 Cypher 查询以测试连接
neode
.cypher('RETURN 1', {})
.then(() => {
console.log('connect neo4j success');
})
.catch((err) => {
console.error('Failed to connect:', err);
});
};
testConnect();

30
src/modules/ollama.ts Normal file
View File

@@ -0,0 +1,30 @@
import { useConfig } from '@abearxiong/use-config';
import { Ollama, Message, ChatRequest } from 'ollama';
const config = useConfig<{ ollama: Ollama['config'] & { model: string } }>();
const { host } = config.ollama;
export const ollama = new Ollama({ host });
export type ChatMessage = {
content: string;
} & Message;
type ChatOpts = {
model?: string;
messages?: ChatMessage[];
options?: ChatRequest['options'];
} & ChatRequest;
export const chat = (messages: ChatMessage[], chatOpts?: ChatOpts) => {
const { options, stream, ...rest } = chatOpts || {};
return ollama.chat({
messages,
model: config.model,
options: {
temperature: 0,
...chatOpts?.options,
},
...rest,
});
};

View File

@@ -5,7 +5,7 @@ const config = useConfig<{
redis: ConstructorParameters<typeof Redis>;
}>();
// 配置 Redis 连接
const redis = new Redis({
export const redis = new Redis({
host: 'localhost', // Redis 服务器的主机名或 IP 地址
port: 6379, // Redis 服务器的端口号
// password: 'your_password', // Redis 的密码 (如果有)