tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
3.75k stars 521 forks source link

fix: handle nil pointer exception in chat_prompt_template #879

Closed ankitraj2330 closed 2 weeks ago

ankitraj2330 commented 3 weeks ago

There may be situation where promptValue is nil which will cause panic while accessing promptValue.Messages()

func (p ChatPromptTemplate) FormatMessages(values map[string]any) ([]llms.ChatMessage, error) {
    promptValue, err := p.FormatPrompt(values)
    if promptValue == nil {
        return nil, err
    }
    return promptValue.Messages(), err
}

PR Checklist

ankitraj2330 commented 3 weeks ago

@tmc Can you please review this small bug fix. Thank you!