Streaming -Antwort von der ASP.NET -Kern -Web -API bis hin zu Angular FrontendC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Streaming -Antwort von der ASP.NET -Kern -Web -API bis hin zu Angular Frontend

Post by Anonymous »

Ich erstelle Lappen mit Azure -Technologien. Dazu muss ich Inhalte so streamen, um Frontend zum Schnell Ergebnis zu stream. Andernfalls dauert es lange, bis sie antwortet.[HttpPost("getCopilotResponseV3")]
public IEnumerable GetCopilotResponsev3(BLCopilotRequestV2 req)
{
CollectionResult response;

try
{
response = _bLOpenAIService.GetOpenAIResponseStream(req);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting OpenAI response stream.");
yield break;
}

var enumerator = response.GetEnumerator();

using (enumerator)
{
while (enumerator.MoveNext())
{
foreach (var cnt in enumerator.Current.ContentUpdate)
{
yield return cnt.Text;
}
}
}
}
< /code>
Hier ist der Angular Service Code, den ich geschrieben habe: < /p>
requestFromBLCopilotAIV3(request: BLCopilotRequestV2) {
return this.http
.post(environment.getEndpoint() + 'Common/getCopilotResponseV3', request,{
responseType: 'text',observe: 'events'
});
}
< /code>
Dies ist der Frontend -Komponentencode: < /p>
this.copilotService.requestFromBLCopilotAIV3({ messageList: cpMessageList, indexName: this.copilotComponent.defaultValue, semanticConfigName:this.copilotComponent.mapName } as BLCopilotRequestV2)
.pipe(takeUntil(this.stopSignal))
.subscribe({
next: (event : any) => {
console.log(event)
},
complete: () => {
//this.changeDetector.detectChanges();
},
error: (err) => {
console.error(err);
this.isLoading = false;
this.responseStarted = false;
this.changeDetector.detectChanges();
}
});
< /code>
Wenn ich die Konsole testet, druckt der Code so etwas: < /p>
{
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "https://localhost:7036/api/Common/getBL ... ResponseV3",
"ok": true,
"type": 4,
"body": "[\"The\",\" requested\",\" information\",\" is\",\" not\",\" available\",\" in\",\" the\",\" retrieved\",\" data\",\".\",\" Please\",\" try\",\" another\",\" query\",\" or\",\" topic\",\".\"]"
}
< /code>
Es ist ein OK -Inhalt, nicht gefundene Antwort ist kein Problem, aber dies ist nicht meine erwartete Ausgabe. < /p>
Meine erwartete Ausgabe wäre: < /p>
the
requested
information
is
not
found
< /code>
Wie eins nach einer Antwort. Rendite Rendite scheint in Ordnung zu sein.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post