1
- using BotSharp . Abstraction . Agents . Models ;
2
1
using BotSharp . Abstraction . MLTasks ;
3
2
using BotSharp . Abstraction . MLTasks . Settings ;
4
3
@@ -11,31 +10,25 @@ public static object GetCompletion(IServiceProvider services,
11
10
string ? model = null ,
12
11
AgentLlmConfig ? agentConfig = null )
13
12
{
14
- var state = services . GetRequiredService < IConversationStateService > ( ) ;
15
- var agentSetting = services . GetRequiredService < AgentSettings > ( ) ;
16
-
17
- if ( string . IsNullOrEmpty ( provider ) )
18
- {
19
- provider = agentConfig ? . Provider ?? agentSetting . LlmConfig ? . Provider ;
20
- provider = state . GetState ( "provider" , provider ?? "azure-openai" ) ;
21
- }
13
+ var settingsService = services . GetRequiredService < ILlmProviderService > ( ) ;
22
14
23
- if ( string . IsNullOrEmpty ( model ) )
24
- {
25
- model = agentConfig ? . Model ?? agentSetting . LlmConfig ? . Model ;
26
- model = state . GetState ( "model" , model ?? "gpt-35-turbo-4k" ) ;
27
- }
15
+ ( provider , model ) = GetProviderAndModel ( services , provider : provider , model : model , agentConfig : agentConfig ) ;
28
16
29
- var settingsService = services . GetRequiredService < ILlmProviderService > ( ) ;
30
17
var settings = settingsService . GetSetting ( provider , model ) ;
31
18
32
19
if ( settings . Type == LlmModelType . Text )
33
20
{
34
- return GetTextCompletion ( services , provider : provider , model : model ) ;
21
+ return GetTextCompletion ( services ,
22
+ provider : provider ,
23
+ model : model ,
24
+ agentConfig : agentConfig ) ;
35
25
}
36
26
else
37
27
{
38
- return GetChatCompletion ( services , provider : provider , model : model ) ;
28
+ return GetChatCompletion ( services ,
29
+ provider : provider ,
30
+ model : model ,
31
+ agentConfig : agentConfig ) ;
39
32
}
40
33
}
41
34
@@ -45,20 +38,7 @@ public static IChatCompletion GetChatCompletion(IServiceProvider services,
45
38
AgentLlmConfig ? agentConfig = null )
46
39
{
47
40
var completions = services . GetServices < IChatCompletion > ( ) ;
48
- var agentSetting = services . GetRequiredService < AgentSettings > ( ) ;
49
- var state = services . GetRequiredService < IConversationStateService > ( ) ;
50
-
51
- if ( string . IsNullOrEmpty ( provider ) )
52
- {
53
- provider = agentConfig ? . Provider ?? agentSetting . LlmConfig ? . Provider ;
54
- provider = state . GetState ( "provider" , provider ?? "azure-openai" ) ;
55
- }
56
-
57
- if ( string . IsNullOrEmpty ( model ) )
58
- {
59
- model = agentConfig ? . Model ?? agentSetting . LlmConfig ? . Model ;
60
- model = state . GetState ( "model" , model ?? "gpt-35-turbo-4k" ) ;
61
- }
41
+ ( provider , model ) = GetProviderAndModel ( services , provider : provider , model : model , agentConfig : agentConfig ) ;
62
42
63
43
var completer = completions . FirstOrDefault ( x => x . Provider == provider ) ;
64
44
if ( completer == null )
@@ -72,12 +52,11 @@ public static IChatCompletion GetChatCompletion(IServiceProvider services,
72
52
return completer ;
73
53
}
74
54
75
- public static ITextCompletion GetTextCompletion ( IServiceProvider services ,
76
- string ? provider = null ,
55
+ private static ( string , string ) GetProviderAndModel ( IServiceProvider services ,
56
+ string ? provider = null ,
77
57
string ? model = null ,
78
58
AgentLlmConfig ? agentConfig = null )
79
59
{
80
- var completions = services . GetServices < ITextCompletion > ( ) ;
81
60
var agentSetting = services . GetRequiredService < AgentSettings > ( ) ;
82
61
var state = services . GetRequiredService < IConversationStateService > ( ) ;
83
62
@@ -90,9 +69,32 @@ public static ITextCompletion GetTextCompletion(IServiceProvider services,
90
69
if ( string . IsNullOrEmpty ( model ) )
91
70
{
92
71
model = agentConfig ? . Model ?? agentSetting . LlmConfig ? . Model ;
93
- model = state . GetState ( "model" , model ?? "gpt-35-turbo-instruct" ) ;
72
+ if ( state . ContainsState ( "model" ) )
73
+ {
74
+ model = state . GetState ( "model" , model ?? "gpt-35-turbo-4k" ) ;
75
+ }
76
+ else if ( state . ContainsState ( "model_id" ) )
77
+ {
78
+ var modelId = state . GetState ( "model_id" ) ;
79
+ var llmProviderService = services . GetRequiredService < ILlmProviderService > ( ) ;
80
+ model = llmProviderService . GetProviderModel ( provider , modelId ) ? . Name ;
81
+ }
94
82
}
95
83
84
+ state . SetState ( "provider" , provider ) ;
85
+ state . SetState ( "model" , model ) ;
86
+
87
+ return ( provider , model ) ;
88
+ }
89
+ public static ITextCompletion GetTextCompletion ( IServiceProvider services ,
90
+ string ? provider = null ,
91
+ string ? model = null ,
92
+ AgentLlmConfig ? agentConfig = null )
93
+ {
94
+ var completions = services . GetServices < ITextCompletion > ( ) ;
95
+
96
+ ( provider , model ) = GetProviderAndModel ( services , provider : provider , model : model , agentConfig : agentConfig ) ;
97
+
96
98
var completer = completions . FirstOrDefault ( x => x . Provider == provider ) ;
97
99
if ( completer == null )
98
100
{
0 commit comments