|
| 1 | +package openresponses |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/mudler/LocalAI/core/config" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo/v2" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | +) |
| 9 | + |
| 10 | +// Regression for mudler/LocalAI#10039. convertORInputToMessages must populate |
| 11 | +// both Content and StringContent: the templating fallback path reads |
| 12 | +// StringContent, while the UseTokenizerTemplate path serialises Content via |
| 13 | +// Messages.ToProto(). Leaving Content nil produced an empty prompt on any model |
| 14 | +// without a Go-side template.chat_message block (the default for imported GGUFs). |
| 15 | +var _ = Describe("convertORInputToMessages", func() { |
| 16 | + cfg := &config.ModelConfig{} |
| 17 | + |
| 18 | + It("populates both Content and StringContent for plain string input", func() { |
| 19 | + msgs, err := convertORInputToMessages("Hello", cfg) |
| 20 | + Expect(err).NotTo(HaveOccurred()) |
| 21 | + Expect(msgs).To(HaveLen(1)) |
| 22 | + Expect(msgs[0].Role).To(Equal("user")) |
| 23 | + Expect(msgs[0].StringContent).To(Equal("Hello")) |
| 24 | + Expect(msgs[0].Content).To(Equal("Hello")) |
| 25 | + }) |
| 26 | + |
| 27 | + It("accepts a bare {role, content} item without a type discriminator", func() { |
| 28 | + // The OpenAI Python SDK helper client.responses.create(input=[{...}]) |
| 29 | + // sends message items with no "type" field. They must not be dropped. |
| 30 | + input := []any{ |
| 31 | + map[string]any{"role": "user", "content": "Hi there"}, |
| 32 | + } |
| 33 | + msgs, err := convertORInputToMessages(input, cfg) |
| 34 | + Expect(err).NotTo(HaveOccurred()) |
| 35 | + Expect(msgs).To(HaveLen(1)) |
| 36 | + Expect(msgs[0].Role).To(Equal("user")) |
| 37 | + Expect(msgs[0].StringContent).To(Equal("Hi there")) |
| 38 | + Expect(msgs[0].Content).To(Equal("Hi there")) |
| 39 | + }) |
| 40 | + |
| 41 | + It("still populates both fields for an explicit type:message item", func() { |
| 42 | + input := []any{ |
| 43 | + map[string]any{"type": "message", "role": "user", "content": "Typed"}, |
| 44 | + } |
| 45 | + msgs, err := convertORInputToMessages(input, cfg) |
| 46 | + Expect(err).NotTo(HaveOccurred()) |
| 47 | + Expect(msgs).To(HaveLen(1)) |
| 48 | + Expect(msgs[0].StringContent).To(Equal("Typed")) |
| 49 | + Expect(msgs[0].Content).To(Equal("Typed")) |
| 50 | + }) |
| 51 | + |
| 52 | + It("does not treat a non-message item (no content key) as a message", func() { |
| 53 | + // An item with neither a known type nor a {role, content} shape must |
| 54 | + // keep falling through unchanged — no behaviour change for such inputs. |
| 55 | + input := []any{ |
| 56 | + map[string]any{"role": "user"}, |
| 57 | + } |
| 58 | + msgs, err := convertORInputToMessages(input, cfg) |
| 59 | + Expect(err).NotTo(HaveOccurred()) |
| 60 | + Expect(msgs).To(BeEmpty()) |
| 61 | + }) |
| 62 | +}) |
0 commit comments