@@ -2,12 +2,14 @@ package chat
22
33import (
44 "context"
5+ "fmt"
56 "paperdebugger/internal/api/mapper"
67 "paperdebugger/internal/libs/contextutil"
78 "paperdebugger/internal/libs/shared"
89 "paperdebugger/internal/models"
910 "paperdebugger/internal/services"
1011 chatv2 "paperdebugger/pkg/gen/api/chat/v2"
12+ "strings"
1113
1214 "github.com/google/uuid"
1315 "github.com/openai/openai-go/v3"
@@ -276,13 +278,38 @@ func (s *ChatServerV2) CreateConversationMessageStream(
276278 return s .sendStreamError (stream , err )
277279 }
278280
281+ // Check if user has an API key for requested model
282+ var customModel * models.CustomModel
283+ customModel = nil
284+ for _ , m := range settings .CustomModels {
285+ if m .Slug == modelSlug {
286+ customModel = & m
287+ break
288+ }
289+ }
290+
279291 // Usage is the same as ChatCompletion, just passing the stream parameter
280- llmProvider := & models.LLMProviderConfig {
281- APIKey : settings .OpenAIAPIKey ,
292+ var llmProvider * models.LLMProviderConfig
293+ if customModel == nil {
294+ // User did not specify API key for this model
295+ llmProvider = & models.LLMProviderConfig {
296+ APIKey : settings .OpenAIAPIKey ,
297+ }
298+ } else {
299+ modelSlug = modelSlug [strings .Index (modelSlug , "/" )+ 1 :]
300+ llmProvider = & models.LLMProviderConfig {
301+ APIKey : customModel .APIKey ,
302+ Endpoint : customModel .BaseUrl ,
303+ }
282304 }
283305
306+ fmt .Println (modelSlug )
307+ fmt .Println (llmProvider .Endpoint )
308+ fmt .Println (llmProvider .APIKey )
309+ fmt .Println ("************************" )
284310 openaiChatHistory , inappChatHistory , err := s .aiClientV2 .ChatCompletionStreamV2 (ctx , stream , conversation .ID .Hex (), modelSlug , conversation .OpenaiChatHistoryCompletion , llmProvider )
285311 if err != nil {
312+ fmt .Println (err )
286313 return s .sendStreamError (stream , err )
287314 }
288315
0 commit comments