refactor for better support of streaming and etc ...
This commit is contained in:
+12
-43
@@ -47,7 +47,7 @@ namespace xAiApi.Providers
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> AskAsync(
|
||||
public virtual async Task<string> AskTextAsync(
|
||||
string prompt,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -81,10 +81,6 @@ namespace xAiApi.Providers
|
||||
// Retrieve Response Text ...
|
||||
var result = response.Text;
|
||||
|
||||
//
|
||||
// Dispose Client ...
|
||||
client.Dispose();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -95,7 +91,7 @@ namespace xAiApi.Providers
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async IAsyncEnumerable<string> AskAsEnumerable(
|
||||
public virtual async IAsyncEnumerable<string> AskTextAsEnumerable(
|
||||
string prompt,
|
||||
[EnumeratorCancellation]
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -117,7 +113,6 @@ namespace xAiApi.Providers
|
||||
);
|
||||
|
||||
//
|
||||
var result = "";
|
||||
await foreach (var res in enumerable)
|
||||
{
|
||||
//
|
||||
@@ -128,15 +123,8 @@ namespace xAiApi.Providers
|
||||
}
|
||||
|
||||
//
|
||||
result += res.Text;
|
||||
yield return res.Text;
|
||||
}
|
||||
|
||||
//
|
||||
// Dispose Client ...
|
||||
client.Dispose();
|
||||
|
||||
//
|
||||
yield return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -172,6 +160,7 @@ namespace xAiApi.Providers
|
||||
var ollamaClient = new OllamaApiClient(httpClient, model);
|
||||
result =
|
||||
new ChatClientBuilder(ollamaClient)
|
||||
.UseFunctionInvocation()
|
||||
.Build();
|
||||
break;
|
||||
|
||||
@@ -188,9 +177,12 @@ namespace xAiApi.Providers
|
||||
}
|
||||
);
|
||||
result =
|
||||
openAiClient
|
||||
.GetChatClient(model)
|
||||
.AsIChatClient();
|
||||
new ChatClientBuilder(
|
||||
openAiClient
|
||||
.GetChatClient(model)
|
||||
.AsIChatClient())
|
||||
.UseFunctionInvocation()
|
||||
.Build();
|
||||
break;
|
||||
|
||||
//
|
||||
@@ -206,29 +198,6 @@ namespace xAiApi.Providers
|
||||
break;
|
||||
}
|
||||
|
||||
// //
|
||||
// if (isOllamaBased)
|
||||
// {
|
||||
// }
|
||||
// else if (isDeepSeekBased)
|
||||
// {
|
||||
// //
|
||||
// if (apiKey is null ||
|
||||
// string.IsNullOrWhiteSpace(apiKey))
|
||||
// {
|
||||
// throw new Exception("Inavlid Args ...");
|
||||
// }
|
||||
|
||||
// //
|
||||
// var deepseekClient = new DeepSeekChatClient(apiKey: apiKey);
|
||||
// result = deepseekClient;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// // TODO: Implement this ...
|
||||
// }
|
||||
|
||||
//
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
@@ -330,7 +299,7 @@ namespace xAiApi.Providers
|
||||
// Preparing Introduction Prompt ...
|
||||
var introductionPrompt = new ChatMessage(
|
||||
ChatRole.System,
|
||||
configuration.GetPrompt()
|
||||
configuration.GetPrompt(XAiApiConstants.XAiApiIntroductionPromptName)
|
||||
);
|
||||
|
||||
//
|
||||
@@ -339,7 +308,7 @@ namespace xAiApi.Providers
|
||||
introductionPrompt,
|
||||
];
|
||||
if (forceMessage &&
|
||||
message is not null)
|
||||
!message.IsNullOrDefault())
|
||||
{
|
||||
result.Add(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user