MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Execute

Method Execute

internal/runtime/executor/kimi_executor.go:75–182  ·  view source on GitHub ↗

Execute performs a non-streaming chat completion request to Kimi.

(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options)

Source from the content-addressed store, hash-verified

73
74// Execute performs a non-streaming chat completion request to Kimi.
75func (e *KimiExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) {
76 from := opts.SourceFormat
77 if from.String() == "claude" {
78 auth.Attributes["base_url"] = kimiauth.KimiAPIBaseURL
79 return e.ClaudeExecutor.Execute(ctx, auth, req, opts)
80 }
81 responseFormat := cliproxyexecutor.ResponseFormatOrSource(opts)
82
83 baseModel := thinking.ParseSuffix(req.Model).ModelName
84
85 token := kimiCreds(auth)
86
87 reporter := helps.NewExecutorUsageReporter(ctx, e, baseModel, auth)
88 defer reporter.TrackFailure(ctx, &err)
89
90 to := sdktranslator.FromString("openai")
91 originalPayloadSource := req.Payload
92 if len(opts.OriginalRequest) > 0 {
93 originalPayloadSource = opts.OriginalRequest
94 }
95 originalPayload := bytes.Clone(originalPayloadSource)
96 originalTranslated := sdktranslator.TranslateRequest(from, to, baseModel, originalPayload, false)
97 body := sdktranslator.TranslateRequest(from, to, baseModel, bytes.Clone(req.Payload), false)
98
99 // Strip kimi- prefix for upstream API
100 upstreamModel := stripKimiPrefix(baseModel)
101 body, err = sjson.SetBytes(body, "model", upstreamModel)
102 if err != nil {
103 return resp, fmt.Errorf("kimi executor: failed to set model in payload: %w", err)
104 }
105
106 body, err = thinking.ApplyThinking(body, req.Model, from.String(), "kimi", e.Identifier())
107 if err != nil {
108 return resp, err
109 }
110
111 requestedModel := helps.PayloadRequestedModel(opts, req.Model)
112 requestPath := helps.PayloadRequestPath(opts)
113 body = helps.ApplyPayloadConfigWithRequest(e.cfg, baseModel, to.String(), from.String(), "", body, originalTranslated, requestedModel, requestPath, opts.Headers)
114 body, err = normalizeKimiToolMessageLinks(body)
115 if err != nil {
116 return resp, err
117 }
118 reporter.SetTranslatedReasoningEffort(body, e.Identifier())
119
120 url := kimiauth.KimiAPIBaseURL + "/v1/chat/completions"
121 httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
122 if err != nil {
123 return resp, err
124 }
125 applyKimiHeadersWithAuth(httpReq, token, false, auth)
126 var attrs map[string]string
127 if auth != nil {
128 attrs = auth.Attributes
129 }
130 util.ApplyCustomHeadersFromAttrs(httpReq, attrs)
131 var authID, authLabel, authType, authValue string
132 if auth != nil {

Callers

nothing calls this directly

Calls 15

IdentifierMethod · 0.95
ParseSuffixFunction · 0.92
NewExecutorUsageReporterFunction · 0.92
ApplyThinkingFunction · 0.92
PayloadRequestedModelFunction · 0.92
PayloadRequestPathFunction · 0.92
RecordAPIRequestFunction · 0.92
NewProxyAwareHTTPClientFunction · 0.92
RecordAPIResponseErrorFunction · 0.92

Tested by

no test coverage detected