Skip to content

Commit 38ec098

Browse files
Improved the OpenAI provider (#548)
1 parent 4e167d5 commit 38ec098

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1107
-211
lines changed

app/MindWork AI Studio/Agents/AgentBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager setti
7373
WorkspaceId = Guid.Empty,
7474
ChatId = Guid.NewGuid(),
7575
Name = string.Empty,
76-
Seed = this.RNG.Next(),
7776
SystemPrompt = systemPrompt,
7877
Blocks = [],
7978
};

app/MindWork AI Studio/Assistants/AssistantBase.razor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
2020

2121
[Inject]
2222
protected IJSRuntime JsRuntime { get; init; } = null!;
23-
24-
[Inject]
25-
protected ThreadSafeRandom RNG { get; init; } = null!;
2623

2724
[Inject]
2825
protected ISnackbar Snackbar { get; init; } = null!;
@@ -199,7 +196,6 @@ protected void CreateChatThread()
199196
WorkspaceId = Guid.Empty,
200197
ChatId = Guid.NewGuid(),
201198
Name = string.Format(this.TB("Assistant - {0}"), this.Title),
202-
Seed = this.RNG.Next(),
203199
Blocks = [],
204200
};
205201
}
@@ -215,7 +211,6 @@ protected Guid CreateChatThread(Guid workspaceId, string name)
215211
WorkspaceId = workspaceId,
216212
ChatId = chatId,
217213
Name = name,
218-
Seed = this.RNG.Next(),
219214
Blocks = [],
220215
};
221216

app/MindWork AI Studio/Chat/ChatThread.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ public sealed record ChatThread
5959
/// The name of the chat thread. Usually generated by an AI model or manually edited by the user.
6060
/// </summary>
6161
public string Name { get; set; } = string.Empty;
62-
63-
/// <summary>
64-
/// The seed for the chat thread. Some providers use this to generate deterministic results.
65-
/// </summary>
66-
public int Seed { get; init; }
6762

6863
/// <summary>
6964
/// The current system prompt for the chat thread.

app/MindWork AI Studio/Components/ChatComponent.razor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
3434
[Inject]
3535
private ILogger<ChatComponent> Logger { get; set; } = null!;
3636

37-
[Inject]
38-
private ThreadSafeRandom RNG { get; init; } = null!;
39-
4037
[Inject]
4138
private IDialogService DialogService { get; init; } = null!;
4239

@@ -436,7 +433,6 @@ private async Task SendMessage(bool reuseLastUserPrompt = false)
436433
ChatId = Guid.NewGuid(),
437434
DataSourceOptions = this.earlyDataSourceOptions,
438435
Name = this.ExtractThreadName(this.userInput),
439-
Seed = this.RNG.Next(),
440436
Blocks = this.currentChatTemplate == ChatTemplate.NO_CHAT_TEMPLATE ? [] : this.currentChatTemplate.ExampleConversation.Select(x => x.DeepClone()).ToList(),
441437
};
442438

@@ -674,7 +670,6 @@ private async Task StartNewChat(bool useSameWorkspace = false, bool deletePrevio
674670
WorkspaceId = this.currentWorkspaceId,
675671
ChatId = Guid.NewGuid(),
676672
Name = string.Empty,
677-
Seed = this.RNG.Next(),
678673
Blocks = this.currentChatTemplate == ChatTemplate.NO_CHAT_TEMPLATE ? [] : this.currentChatTemplate.ExampleConversation.Select(x => x.DeepClone()).ToList(),
679674
};
680675
}

app/MindWork AI Studio/Components/Workspaces.razor.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public partial class Workspaces : MSGComponentBase
1616
[Inject]
1717
private IDialogService DialogService { get; init; } = null!;
1818

19-
[Inject]
20-
private ThreadSafeRandom RNG { get; init; } = null!;
21-
2219
[Inject]
2320
private ILogger<Workspaces> Logger { get; init; } = null!;
2421

@@ -576,7 +573,6 @@ private async Task AddChat(string workspacePath)
576573
WorkspaceId = workspaceId,
577574
ChatId = Guid.NewGuid(),
578575
Name = string.Empty,
579-
Seed = this.RNG.Next(),
580576
SystemPrompt = SystemPrompts.DEFAULT,
581577
Blocks = [],
582578
};

app/MindWork AI Studio/Pages/Writer.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ private async Task GetSuggestions()
7777
WorkspaceId = Guid.Empty,
7878
ChatId = Guid.NewGuid(),
7979
Name = string.Empty,
80-
Seed = 798798,
8180
SystemPrompt = """
8281
You are an assistant who helps with writing documents. You receive a sample
8382
from a document as input. As output, you provide how the begun sentence could

app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(
3636
};
3737

3838
// Prepare the AlibabaCloud HTTP chat request:
39-
var alibabaCloudChatRequest = JsonSerializer.Serialize(new ChatRequest
39+
var alibabaCloudChatRequest = JsonSerializer.Serialize(new ChatCompletionAPIRequest
4040
{
4141
Model = chatModel.Id,
4242

@@ -77,7 +77,7 @@ async Task<HttpRequestMessage> RequestBuilder()
7777
return request;
7878
}
7979

80-
await foreach (var content in this.StreamChatCompletionInternal<ResponseStreamLine>("AlibabaCloud", RequestBuilder, token))
80+
await foreach (var content in this.StreamChatCompletionInternal<ChatCompletionDeltaStreamLine, NoChatCompletionAnnotationStreamLine>("AlibabaCloud", RequestBuilder, token))
8181
yield return content;
8282
}
8383

@@ -156,7 +156,9 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
156156
Capability.AUDIO_INPUT, Capability.SPEECH_INPUT,
157157
Capability.VIDEO_INPUT,
158158

159-
Capability.TEXT_OUTPUT, Capability.SPEECH_OUTPUT
159+
Capability.TEXT_OUTPUT, Capability.SPEECH_OUTPUT,
160+
161+
Capability.CHAT_COMPLETION_API,
160162
];
161163

162164
// Check for Qwen 3:
@@ -166,14 +168,17 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
166168
Capability.TEXT_INPUT,
167169
Capability.TEXT_OUTPUT,
168170

169-
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING
171+
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
172+
Capability.CHAT_COMPLETION_API,
170173
];
171174

172175
if(modelName.IndexOf("-vl-") is not -1)
173176
return
174177
[
175178
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
176179
Capability.TEXT_OUTPUT,
180+
181+
Capability.CHAT_COMPLETION_API,
177182
];
178183
}
179184

@@ -185,7 +190,8 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
185190
Capability.TEXT_INPUT,
186191
Capability.TEXT_OUTPUT,
187192

188-
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING
193+
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
194+
Capability.CHAT_COMPLETION_API,
189195
];
190196
}
191197

@@ -197,7 +203,8 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
197203
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
198204
Capability.TEXT_OUTPUT,
199205

200-
Capability.ALWAYS_REASONING
206+
Capability.ALWAYS_REASONING,
207+
Capability.CHAT_COMPLETION_API,
201208
];
202209
}
203210

@@ -207,7 +214,8 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
207214
Capability.TEXT_INPUT,
208215
Capability.TEXT_OUTPUT,
209216

210-
Capability.FUNCTION_CALLING
217+
Capability.FUNCTION_CALLING,
218+
Capability.CHAT_COMPLETION_API,
211219
];
212220
}
213221

app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async Task<HttpRequestMessage> RequestBuilder()
7272
return request;
7373
}
7474

75-
await foreach (var content in this.StreamChatCompletionInternal<ResponseStreamLine>("Anthropic", RequestBuilder, token))
75+
await foreach (var content in this.StreamChatCompletionInternal<ResponseStreamLine, NoChatCompletionAnnotationStreamLine>("Anthropic", RequestBuilder, token))
7676
yield return content;
7777
}
7878

@@ -122,29 +122,37 @@ public override IReadOnlyCollection<Capability> GetModelCapabilities(Model model
122122
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
123123
Capability.TEXT_OUTPUT,
124124

125-
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING];
125+
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
126+
Capability.CHAT_COMPLETION_API,
127+
];
126128

127129
// Claude 3.7 is able to do reasoning:
128130
if(modelName.StartsWith("claude-3-7"))
129131
return [
130132
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
131133
Capability.TEXT_OUTPUT,
132134

133-
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING];
135+
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
136+
Capability.CHAT_COMPLETION_API,
137+
];
134138

135139
// All other 3.x models are able to process text and images as input:
136140
if(modelName.StartsWith("claude-3-"))
137141
return [
138142
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
139143
Capability.TEXT_OUTPUT,
140144

141-
Capability.FUNCTION_CALLING];
145+
Capability.FUNCTION_CALLING,
146+
Capability.CHAT_COMPLETION_API,
147+
];
142148

143149
// Any other model is able to process text only:
144150
return [
145151
Capability.TEXT_INPUT,
146152
Capability.TEXT_OUTPUT,
147-
Capability.FUNCTION_CALLING];
153+
Capability.FUNCTION_CALLING,
154+
Capability.CHAT_COMPLETION_API,
155+
];
148156
}
149157

150158
#endregion

app/MindWork AI Studio/Provider/Anthropic/ResponseStreamLine.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ public readonly record struct ResponseStreamLine(string Type, int Index, Delta D
1414

1515
/// <inheritdoc />
1616
public ContentStreamChunk GetContent() => new(this.Delta.Text, []);
17+
18+
#region Implementation of IAnnotationStreamLine
19+
20+
//
21+
// Please note: Anthropic's API does not currently support sources in their
22+
// OpenAI-compatible response stream.
23+
//
24+
25+
/// <inheritdoc />
26+
public bool ContainsSources() => false;
27+
28+
/// <inheritdoc />
29+
public IList<ISource> GetSources() => [];
30+
31+
#endregion
1732
}
1833

1934
/// <summary>

0 commit comments

Comments
 (0)