mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
chore: bump package versions + fix linter
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"use server"
|
||||
|
||||
import { ActionState } from "@/lib/actions"
|
||||
import { AnalyzeAttachment } from "./attachments"
|
||||
import { updateFile } from "@/models/files"
|
||||
import { getSettings, getLLMSettings } from "@/models/settings"
|
||||
import { getLLMSettings, getSettings } from "@/models/settings"
|
||||
import { AnalyzeAttachment } from "./attachments"
|
||||
import { requestLLM } from "./providers/llmProvider"
|
||||
|
||||
export type AnalysisResult = {
|
||||
@@ -18,7 +18,6 @@ export async function analyzeTransaction(
|
||||
fileId: string,
|
||||
userId: string
|
||||
): Promise<ActionState<AnalysisResult>> {
|
||||
|
||||
const settings = await getSettings(userId)
|
||||
const llmSettings = getLLMSettings(settings)
|
||||
|
||||
@@ -45,7 +44,7 @@ export async function analyzeTransaction(
|
||||
success: true,
|
||||
data: {
|
||||
output: result,
|
||||
tokensUsed: tokensUsed
|
||||
tokensUsed: tokensUsed,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -30,79 +30,76 @@ export interface LLMResponse {
|
||||
|
||||
async function requestLLMUnified(config: LLMConfig, req: LLMRequest): Promise<LLMResponse> {
|
||||
try {
|
||||
const temperature = 0;
|
||||
let model: any;
|
||||
const temperature = 0
|
||||
let model: any
|
||||
if (config.provider === "openai") {
|
||||
model = new ChatOpenAI({
|
||||
apiKey: config.apiKey,
|
||||
model: config.model,
|
||||
temperature: temperature,
|
||||
});
|
||||
})
|
||||
} else if (config.provider === "google") {
|
||||
model = new ChatGoogleGenerativeAI({
|
||||
apiKey: config.apiKey,
|
||||
model: config.model,
|
||||
temperature: temperature,
|
||||
});
|
||||
})
|
||||
} else if (config.provider === "mistral") {
|
||||
model = new ChatMistralAI({
|
||||
apiKey: config.apiKey,
|
||||
model: config.model,
|
||||
temperature: temperature,
|
||||
});
|
||||
})
|
||||
} else {
|
||||
return {
|
||||
output: {},
|
||||
provider: config.provider,
|
||||
error: "Unknown provider",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const structuredModel = model.withStructuredOutput(req.schema, { 'name': 'transaction'});
|
||||
const structuredModel = model.withStructuredOutput(req.schema, { name: "transaction" })
|
||||
|
||||
let message_content: any = [{ type: "text", text: req.prompt }];
|
||||
let message_content: any = [{ type: "text", text: req.prompt }]
|
||||
if (req.attachments && req.attachments.length > 0) {
|
||||
const images = req.attachments.map(att => ({
|
||||
const images = req.attachments.map((att) => ({
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: `data:${att.contentType};base64,${att.base64}`
|
||||
url: `data:${att.contentType};base64,${att.base64}`,
|
||||
},
|
||||
}));
|
||||
message_content.push(...images);
|
||||
}))
|
||||
message_content.push(...images)
|
||||
}
|
||||
const messages: BaseMessage[] = [
|
||||
new HumanMessage({ content: message_content })
|
||||
];
|
||||
const messages: BaseMessage[] = [new HumanMessage({ content: message_content })]
|
||||
|
||||
const response = await structuredModel.invoke(messages);
|
||||
const response = await structuredModel.invoke(messages)
|
||||
|
||||
return {
|
||||
output: response,
|
||||
provider: config.provider,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
output: {},
|
||||
provider: config.provider,
|
||||
error: error instanceof Error ? error.message : `${config.provider} request failed`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestLLM(settings: LLMSettings, req: LLMRequest): Promise<LLMResponse> {
|
||||
for (const config of settings.providers) {
|
||||
if (!config.apiKey || !config.model) {
|
||||
console.info('Skipping provider:', config.provider);
|
||||
continue;
|
||||
console.info("Skipping provider:", config.provider)
|
||||
continue
|
||||
}
|
||||
console.info('Use provider:', config.provider);
|
||||
console.info("Use provider:", config.provider)
|
||||
|
||||
const response = await requestLLMUnified(config, req);
|
||||
const response = await requestLLMUnified(config, req)
|
||||
|
||||
if (!response.error) {
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
return response
|
||||
} else {
|
||||
console.error(response.error)
|
||||
}
|
||||
}
|
||||
@@ -111,5 +108,5 @@ export async function requestLLM(settings: LLMSettings, req: LLMRequest): Promis
|
||||
output: {},
|
||||
provider: settings.providers[0]?.provider || "openai",
|
||||
error: "All LLM providers failed or are not configured",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ export const fieldsToJsonSchema = (fields: Field[]) => {
|
||||
...schemaProperties,
|
||||
items: {
|
||||
type: "array",
|
||||
description: "Separate items, products or transactions in the file which have own name and price or sum. Find all items!",
|
||||
description:
|
||||
"Separate items, products or transactions in the file which have own name and price or sum. Find all items!",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: schemaProperties,
|
||||
|
||||
Reference in New Issue
Block a user