bugfixing #2
This commit is contained in:
parent
2a6c56ed23
commit
1c4dcdd108
4 changed files with 25 additions and 28 deletions
|
|
@ -1,22 +1,8 @@
|
|||
import { ENRICHMENT_SYSTEM_PROMPT } from "../config/prompt.js";
|
||||
import { buildSystemPrompt } from "../config/prompt.js";
|
||||
import { createAdapter } from "./llm-adapters/factory.js";
|
||||
import { BATCH_CONFIG } from "../config/batch.js";
|
||||
import type { Language, Pos, EnrichedSense } from "./merge-enriched-data.js";
|
||||
|
||||
const LANG_MAP: Record<string, string> = {
|
||||
english: "en",
|
||||
italian: "it",
|
||||
german: "de",
|
||||
french: "fr",
|
||||
spanish: "es",
|
||||
};
|
||||
|
||||
const POS_MAP: Record<string, string> = {
|
||||
nouns: "noun",
|
||||
verbs: "verb",
|
||||
adverbs: "adverb",
|
||||
adjectives: "adjective",
|
||||
};
|
||||
import { LANG_MAP, POS_MAP, ALL_LANGUAGES } from "../config/constants.js";
|
||||
|
||||
interface LlmResponse {
|
||||
content: string;
|
||||
|
|
@ -42,9 +28,16 @@ export interface EnrichmentResult {
|
|||
* Calls the LLM with the enrichment prompt.
|
||||
* Returns the response content and timing metrics.
|
||||
*/
|
||||
async function callLlm(words: string[]): Promise<LlmResponse> {
|
||||
async function callLlm(
|
||||
words: string[],
|
||||
rawLanguage: string,
|
||||
rawPos: string,
|
||||
): Promise<LlmResponse> {
|
||||
const adapter = createAdapter();
|
||||
return adapter.call(words, ENRICHMENT_SYSTEM_PROMPT);
|
||||
const sourceCode = LANG_MAP[rawLanguage] || rawLanguage;
|
||||
const targetLanguages = ALL_LANGUAGES.filter((lang) => lang !== sourceCode);
|
||||
const prompt = buildSystemPrompt(rawLanguage, rawPos, targetLanguages);
|
||||
return adapter.call(words, prompt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,7 +133,7 @@ export async function enrichWord(
|
|||
rawLanguage: string,
|
||||
rawPos: string,
|
||||
): Promise<EnrichmentResult> {
|
||||
const llmResponse = await callLlm(words);
|
||||
const llmResponse = await callLlm(words, rawLanguage, rawPos);
|
||||
const parsed = parseLlmResponse(llmResponse.content, words);
|
||||
const results = buildEnrichedData(parsed, rawLanguage, rawPos);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue