package llm import "context" // AskPetalMessages assembles the message array for one Ask Petal turn: the // suggestion-context system prompt followed by the (length-capped) client-side // conversation history. The backend is stateless, so the full history rides on // every request (spec: no server-side sessions). func AskPetalMessages(systemPrompt string, history []Message) []Message { msgs := make([]Message, 0, len(history)+1) msgs = append(msgs, Message{Role: "system", Content: systemPrompt}) msgs = append(msgs, TrimHistory(history)...) return msgs } // StreamAskPetal opens an SSE-friendly token stream for an Ask Petal reply using // the conversational sampling parameters from the spec. The caller forwards the // returned chunks to the browser; the channel closes when generation ends. func StreamAskPetal(ctx context.Context, client LLMClient, systemPrompt string, history []Message) (<-chan string, error) { return client.Stream(ctx, CompletionRequest{ Messages: AskPetalMessages(systemPrompt, history), MaxTokens: 512, Temperature: 0.7, RepetitionPenalty: 1.15, TopP: 0.92, Stop: []string{"\n\n\n"}, Stream: true, }) }