MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / convertAnthropicMessagesToOpenAI

Function convertAnthropicMessagesToOpenAI

api/client.go:1124–1225  ·  view source on GitHub ↗
(messages []map[string]any)

Source from the content-addressed store, hash-verified

1122 defer close(results)
1123 scanner := bufio.NewScanner(body)
1124 scanner.Buffer(make([]byte, 0, 64*1024), 10*1024*1024)
1125 for scanner.Scan() {
1126 line := scanner.Text()
1127 if !strings.HasPrefix(line, "data:") {
1128 continue
1129 }
1130 dataStr := strings.TrimSpace(line[len("data:"):])
1131 if dataStr == "" {
1132 continue
1133 }
1134 select {
1135 case results <- sseScanResult{data: dataStr}:
1136 case <-scanCtx.Done():
1137 return
1138 }
1139 }
1140 if err := scanner.Err(); err != nil {
1141 select {
1142 case results <- sseScanResult{err: err}:
1143 case <-scanCtx.Done():
1144 }
1145 }
1146 }()
1147
1148 timer := time.NewTimer(idleTimeout)
1149 defer timer.Stop()
1150 for {
1151 select {
1152 case <-ctx.Done():
1153 _ = body.Close()
1154 return ctx.Err()
1155 case item, ok := <-results:
1156 if !ok {
1157 return nil
1158 }
1159 if !timer.Stop() {
1160 select {
1161 case <-timer.C:
1162 default:
1163 }
1164 }
1165 timer.Reset(idleTimeout)
1166 if item.err != nil {
1167 return item.err
1168 }
1169 if !handle(item.data) {
1170 return nil
1171 }
1172 case <-timer.C:
1173 _ = body.Close()
1174 return StreamIdleTimeoutError{Timeout: idleTimeout}
1175 }
1176 }
1177}
1178
1179func singleErrorEvent(err error) <-chan EventResult {
1180 ch := make(chan EventResult, 1)
1181 ch <- EventResult{Err: err}

Callers 1

buildMessagesMethod · 0.85

Calls 6

getStringDefaultFunction · 0.85
normalizeContentBlocksFunction · 0.85
splitAnthropicBlocksFunction · 0.85
getStringFunction · 0.85
consumeToolResultCarrierFunction · 0.85
fallbackToolMessageFunction · 0.85

Tested by

no test coverage detected