@@ -2631,40 +2631,6 @@ class MyService(IChatClients clients)
26312631}
26322632```
26332633
2634- ## Persist AI Chat History
2635-
2636- By default AI Chat is designed to be minimally invasive and doesn't require anything other than the API Keys
2637- needed to access the AI Models it should use.
2638-
2639- If preferred you can choose to persist AI Chat History made through the external ChatCompletion API with the
2640- ` OnChatCompletionSuccessAsync ` and ` OnChatCompletionFailedAsync ` callbacks which can be used to store successful
2641- and failed requests in your preferred data store using the included
2642- [ ChatCompletionLog] ( https://github.com/ServiceStack/ServiceStack/blob/main/ServiceStack/src/ServiceStack.AI.Chat/ChatCompletionLog.cs )
2643- or your own data model:
2644-
2645- ``` csharp
2646- public class ConfigureAiChat : IHostingStartup
2647- {
2648- public void Configure (IWebHostBuilder builder ) => builder
2649- .ConfigureServices (services => {
2650- services .AddPlugin (new ChatFeature
2651- {
2652- OnChatCompletionSuccessAsync = async (request , response , req ) => {
2653- using var db = await req .Resolve <IDbConnectionFactory >().OpenAsync ();
2654- await db .InsertAsync (req .ToChatCompletionLog (request , response ));
2655- },
2656- OnChatCompletionFailedAsync = async (request , exception , req ) => {
2657- using var db = await req .Resolve <IDbConnectionFactory >().OpenAsync ();
2658- await db .InsertAsync (req .ToChatCompletionLog (request , exception ));
2659- },
2660- });
2661- }).ConfigureAppHost (appHost => {
2662- using var db = appHost .Resolve <IDbConnectionFactory >().Open ();
2663- db .CreateTableIfNotExists <ChatCompletionLog >();
2664- });
2665- }
2666- ```
2667-
26682634### Compatible with llms.py
26692635
26702636The other benefit of simple configuration and simple solutions, is that they're easy to implement. A perfect example
0 commit comments