MCPcopy Index your code
hub / github.com/coder/coder / OpenAITextChunks

Function OpenAITextChunks

coderd/x/chatd/chattest/openai.go:874–899  ·  view source on GitHub ↗

OpenAITextChunks creates streaming chunks with text deltas. Each delta string becomes a separate chunk with a single choice. Returns a slice of chunks, one per delta, with each choice having its index (0, 1, 2, ...).

(deltas ...string)

Source from the content-addressed store, hash-verified

872// Each delta string becomes a separate chunk with a single choice.
873// Returns a slice of chunks, one per delta, with each choice having its index (0, 1, 2, ...).
874func OpenAITextChunks(deltas ...string) []OpenAIChunk {
875 if len(deltas) == 0 {
876 return nil
877 }
878
879 chunkID := fmt.Sprintf("chatcmpl-%s", uuid.New().String()[:8])
880 now := time.Now().Unix()
881 chunks := make([]OpenAIChunk, len(deltas))
882
883 for i, delta := range deltas {
884 chunks[i] = OpenAIChunk{
885 ID: chunkID,
886 Object: "chat.completion.chunk",
887 Created: now,
888 Model: "gpt-4",
889 Choices: []OpenAIChunkChoice{
890 {
891 Index: i,
892 Delta: delta,
893 },
894 },
895 }
896 }
897
898 return chunks
899}
900
901// OpenAIToolCallChunk creates a streaming chunk with a tool call.
902// Takes the tool name and arguments JSON string, creates a tool call for choice index 0.

Calls 2

NewMethod · 0.65
StringMethod · 0.45