Skip to content

Commit

Permalink
chore(embeddings): use framework embeddings, refactor ai providers
Browse files Browse the repository at this point in the history
Signed-off-by: Radek Ježek <[email protected]>
  • Loading branch information
jezekra1 committed Dec 20, 2024
1 parent 98e9426 commit b72da10
Show file tree
Hide file tree
Showing 137 changed files with 389 additions and 6,566 deletions.
5 changes: 1 addition & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ RUN_BULLMQ_WORKERS=runs,runs-cleanup,vectorStores-cleanup,vectorStores-fileProce
# --- BACKEND SECTION ---

# LLM backend, possible values are: ollama, openai, watsonx, bam, ibm-vllm
LLM_BACKEND=watsonx

# Embedding backend, possible values are: ollama, openai, watsonx, bam, caikit
EMBEDDING_BACKEND=watsonx
AI_BACKEND=watsonx

# Extraction backend, possible values are: docling, unstructured-opensource, unstructured-api
EXTRACTION_BACKEND=docling
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pnpm mikro-orm seeder:run
cp .env.example .env
```

- Add values the env vars: CRYPTO_CIPHER_KEY, LLM_BACKEND, EMBEDDING_BACKEND and API key for which ever provider you have chosen.
- Add values the env vars: CRYPTO_CIPHER_KEY, AI_BACKEND and API key for which ever provider you have chosen.

- Run the bee-api:

Expand Down
9 changes: 5 additions & 4 deletions seeders/DatabaseSeeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ref, type EntityManager } from '@mikro-orm/core';
import { type EntityManager, ref } from '@mikro-orm/core';
import { Seeder } from '@mikro-orm/seeder';

import { OrganizationUserRole, ProjectRole } from '@/administration/entities/constants';
Expand All @@ -30,7 +30,8 @@ import { ProjectApiKey } from '@/administration/entities/project-api-key.entity'
import { API_KEY_PREFIX, scryptSecret } from '@/auth/utils';
import { IBM_ORGANIZATION_OWNER_ID } from '@/config';
import { redactProjectKeyValue } from '@/administration/helpers';
import { Agent, getDefaultModel } from '@/runs/execution/constants';
import { Agent } from '@/runs/execution/constants';
import { defaultAIProvider } from '@/runs/execution/provider';

const USER_EXTERNAL_ID = 'test';
const PROJECT_API_KEY = `${API_KEY_PREFIX}testkey`;
Expand Down Expand Up @@ -91,7 +92,7 @@ export class DatabaseSeeder extends Seeder {
redactedValue: redactProjectKeyValue(PROJECT_API_KEY)
});
const beeAssistant = new Assistant({
model: getDefaultModel(),
model: defaultAIProvider.createChatLLM().modelId,
agent: Agent.BEE,
tools: [
{
Expand Down Expand Up @@ -120,7 +121,7 @@ export class DatabaseSeeder extends Seeder {
}
});
const streamlitAssistant = new Assistant({
model: getDefaultModel(),
model: defaultAIProvider.createChatLLM().modelId,
agent: Agent.STREAMLIT,
tools: [],
name: 'Builder Assistant',
Expand Down
5 changes: 3 additions & 2 deletions src/assistants/assistants.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import { APIError, APIErrorCode } from '@/errors/error.entity.js';
import { Tool, ToolType } from '@/tools/entities/tool/tool.entity.js';
import { getUpdatedValue } from '@/utils/update.js';
import { createDeleteResponse } from '@/utils/delete.js';
import { Agent, getDefaultModel } from '@/runs/execution/constants.js';
import { Agent } from '@/runs/execution/constants.js';
import { defaultAIProvider } from '@/runs/execution/provider';

export function toDto(assistant: Loaded<Assistant>): AssistantDto {
return {
Expand Down Expand Up @@ -113,7 +114,7 @@ export async function createAssistant({
description: description ?? undefined,
metadata,
topP: top_p ?? undefined,
model: model ?? getDefaultModel(),
model: model ?? defaultAIProvider.createChatLLM().modelId,
agent,
temperature: temperature ?? undefined,
systemPromptOverwrite: system_prompt_overwrite ?? undefined
Expand Down
9 changes: 4 additions & 5 deletions src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import {
import { ChatMessageRole } from './constants';
import { Chat } from './entities/chat.entity';

import { createChatLLM } from '@/runs/execution/factory';
import { getLogger } from '@/logger';
import { APIError, APIErrorCode } from '@/errors/error.entity';
import { getDefaultModel } from '@/runs/execution/constants';
import { ORM } from '@/database';
import { defaultAIProvider } from '@/runs/execution/provider';

const getChatLogger = () => getLogger();

Expand All @@ -52,12 +51,12 @@ export function toDto(chat: Loaded<Chat>): ChatCompletionCreateResponse {
}

export async function createChatCompletion({
model = getDefaultModel(),
model,
messages,
response_format
}: ChatCompletionCreateBody): Promise<ChatCompletionCreateResponse> {
const llm = createChatLLM({ model });
const chat = new Chat({ model, messages, responseFormat: response_format });
const llm = defaultAIProvider.createChatLLM({ model });
const chat = new Chat({ model: llm.modelId, messages, responseFormat: response_format });
await ORM.em.persistAndFlush(chat);
try {
const schema = response_format?.json_schema.schema;
Expand Down
6 changes: 2 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import 'dotenv/config';
import { difference } from 'remeda';

import {
AIBackend,
CodeInterpreterStorageBackend,
LLMBackend,
SearchToolBackend
} from './runs/execution/constants';
import { EmbeddingBackend } from './embedding/constants';
import { ExtractionBackend } from './files/extraction/constants';

import { QueueName } from '@/jobs/constants.js';
Expand Down Expand Up @@ -81,8 +80,7 @@ export const AUTH_CLIENT_SECRET = getEnv('AUTH_CLIENT_SECRET');
export const AUTH_AUDIENCE = getEnv('AUTH_AUDIENCE');

// Backends
export const LLM_BACKEND = getEnum('LLM_BACKEND', Object.values(LLMBackend));
export const EMBEDDING_BACKEND = getEnum('EMBEDDING_BACKEND', Object.values(EmbeddingBackend));
export const AI_BACKEND = getEnum('AI_BACKEND', Object.values(AIBackend));
export const EXTRACTION_BACKEND = getEnum('EXTRACTION_BACKEND', Object.values(ExtractionBackend));

export const OLLAMA_URL = getEnv('OLLAMA_URL', null);
Expand Down
56 changes: 0 additions & 56 deletions src/embedding/adapters/bam-embedding.ts

This file was deleted.

61 changes: 0 additions & 61 deletions src/embedding/adapters/caikit/caikit-embedding.ts

This file was deleted.

57 changes: 0 additions & 57 deletions src/embedding/adapters/caikit/grpc/client.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/embedding/adapters/caikit/grpc/constants.ts

This file was deleted.

Loading

0 comments on commit b72da10

Please sign in to comment.