sgcWebSockets 2024.10.0 から、汎用モデルを使用する代わりに OpenAI Assistants を使用して独自のファイルを検索できます。
File Search はアシスタントにモデル外の知識 (独自の製品情報やユーザーが提供したドキュメントなど) を追加します。OpenAI は自動的にドキュメントを解析・チャンク化し、エンベディングを作成・保存し、ベクトル検索とキーワード検索の両方を使用して、ユーザーのクエリに回答するための関連コンテンツを取得します。
サポート対象のファイル
サポート対象のファイル
text/ MIME タイプの場合、エンコーディングは utf-8、utf-16、または ascii のいずれかである必要があります。
| ファイル形式 | MIME タイプ |
|---|---|
.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 |
ステップ 1: File Search を有効にした新しいアシスタントを作成
アシスタントの tools パラメーターで file_search を有効にして、新しいアシスタントを作成します。
file_search ツールが有効になると、ユーザーメッセージに基づいてモデルがコンテンツを取得するタイミングを決定します。
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;
ステップ 2: ファイルをアップロードしてベクトルストアに追加
ファイルにアクセスするために、file_search ツールは Vector Store オブジェクトを使用します。ファイルをアップロードし、それらを格納する Vector Store を作成します。
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;
ステップ 3: 実行を作成して出力を確認
Run を作成し、モデルが File Search ツールを使用してユーザーの質問への応答を提供することを確認します。
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;
