@@ -33,7 +33,26 @@ actor BuiltinExtensionChatCompletionsService {
3333
3434extension BuiltinExtensionChatCompletionsService : ChatCompletionsAPI {
3535 func callAsFunction( ) async throws -> ChatCompletionResponseBody {
36- fatalError ( )
36+ let stream : AsyncThrowingStream < ChatCompletionsStreamDataChunk , Error > =
37+ try await callAsFunction ( )
38+
39+ var id : String ? = nil
40+ var model = " "
41+ var content = " "
42+ for try await chunk in stream {
43+ if let chunkId = chunk. id { id = chunkId }
44+ if model. isEmpty, let chunkModel = chunk. model { model = chunkModel }
45+ content. append ( chunk. message? . content ?? " " )
46+ }
47+
48+ return . init(
49+ id: id,
50+ object: " " ,
51+ model: model,
52+ message: . init( role: . assistant, content: content) ,
53+ otherChoices: [ ] ,
54+ finishReason: " "
55+ )
3756 }
3857}
3958
@@ -42,8 +61,8 @@ extension BuiltinExtensionChatCompletionsService: ChatCompletionsStreamAPI {
4261 ) async throws -> AsyncThrowingStream < ChatCompletionsStreamDataChunk , Error > {
4362 let service = try getChatService ( )
4463 let ( message, history) = extractMessageAndHistory ( from: requestBody)
45- guard let workspaceURL = XcodeInspector . shared. realtimeActiveWorkspaceURL,
46- let projectURL = XcodeInspector . shared. realtimeActiveProjectURL
64+ guard let workspaceURL = await XcodeInspector . shared. safe . realtimeActiveWorkspaceURL,
65+ let projectURL = await XcodeInspector . shared. safe . realtimeActiveProjectURL
4766 else { throw CancellationError ( ) }
4867 let stream = await service. sendMessage (
4968 message,
@@ -54,12 +73,12 @@ extension BuiltinExtensionChatCompletionsService: ChatCompletionsStreamAPI {
5473 projectURL: projectURL
5574 )
5675 )
57-
76+ let responseID = UUID ( ) . uuidString
5877 return stream. map { text in
5978 ChatCompletionsStreamDataChunk (
60- id: nil ,
79+ id: responseID ,
6180 object: nil ,
62- model: nil ,
81+ model: " github-copilot " ,
6382 message: . init(
6483 role: . assistant,
6584 content: text,
0 commit comments