Fehlerbehebung & Start Vector Search
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dotenv/config';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { existsSync, readFileSync, readdirSync, statSync, unlinkSync } from 'fs';
|
||||
import fs from 'fs-extra';
|
||||
import OpenAI from 'openai';
|
||||
import { join } from 'path';
|
||||
import pkg from 'pg';
|
||||
import { rimraf } from 'rimraf';
|
||||
@@ -11,6 +12,10 @@ import { emailToDirName } from 'src/models/main.model.js';
|
||||
import * as schema from './schema.js';
|
||||
const { Pool } = pkg;
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: process.env.OPENAI_API_KEY, // Stellen Sie sicher, dass Sie Ihren API-Key als Umgebungsvariable setzen
|
||||
});
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
// const pool = new Pool({connectionString})
|
||||
const client = new Pool({ connectionString });
|
||||
@@ -124,6 +129,14 @@ for (const commercial of commercialJsonData) {
|
||||
//End
|
||||
await client.end();
|
||||
|
||||
async function createEmbedding(text: string): Promise<number[]> {
|
||||
const response = await openai.embeddings.create({
|
||||
model: 'text-embedding-ada-002',
|
||||
input: text,
|
||||
});
|
||||
return response.data[0].embedding;
|
||||
}
|
||||
|
||||
function getRandomItem<T>(arr: T[]): T {
|
||||
if (arr.length === 0) {
|
||||
throw new Error('The array is empty.');
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { boolean, char, doublePrecision, integer, jsonb, pgEnum, pgTable, serial, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
|
||||
import { boolean, char, doublePrecision, integer, jsonb, pgEnum, pgTable, serial, text, timestamp, uuid, varchar, vector } from 'drizzle-orm/pg-core';
|
||||
import { AreasServed, LicensedIn } from 'src/models/db.model';
|
||||
|
||||
export const PG_CONNECTION = 'PG_CONNECTION';
|
||||
export const genderEnum = pgEnum('gender', ['male', 'female']);
|
||||
export const customerTypeEnum = pgEnum('customerType', ['buyer', 'professional']);
|
||||
@@ -58,6 +57,9 @@ export const businesses = pgTable('businesses', {
|
||||
updated: timestamp('updated'),
|
||||
visits: integer('visits'),
|
||||
lastVisit: timestamp('lastVisit'),
|
||||
// Neue Spalte für das OpenAI Embedding
|
||||
embedding: vector('embedding', { dimensions: 1536 }),
|
||||
// embedding: sql`vector(1536)`,
|
||||
});
|
||||
|
||||
export const commercials = pgTable('commercials', {
|
||||
|
||||
Reference in New Issue
Block a user