AI szopás
This commit is contained in:
parent
538dba5773
commit
f048b999cf
File diff suppressed because one or more lines are too long
|
|
@ -27,10 +27,12 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="9.0.10" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="9.0.10" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.10" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />
|
||||||
<!--<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />-->
|
<!--<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />-->
|
||||||
<PackageReference Include="PdfPig" Version="0.1.11" />
|
<PackageReference Include="PdfPig" Version="0.1.11" />
|
||||||
<PackageReference Include="PdfPig.Rendering.Skia" Version="0.1.11.5" />
|
<PackageReference Include="PdfPig.Rendering.Skia" Version="0.1.11.5" />
|
||||||
<PackageReference Include="SendGrid" Version="9.29.3" />
|
<PackageReference Include="SendGrid" Version="9.29.3" />
|
||||||
|
<PackageReference Include="System.Memory.Data" Version="9.0.10" />
|
||||||
<PackageReference Include="Tesseract" Version="5.2.0" />
|
<PackageReference Include="Tesseract" Version="5.2.0" />
|
||||||
<PackageReference Include="TesseractOCR" Version="5.5.1" />
|
<PackageReference Include="TesseractOCR" Version="5.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -312,6 +312,34 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services
|
||||||
_assistantId ??= await FindOrCreateAssistantAsync("PDF and Image Analyzer Assistant");
|
_assistantId ??= await FindOrCreateAssistantAsync("PDF and Image Analyzer Assistant");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task CleanupAllVectorStoresAsync()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Cleaning up all existing vector stores...");
|
||||||
|
var listRequest = new HttpRequestMessage(HttpMethod.Get, $"{BaseUrl}/vector_stores");
|
||||||
|
listRequest.Headers.Add("OpenAI-Beta", "assistants=v2");
|
||||||
|
|
||||||
|
var response = await _httpClient.SendAsync(listRequest);
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
using var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
|
||||||
|
var vectorStores = json.RootElement.GetProperty("data");
|
||||||
|
|
||||||
|
foreach (var vectorStore in vectorStores.EnumerateArray())
|
||||||
|
{
|
||||||
|
var id = vectorStore.GetProperty("id").GetString();
|
||||||
|
var name = vectorStore.TryGetProperty("name", out var nameElement) && nameElement.ValueKind != JsonValueKind.Null
|
||||||
|
? nameElement.GetString()
|
||||||
|
: "Unnamed";
|
||||||
|
|
||||||
|
var deleteRequest = new HttpRequestMessage(HttpMethod.Delete, $"{BaseUrl}/vector_stores/{id}");
|
||||||
|
deleteRequest.Headers.Add("OpenAI-Beta", "assistants=v2");
|
||||||
|
await _httpClient.SendAsync(deleteRequest);
|
||||||
|
|
||||||
|
Console.WriteLine($"Deleted vector store: {name} ({id})");
|
||||||
|
}
|
||||||
|
Console.WriteLine("Vector store cleanup complete!");
|
||||||
|
}
|
||||||
|
}
|
||||||
//TEMPORARY: Cleanup all assistants (for testing purposes) - A.
|
//TEMPORARY: Cleanup all assistants (for testing purposes) - A.
|
||||||
public async Task CleanupAllAssistantsAsync()
|
public async Task CleanupAllAssistantsAsync()
|
||||||
{
|
{
|
||||||
|
|
@ -347,8 +375,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services
|
||||||
|
|
||||||
public async Task<string?> AnalyzePdfAsync(Stream file, string fileName, string userPrompt)
|
public async Task<string?> AnalyzePdfAsync(Stream file, string fileName, string userPrompt)
|
||||||
{
|
{
|
||||||
|
|
||||||
await EnsureAssistantAndVectorStoreAsync();
|
await EnsureAssistantAndVectorStoreAsync();
|
||||||
|
|
||||||
var fileId = await UploadFileAsync(file, fileName);
|
var fileId = await UploadFileAsync(file, fileName);
|
||||||
var isImage = IsImageFile(fileName);
|
var isImage = IsImageFile(fileName);
|
||||||
|
|
||||||
|
|
@ -640,7 +668,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services
|
||||||
var assistantBody = new
|
var assistantBody = new
|
||||||
{
|
{
|
||||||
name = name,
|
name = name,
|
||||||
instructions = "You are an assistant that analyzes uploaded files. When you receive an image, analyze and describe what you see in the image in detail. When you receive a PDF or text document, use the file_search tool to find and analyze relevant information. Always respond directly to the user's question about the file they uploaded.",
|
instructions = "You are an assistant that analyzes uploaded files. When you receive an image, analyze and describe what you see in the image in detail. When you receive a PDF or text document, use the file_search tool to find and analyze relevant information. Always respond directly according to the user's instructions about the current file they upload.",
|
||||||
model = "gpt-4o",
|
model = "gpt-4o",
|
||||||
tools = new[] { new { type = "file_search" } }
|
tools = new[] { new { type = "file_search" } }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue