Skip to content
forked from 3ventic/EvtSource

Server-Sent Events client implementation for .net core

License

Notifications You must be signed in to change notification settings

lknbv5/EvtSource

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EvtSource

A .net core client library for server-sent events.

EvtSource的改进优化版本, 增加对post的支持

Usage Example

//get sse
var evt = new EventSourceReader(new Uri("https://example.com/some/url/to/SSE")).Start();
evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => Console.WriteLine($"{e.Event} : {e.Message}");
evt.Disconnected += async (object sender, DisconnectEventArgs e) => {
    Console.WriteLine($"Retry: {e.ReconnectDelay} - Error: {e.Exception}");
    await Task.Delay(e.ReconnectDelay);
    evt.Start(); // Reconnect to the same URL
};

//post sse
var url = "http://10.8.2.251:3001/v1/chat/completions"; // 替换为你的SSE服务地址
var data = @"{ 
      ""model"":""qwen-long"",
      ""messages"": [ 
        { ""role"": ""system"", ""content"": ""用中文回答用户的问题"" },
        { ""role"": ""user"", ""content"": ""介绍一下你自己"" }
      ], 
      ""temperature"": 0.7, 
      ""stream"": true
    }";
var content = new StringContent(data,Encoding.UTF8,"application/json");
var evt = new EventSourceReader(new Uri(url), content,("Authorization", "Bearer sk-Z2egX6DGBQ6BcRN19fBf460d192045869d6b1c60867d4e2b")).Start();
evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => Console.WriteLine($"{e.Event} : {e.Message}");

About

Server-Sent Events client implementation for .net core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%