Skip to content

Commit c52c4f4

Browse files
committed
Revert "Fixups"
This reverts commit ab1b3d6.
1 parent ab1b3d6 commit c52c4f4

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

core/http/endpoints/openai/mcp.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,20 @@ func MCPCompletionEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader,
7272
fragment = fragment.AddMessage(message.Role, message.StringContent)
7373
}
7474

75-
// Extract port from APIAddress (format: ":8080" or "127.0.0.1:8080" or "0.0.0.0:8080")
76-
port := "8080" // default
77-
if appConfig.APIAddress != "" {
78-
lastColon := strings.LastIndex(appConfig.APIAddress, ":")
79-
if lastColon >= 0 && lastColon+1 < len(appConfig.APIAddress) {
80-
port = appConfig.APIAddress[lastColon+1:]
81-
} else {
82-
log.Warn().Str("APIAddress", appConfig.APIAddress).Msg("[MCP] Could not extract port from APIAddress, using default 8080")
83-
}
84-
}
85-
75+
port := appConfig.APIAddress[strings.LastIndex(appConfig.APIAddress, ":")+1:]
8676
apiKey := ""
87-
if len(appConfig.ApiKeys) > 0 {
77+
if appConfig.ApiKeys != nil {
8878
apiKey = appConfig.ApiKeys[0]
8979
}
9080

91-
baseURL := "http://127.0.0.1:" + port
92-
log.Debug().Str("baseURL", baseURL).Str("model", config.Name).Msg("[MCP] Creating OpenAI LLM client for internal API calls")
93-
9481
ctxWithCancellation, cancel := context.WithCancel(ctx)
9582
defer cancel()
9683
handleConnectionCancellation(c, cancel, ctxWithCancellation)
9784
// TODO: instead of connecting to the API, we should just wire this internally
9885
// and act like completion.go.
9986
// We can do this as cogito expects an interface and we can create one that
10087
// we satisfy to just call internally ComputeChoices
101-
defaultLLM := cogito.NewOpenAILLM(config.Name, apiKey, baseURL)
88+
defaultLLM := cogito.NewOpenAILLM(config.Name, apiKey, "http://127.0.0.1:"+port)
10289

10390
cogitoOpts := []cogito.Option{
10491
cogito.WithStatusCallback(func(s string) {
@@ -140,8 +127,7 @@ func MCPCompletionEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader,
140127
cogitoOpts...,
141128
)
142129
if err != nil && !errors.Is(err, cogito.ErrNoToolSelected) {
143-
log.Error().Err(err).Msgf("[MCP] ExecuteTools failed for model %s", config.Name)
144-
return fmt.Errorf("failed to execute tools: %w", err)
130+
return err
145131
}
146132

147133
f, err = defaultLLM.Ask(ctx, f)

core/http/static/chat.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -435,28 +435,9 @@ async function promptGPT(systemPrompt, input) {
435435
}
436436

437437
if (!response.ok) {
438-
// Try to get error details from response body
439-
let errorMessage = `Error: POST ${endpoint} ${response.status}`;
440-
try {
441-
const errorData = await response.json();
442-
if (errorData && errorData.error && errorData.error.message) {
443-
errorMessage = `Error (${response.status}): ${errorData.error.message}`;
444-
}
445-
} catch (e) {
446-
// If response is not JSON, try to get text
447-
try {
448-
const errorText = await response.text();
449-
if (errorText) {
450-
errorMessage = `Error (${response.status}): ${errorText.substring(0, 200)}`;
451-
}
452-
} catch (e2) {
453-
// Ignore - use default error message
454-
}
455-
}
456-
457438
Alpine.store("chat").add(
458439
"assistant",
459-
`<span class='error'>${errorMessage}</span>`,
440+
`<span class='error'>Error: POST ${endpoint} ${response.status}</span>`,
460441
);
461442
toggleLoader(false);
462443
currentAbortController = null;

0 commit comments

Comments
 (0)