-
-
Save ayende/00dabd9d95255c41c80d5600981fe166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // run via: dotnet run app.cs | |
| #:package RavenDB.Client@7.1.2 | |
| using System.Linq; | |
| using Raven.Client.Documents; | |
| using Raven.Client.Documents.AI; | |
| using Newtonsoft.Json; | |
| using var store = new DocumentStore | |
| { | |
| Urls = new[] { "http://localhost:8080" }, | |
| Database = "orders" | |
| }; | |
| store.Initialize(); | |
| var conversation = store.AI.Conversation( | |
| agentId: "orders-agent", | |
| conversationId: "chats/0000000000000009111-A", | |
| new AiConversationCreationOptions | |
| { | |
| Parameters = new() | |
| { | |
| ["company"] = "companies/1-A" | |
| }, | |
| }); | |
| conversation.Handle<AddToCartArgs>("AddToCart", async args => | |
| { | |
| Console.WriteLine($"- Added to cart: {args.ProductId}, Quantity: {args.Quantity}"); | |
| return "Added to cart"; | |
| }); | |
| Console.Write("(new conversation)"); | |
| while (true) | |
| { | |
| Console.Write($"> "); | |
| var userInput = Console.ReadLine(); | |
| if (string.Equals(userInput, "exit", StringComparison.OrdinalIgnoreCase)) | |
| break; | |
| conversation.SetUserPrompt(userInput); | |
| var result = await conversation.RunAsync<ModelAnswer>(); | |
| Console.WriteLine(); | |
| var json = JsonConvert.SerializeObject(result.Answer, Formatting.Indented); | |
| Console.WriteLine(json); | |
| System.Console.Write($"('{conversation.Id}')"); | |
| } | |
| public record ModelAnswer(string Reply, string[] ProductIds, string[] OrderIds); | |
| public record AddToCartArgs(string ProductId, int Quantity); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment