Skip to content

Commit 662d02c

Browse files
committed
Add X news search too to sanity check
1 parent 5a0a91c commit 662d02c

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/xAI.Tests/ChatClientTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,5 +514,11 @@ public async Task GrokCustomFactoryInvokedFromOptions()
514514
Assert.Equal("Hey Cazzulino!", response.Text);
515515
}
516516

517+
[Fact]
518+
public async Task AskFiles()
519+
{
520+
521+
}
522+
517523
record Response(DateOnly Today, string Release, decimal Price);
518524
}

src/xAI.Tests/SanityChecks.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,19 @@ public async Task IntegrationTestStreaming()
185185
{ "system", "You are a helpful assistant that uses all available tools to answer questions accurately." },
186186
{ "user",
187187
$$"""
188-
Current timestamp is {{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}}.
189-
190188
Please answer the following questions using the appropriate tools:
191189
1. What is today's date? (use get_date tool)
192-
2. What is the current price of Tesla (TSLA) stock? (use Yahoo news web search)
193-
3. Calculate the earnings that would be produced by compound interest to $5k at 4% annually for 5 years (use code interpreter)
194-
4. What is the latest release version of the {{ThisAssembly.Git.Url}} repository? (use GitHub MCP tool)
190+
2. What is the current price of Tesla (TSLA) stock? (use Yahoo news web search, always include citations)
191+
3. What is the top news from Tesla on X?
192+
4. Calculate the earnings that would be produced by compound interest to $5k savings at 4% annually for 5 years (use code interpreter).
193+
Return just the earnings, not the grand total of savings plus earnings).
194+
5. What is the latest release version of the {{ThisAssembly.Git.Url}} repository? (use GitHub MCP tool)
195195
196196
Respond with a JSON object in this exact format:
197197
{
198198
"today": "[date from get_date in YYYY-MM-DD format]",
199199
"tesla_price": [numeric price from web search],
200+
"tesla_news": "[top news from X]",
200201
"compound_interest": [numeric result from code interpreter],
201202
"latest_release": "[version string from GitHub]"
202203
}
@@ -215,33 +216,32 @@ 2. What is the current price of Tesla (TSLA) stock? (use Yahoo news web search)
215216

216217
var options = new GrokChatOptions
217218
{
219+
ResponseFormat = ChatResponseFormat.Json,
218220
Include =
219221
[
220222
IncludeOption.InlineCitations,
221223
IncludeOption.WebSearchCallOutput,
222224
IncludeOption.CodeExecutionCallOutput,
223-
IncludeOption.McpCallOutput
225+
IncludeOption.McpCallOutput,
226+
IncludeOption.XSearchCallOutput,
224227
],
225228
Tools =
226229
[
227-
// Client-side tool
228230
AIFunctionFactory.Create(() =>
229231
{
230232
getDateCalls++;
231233
return DateTime.Now.ToString("yyyy-MM-dd");
232234
}, "get_date", "Gets the current date in YYYY-MM-DD format"),
233-
234-
// Hosted web search tool
235235
new HostedWebSearchTool(),
236-
237-
// Hosted code interpreter tool
238236
new HostedCodeInterpreterTool(),
239-
240-
// Hosted MCP server tool (GitHub)
241237
new HostedMcpServerTool("GitHub", "https://api.githubcopilot.com/mcp/")
242238
{
243239
AuthorizationToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN")!,
244240
AllowedTools = ["list_releases", "get_release_by_tag"],
241+
},
242+
new GrokXSearchTool
243+
{
244+
AllowedHandles = ["tesla"]
245245
}
246246
]
247247
};
@@ -339,6 +339,10 @@ void AssertIntegrationTest(ChatResponse response, Func<int> getDateCalls)
339339

340340
output.WriteLine($"Parsed response: Today={result.Today}, TeslaPrice={result.TeslaPrice}, CompoundInterest={result.CompoundInterest}, LatestRelease={result.LatestRelease}");
341341
}
342+
else
343+
{
344+
Assert.Fail("Response did not contain expected JSON output");
345+
}
342346

343347
output.WriteLine($"Code interpreter calls: {codeInterpreterCalls.Count}");
344348
output.WriteLine($"MCP calls: {mcpCalls.Count}");
@@ -347,6 +351,7 @@ void AssertIntegrationTest(ChatResponse response, Func<int> getDateCalls)
347351
record IntegrationTestResponse(
348352
string Today,
349353
decimal TeslaPrice,
354+
string TeslaNews,
350355
decimal CompoundInterest,
351356
string LatestRelease);
352357
}

src/xAI/GrokProtocolExtensions.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Linq;
1+
using System.ComponentModel;
52
using System.Text;
63
using System.Text.Json;
74
using System.Text.Json.Serialization;
8-
using System.Threading.Tasks;
9-
using Google.Protobuf;
105
using Microsoft.Extensions.AI;
116
using xAI.Protocol;
12-
using static Google.Protobuf.Reflection.GeneratedCodeInfo.Types;
137

148
namespace xAI;
159

0 commit comments

Comments
 (0)