move constants to their own files and folder

This commit is contained in:
perf3ct 2025-03-26 17:56:37 +00:00
parent 44b6734034
commit c49883fdfa
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
12 changed files with 56 additions and 25 deletions

View File

@ -2,6 +2,7 @@ import axios from 'axios';
import options from "../../services/options.js";
import log from "../../services/log.js";
import type { Request, Response } from "express";
import { PROVIDER_CONSTANTS } from '../../services/llm/constants/provider_constants.js';
// Map of simplified model names to full model names with versions
const MODEL_MAPPING: Record<string, string> = {
@ -26,7 +27,7 @@ async function listModels(req: Request, res: Response) {
const { baseUrl } = req.body;
// Use provided base URL or default from options, and ensure correct formatting
let anthropicBaseUrl = baseUrl || await options.getOption('anthropicBaseUrl') || 'https://api.anthropic.com';
let anthropicBaseUrl = baseUrl || await options.getOption('anthropicBaseUrl') || PROVIDER_CONSTANTS.ANTHROPIC.BASE_URL;
// Ensure base URL doesn't already include '/v1' and is properly formatted
anthropicBaseUrl = anthropicBaseUrl.replace(/\/+$/, '').replace(/\/v1$/, '');
@ -43,8 +44,8 @@ async function listModels(req: Request, res: Response) {
headers: {
'Content-Type': 'application/json',
'X-Api-Key': apiKey,
'anthropic-version': '2023-06-01',
'anthropic-beta': 'messages-2023-12-15'
'anthropic-version': PROVIDER_CONSTANTS.ANTHROPIC.API_VERSION,
'anthropic-beta': PROVIDER_CONSTANTS.ANTHROPIC.BETA_VERSION
},
timeout: 10000
});
@ -77,12 +78,12 @@ async function listModels(req: Request, res: Response) {
});
// Also include known models that might not be returned by the API
for (const [simpleName, fullName] of Object.entries(MODEL_MAPPING)) {
for (const model of PROVIDER_CONSTANTS.ANTHROPIC.AVAILABLE_MODELS) {
// Check if this model is already in our list
if (!chatModels.some((m: AnthropicModel) => m.id === fullName)) {
if (!chatModels.some((m: AnthropicModel) => m.id === model.id)) {
chatModels.push({
id: fullName,
name: simpleName,
id: model.id,
name: model.name,
type: 'chat'
});
}

View File

@ -13,7 +13,7 @@ import contextService from "../../services/llm/context_service.js";
import sql from "../../services/sql.js";
// Import the index service for knowledge base management
import indexService from "../../services/llm/index_service.js";
import { CONTEXT_PROMPTS } from '../../services/llm/prompts/llm_prompt_constants.js';
import { CONTEXT_PROMPTS } from '../../services/llm/constants/llm_prompt_constants.js';
// LLM service constants
export const LLM_CONSTANTS = {

View File

@ -15,7 +15,7 @@
import log from "../../log.js";
import aiServiceManager from "../ai_service_manager.js";
import { AGENT_TOOL_PROMPTS } from '../prompts/llm_prompt_constants.js';
import { AGENT_TOOL_PROMPTS } from '../constants/llm_prompt_constants.js';
/**
* Represents a single reasoning step taken by the agent

View File

@ -13,7 +13,7 @@
*/
import log from '../../log.js';
import { AGENT_TOOL_PROMPTS } from '../prompts/llm_prompt_constants.js';
import { AGENT_TOOL_PROMPTS } from '../constants/llm_prompt_constants.js';
export interface SubQuery {
id: string;

View File

@ -1,6 +1,6 @@
import options from '../options.js';
import type { AIService, ChatCompletionOptions, ChatResponse, Message } from './ai_interface.js';
import { DEFAULT_SYSTEM_PROMPT } from './prompts/llm_prompt_constants.js';
import { DEFAULT_SYSTEM_PROMPT } from './constants/llm_prompt_constants.js';
export abstract class BaseAIService implements AIService {
protected name: string;

View File

@ -0,0 +1,35 @@
export const PROVIDER_CONSTANTS = {
ANTHROPIC: {
API_VERSION: '2023-06-01',
BETA_VERSION: 'messages-2023-12-15',
BASE_URL: 'https://api.anthropic.com',
DEFAULT_MODEL: 'claude-3-haiku-20240307',
// These are the currently available models from Anthropic
AVAILABLE_MODELS: [
{
id: 'claude-3-opus-20240229',
name: 'Claude 3 Opus',
description: 'Most capable model for highly complex tasks',
maxTokens: 4096
},
{
id: 'claude-3-sonnet-20240229',
name: 'Claude 3 Sonnet',
description: 'Ideal balance of intelligence and speed',
maxTokens: 4096
},
{
id: 'claude-3-haiku-20240307',
name: 'Claude 3 Haiku',
description: 'Fastest and most compact model',
maxTokens: 4096
},
{
id: 'claude-2.1',
name: 'Claude 2.1',
description: 'Previous generation model',
maxTokens: 4096
}
]
}
} as const;

View File

@ -1,6 +1,6 @@
import sanitizeHtml from 'sanitize-html';
import log from '../../../log.js';
import { CONTEXT_PROMPTS } from '../../prompts/llm_prompt_constants.js';
import { CONTEXT_PROMPTS } from '../../constants/llm_prompt_constants.js';
// Constants for context window sizes, defines in-module to avoid circular dependencies
const CONTEXT_WINDOW = {

View File

@ -6,7 +6,7 @@ import queryEnhancer from './query_enhancer.js';
import contextFormatter from './context_formatter.js';
import aiServiceManager from '../../ai_service_manager.js';
import { ContextExtractor } from '../index.js';
import { CONTEXT_PROMPTS } from '../../prompts/llm_prompt_constants.js';
import { CONTEXT_PROMPTS } from '../../constants/llm_prompt_constants.js';
import becca from '../../../../becca/becca.js';
/**

View File

@ -1,7 +1,7 @@
import log from '../../../log.js';
import cacheManager from './cache_manager.js';
import type { Message } from '../../ai_interface.js';
import { CONTEXT_PROMPTS } from '../../prompts/llm_prompt_constants.js';
import { CONTEXT_PROMPTS } from '../../constants/llm_prompt_constants.js';
/**
* Provides utilities for enhancing queries and generating search queries

View File

@ -20,7 +20,7 @@ import type { NoteEmbeddingContext } from "./embeddings/embeddings_interface.js"
import type { OptionDefinitions } from "../options_interface.js";
import sql from "../sql.js";
import sqlInit from "../sql_init.js";
import { CONTEXT_PROMPTS } from './prompts/llm_prompt_constants.js';
import { CONTEXT_PROMPTS } from './constants/llm_prompt_constants.js';
class IndexService {
private initialized = false;

View File

@ -1,6 +1,7 @@
import options from '../../options.js';
import { BaseAIService } from '../base_ai_service.js';
import type { ChatCompletionOptions, ChatResponse, Message } from '../ai_interface.js';
import { PROVIDER_CONSTANTS } from '../constants/provider_constants.js';
export class AnthropicService extends BaseAIService {
// Map of simplified model names to full model names with versions
@ -25,14 +26,8 @@ export class AnthropicService extends BaseAIService {
}
const apiKey = options.getOption('anthropicApiKey');
const baseUrl = options.getOption('anthropicBaseUrl') || 'https://api.anthropic.com';
let model = opts.model || options.getOption('anthropicDefaultModel') || 'claude-3-haiku-20240307';
// Apply model name mapping if needed
if (AnthropicService.MODEL_MAPPING[model]) {
model = AnthropicService.MODEL_MAPPING[model];
console.log(`Mapped model name to: ${model}`);
}
const baseUrl = options.getOption('anthropicBaseUrl') || PROVIDER_CONSTANTS.ANTHROPIC.BASE_URL;
const model = opts.model || options.getOption('anthropicDefaultModel') || PROVIDER_CONSTANTS.ANTHROPIC.DEFAULT_MODEL;
const temperature = opts.temperature !== undefined
? opts.temperature
@ -56,8 +51,8 @@ export class AnthropicService extends BaseAIService {
headers: {
'Content-Type': 'application/json',
'X-Api-Key': apiKey,
'anthropic-version': '2023-06-01',
'anthropic-beta': 'messages-2023-12-15'
'anthropic-version': PROVIDER_CONSTANTS.ANTHROPIC.API_VERSION,
'anthropic-beta': PROVIDER_CONSTANTS.ANTHROPIC.BETA_VERSION
},
body: JSON.stringify({
model,