@@ -763,40 +763,6 @@ class MyService(IChatClients clients)
763763}
764764```
765765
766- ## Persist AI Chat History
767-
768- By default AI Chat is designed to be minimally invasive and doesn't require anything other than the API Keys
769- needed to access the AI Models it should use.
770-
771- If preferred you can choose to persist AI Chat History made through the external ChatCompletion API with the
772- ` OnChatCompletionSuccessAsync ` and ` OnChatCompletionFailedAsync ` callbacks which can be used to store successful
773- and failed requests in your preferred data store using the included
774- [ ChatCompletionLog] ( https://github.com/ServiceStack/ServiceStack/blob/main/ServiceStack/src/ServiceStack.AI.Chat/ChatCompletionLog.cs )
775- or your own data model:
776-
777- ``` csharp
778- public class ConfigureAiChat : IHostingStartup
779- {
780- public void Configure (IWebHostBuilder builder ) => builder
781- .ConfigureServices (services => {
782- services .AddPlugin (new ChatFeature
783- {
784- OnChatCompletionSuccessAsync = async (request , response , req ) => {
785- using var db = await req .Resolve <IDbConnectionFactory >().OpenAsync ();
786- await db .InsertAsync (req .ToChatCompletionLog (request , response ));
787- },
788- OnChatCompletionFailedAsync = async (request , exception , req ) => {
789- using var db = await req .Resolve <IDbConnectionFactory >().OpenAsync ();
790- await db .InsertAsync (req .ToChatCompletionLog (request , exception ));
791- },
792- });
793- }).ConfigureAppHost (appHost => {
794- using var db = appHost .Resolve <IDbConnectionFactory >().Open ();
795- db .CreateTableIfNotExists <ChatCompletionLog >();
796- });
797- }
798- ```
799-
800766### Compatible with llms.py
801767
802768The other benefit of simple configuration and simple solutions, is that they're easy to implement. A perfect example
0 commit comments