Ab sgcWebSockets 2024.10.0 kannst du die OpenAI Assistants nutzen, um in deinen eigenen Dateien zu suchen, statt das generische Modell zu verwenden.
File Search erweitert den Assistant um Wissen außerhalb seines Modells, etwa proprietäre Produktinformationen oder Dokumente, die von deinen Nutzern bereitgestellt werden. OpenAI parst und chunked deine Dokumente automatisch, erstellt und speichert die Embeddings und nutzt sowohl Vektor- als auch Keyword-Suche, um relevante Inhalte für die Beantwortung von Nutzeranfragen abzurufen.
Unterstützte Dateien
Unterstützte Dateien
Bei text/-MIME-Typen muss die Kodierung utf-8, utf-16 oder ascii sein.
| Dateiformat | MIME-Typ |
|---|---|
.c | text/x-c |
.cpp | text/x-c++ |
.cs | text/x-csharp |
.css | text/css |
.doc | application/msword |
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.go | text/x-golang |
.html | text/html |
.java | text/x-java |
.js | text/javascript |
.json | application/json |
.md | text/markdown |
.pdf | application/pdf |
.php | text/x-php |
.pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
.py | text/x-python |
.py | text/x-script.python |
.rb | text/x-ruby |
.sh | application/x-sh |
.tex | text/x-tex |
.ts | application/typescript |
.txt | text/plain |
Schritt 1: Einen neuen Assistant mit aktivierter File Search erstellen
Erstelle einen neuen Assistant mit aktivierter file_search im Tools-Parameter des Assistants.
Sobald das file_search-Tool aktiviert ist, entscheidet das Modell anhand der Nutzer-Nachrichten, wann es Inhalte abruft.
Assistant := TsgcAIOpenAIAssistant.Create(nil); Assistant.OpenAIOptions.ApiKey := 'sk-askdjfalskdjfl23kjkjasdefasdfj'; Assistant.AssistantOptions.Name := 'sgcWebSockets HelpDesk'; Assistant.AssistantOptions.Instructions.Text := 'You are a sgcWebSockets HelpDesk Agent. ' + 'Answer questions briefly, in a sentence or less. When asked a question,use the manual to answer the question.' Assistant.AssistantOptions.Model := 'gpt-4o-mini'; Assistant.AssistantOptions.Tools.FileSearch.Enabled := True; Assistant.AssistantOptions.Tools.CodeInterpreter.Enabled := False;
Schritt 2: Dateien hochladen und einem Vector Store hinzufügen
Um auf deine Dateien zuzugreifen, verwendet das file_search-Tool das Vector-Store-Objekt. Lade deine Dateien hoch und erstelle einen Vector Store, der sie aufnimmt.
procedure UploadFile();
var
oDialog: TOpenDialog;
begin
oDialog := TOpenDialog.Create(nil);
Try
if oDialog.Execute then
begin
Screen.Cursor := crHourGlass;
Try
Assistant.UploadVectorStoreFile('sgcVectorStore', oDialog.FileName);
Finally
Screen.Cursor := crDefault;
End;
end;
Finally
oDialog.Free;
End;
end;
Schritt 3: Einen Run erstellen und die Ausgabe prüfen
Erstelle nun einen Run und beobachte, wie das Modell das File-Search-Tool nutzt, um die Frage des Nutzers zu beantworten.
procedure SendMessage()
var
i: Integer;
oMessage: TsgcOpenAIClass_Message;
oMessages: TsgcOpenAIClass_Response_List_Messages;
oRun: TsgcOpenAIClass_Run;
begin
DoLog('[user]: ' + memoMessage.Lines.Text);
Screen.Cursor := crHourGlass;
Try
oMessage := Assistant.CreateMessageText('thread_id', 'Create a WebSocket Client that connects to eSeGeCe WebSocket Server');
if Assigned(oMessage) then
begin
oRun := Assistant.CreateRunAndWait('thread_id');
if Assigned(oRun) then
begin
oMessages := Assistant.GetMessages('thread_id', oRun.Id);
if Assigned(oMessages) and (Length(oMessages.Messages) > 0) then
begin
memoMessage.Lines.Text := '';
for i := 0 to Length(oMessages.Messages) - 1 do
DoLog('[assistant]: ' + DoFormatResponse(oMessages.Messages[i]
.ContentText + #13#10));
end;
end;
end;
Finally
Screen.Cursor := crDefault;
End;
end;
