Skip to content

Commit bc09991

Browse files
committed
Add support for hosted file search and vector store IDs
HostedFileSearchTool => Collection Search HostedVectorStoreContent => CollectionIds
1 parent cdfc72c commit bc09991

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Extensions.Grok/GrokChatClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ GetCompletionsRequest MapToRequest(IEnumerable<ChatMessage> messages, ChatOption
252252
{
253253
request.Tools.Add(new Tool { CodeExecution = new CodeExecution { } });
254254
}
255+
else if (tool is HostedFileSearchTool fileSearch)
256+
{
257+
var toolProto = new CollectionsSearch();
258+
259+
if (fileSearch.Inputs?.OfType<HostedVectorStoreContent>() is { } vectorStores)
260+
toolProto.CollectionIds.AddRange(vectorStores.Select(x => x.VectorStoreId).Distinct());
261+
262+
if (fileSearch.MaximumResultCount is { } maxResults)
263+
toolProto.Limit = maxResults;
264+
265+
request.Tools.Add(new Tool { CollectionsSearch = toolProto });
266+
}
255267
}
256268
}
257269

src/Tests/GrokTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,30 @@ public async Task GrokInvokesHostedCodeExecution()
266266
response.Messages.SelectMany(x => x.Contents).OfType<HostedToolCallContent>(),
267267
x => x.ToolCall.Type == Devlooped.Grok.ToolCallType.CodeExecutionTool);
268268
}
269+
270+
[SecretsFact("XAI_API_KEY")]
271+
public async Task GrokInvokesHostedCollectionSearch()
272+
{
273+
var messages = new Chat()
274+
{
275+
{ "user", "¿Cuál es el monto exacto del rango de la multa por inasistencia injustificada a la audiencia señalada por el juez en el proceso sucesorio, según lo establecido en el Artículo 691 del Código Procesal Civil y Comercial de la Nación (Ley 17.454)?" },
276+
};
277+
278+
var grok = new GrokClient(Configuration["XAI_API_KEY"]!).AsIChatClient("grok-4-fast");
279+
280+
var options = new ChatOptions
281+
{
282+
Tools = [new HostedFileSearchTool {
283+
Inputs = [new HostedVectorStoreContent("collection_91559d9b-a55d-42fe-b2ad-ecf8904d9049")]
284+
}]
285+
};
286+
287+
var response = await grok.GetResponseAsync(messages, options);
288+
var text = response.Text;
289+
290+
Assert.Contains("11,74", text);
291+
Assert.Contains(
292+
response.Messages.SelectMany(x => x.Contents).OfType<HostedToolCallContent>(),
293+
x => x.ToolCall.Type == Devlooped.Grok.ToolCallType.CollectionsSearchTool);
294+
}
269295
}

0 commit comments

Comments
 (0)