Skip to content

Commit 4932939

Browse files
committed
refactor: implement fix in NewAIClientV2 and getDefaultParamsV2 only
1 parent 6d5b389 commit 4932939

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

internal/services/toolkit/client/client_v2.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,23 @@ func NewAIClientV2(
7070

7171
var baseUrl string
7272
var apiKey string
73+
var modelSlug string
74+
7375
if llmProvider != nil && llmProvider.IsCustom() {
74-
baseUrl = cfg.InferenceBaseURL + "/openai"
76+
baseUrl = cfg.OpenAIBaseURL
7577
apiKey = cfg.OpenAIAPIKey
78+
modelSlug = "gpt-5-nano"
7679
} else {
7780
baseUrl = cfg.InferenceBaseURL + "/openrouter"
7881
apiKey = cfg.InferenceAPIKey
82+
modelSlug = "openai/gpt-5-nano"
7983
}
8084

8185
oaiClient := openai.NewClient(
8286
option.WithBaseURL(baseUrl),
8387
option.WithAPIKey(apiKey),
8488
)
85-
CheckOpenAIWorksV2(oaiClient, llmProvider, logger)
89+
CheckOpenAIWorksV2(oaiClient, baseUrl, modelSlug, logger)
8690

8791
toolRegistry := initializeToolkitV2(db, projectService, cfg, logger)
8892
toolCallHandler := handler.NewToolCallHandlerV2(toolRegistry)

internal/services/toolkit/client/completion_v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func (a *AIClientV2) ChatCompletionStreamV2(ctx context.Context, callbackStream
6565
}()
6666

6767
oaiClient := a.GetOpenAIClient(llmProvider)
68-
params := getDefaultParamsV2(modelSlug, a.toolCallHandler.Registry)
68+
var isCustomModel bool = llmProvider != nil && llmProvider.IsCustom()
69+
params := getDefaultParamsV2(modelSlug, a.toolCallHandler.Registry, isCustomModel)
6970

7071
for {
7172
params.Messages = openaiChatHistory

internal/services/toolkit/client/utils_v2.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ This file contains utility functions for the client package. (Mainly miscellaneo
66
It is used to append assistant responses to both OpenAI and in-app chat histories, and to create response items for chat interactions.
77
*/
88
import (
9+
"path"
910
"context"
1011
"fmt"
1112
"paperdebugger/internal/libs/cfg"
1213
"paperdebugger/internal/libs/db"
1314
"paperdebugger/internal/libs/logger"
1415
"paperdebugger/internal/services"
15-
"paperdebugger/internal/models"
1616
"paperdebugger/internal/services/toolkit/registry"
1717
"paperdebugger/internal/services/toolkit/tools/xtramcp"
1818
chatv2 "paperdebugger/pkg/gen/api/chat/v2"
@@ -53,7 +53,12 @@ func appendAssistantTextResponseV2(openaiChatHistory *OpenAIChatHistory, inappCh
5353
})
5454
}
5555

56-
func getDefaultParamsV2(modelSlug string, toolRegistry *registry.ToolRegistryV2) openaiv3.ChatCompletionNewParams {
56+
func getDefaultParamsV2(modelSlug string, toolRegistry *registry.ToolRegistryV2, isCustomModel bool) openaiv3.ChatCompletionNewParams {
57+
// If custom model is used, strip prefix (eg "openai/gpt-4o" -> "gpt-4o")
58+
if isCustomModel {
59+
modelSlug = path.Base(modelSlug)
60+
}
61+
5762
var reasoningModels = []string{
5863
"gpt-5",
5964
"gpt-5-mini",
@@ -88,14 +93,8 @@ func getDefaultParamsV2(modelSlug string, toolRegistry *registry.ToolRegistryV2)
8893
}
8994
}
9095

91-
func CheckOpenAIWorksV2(oaiClient openaiv3.Client, llmProvider *models.LLMProviderConfig, logger *logger.Logger) {
92-
logger.Info("[AI Client V2] checking if openai client works")
93-
94-
var model = "openai/gpt-5-nano"
95-
if llmProvider != nil && llmProvider.IsCustom() {
96-
model = model[strings.LastIndex(model, "/")+1:]
97-
}
98-
96+
func CheckOpenAIWorksV2(oaiClient openaiv3.Client, baseUrl string, model string, logger *logger.Logger) {
97+
logger.Info("[AI Client V2] checking if openai client works with " + baseUrl + "..")
9998
chatCompletion, err := oaiClient.Chat.Completions.New(context.TODO(), openaiv3.ChatCompletionNewParams{
10099
Messages: []openaiv3.ChatCompletionMessageParamUnion{
101100
openaiv3.UserMessage("Say 'openai client works'"),

0 commit comments

Comments
 (0)