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

Method StreamChat

api/client.go:324–394  ·  view source on GitHub ↗
(
	ctx context.Context,
	systemPrompt string,
	messages []map[string]any,
	tools []map[string]any,
	options *LLMRequestOptions,
)

Source from the content-addressed store, hash-verified

322 }
323
324 return false
325}
326
327type AnthropicClient struct {
328 LLMClientBase
329}
330
331var _ LLMClient = (*AnthropicClient)(nil)
332
333func (c *AnthropicClient) buildHeaders() map[string]string {
334 headers := map[string]string{"anthropic-version": "2023-06-01", "content-type": "application/json"}
335 if isDeepSeekModel(c.Model) || strings.Contains(strings.ToLower(c.BaseURL), "api.deepseek.com") {
336 headers["Authorization"] = "Bearer " + c.APIKey
337 } else {
338 headers["x-api-key"] = c.APIKey
339 }
340 return headers
341}
342
343func (c *AnthropicClient) Complete(
344 ctx context.Context,
345 systemPrompt string,
346 messages []map[string]any,
347 opts CompleteOptions,
348) (string, error) {
349 response, err := collectCompletionStream(c.StreamChat(ctx, systemPrompt, messages, opts.Tools,
350 &LLMRequestOptions{MaxTokens: opts.MaxTokens, Temperature: opts.Temperature}))
351 if err != nil {
352 return "", err
353 }
354 return response.Text, nil
355}
356
357func (c *AnthropicClient) CompleteStructured(
358 ctx context.Context,
359 systemPrompt string,
360 messages []map[string]any,
361 opts StructuredCompletionOptions,
362) (Response, error) {
363 return collectCompletionStream(c.StreamChat(ctx, systemPrompt, messages, opts.Tools, &LLMRequestOptions{
364 MaxTokens: opts.MaxTokens, RequiredTool: opts.RequiredTool, DisableThinking: opts.DisableThinking,
365 Temperature: opts.Temperature,
366 }))
367}
368
369func (c *AnthropicClient) StreamChat(
370 ctx context.Context,
371 systemPrompt string,
372 messages []map[string]any,
373 tools []map[string]any,
374 options *LLMRequestOptions,
375) <-chan EventResult {
376 url := c.BaseURL + "/v1/messages"
377 headers := c.buildHeaders()
378
379 apiTools := make([]map[string]any, 0, len(tools))
380 for _, tool := range tools {
381 parameters, ok := tool["input_schema"]

Callers

nothing calls this directly

Calls 3

getStringFunction · 0.85
singleErrorEventFunction · 0.85
RetryWithBackoffFunction · 0.85

Tested by

no test coverage detected