Repository: ollama/ollama
File: api/types.go (Go)

Code before:
func (e StatusError) Error() string {
	switch {
	case e.Status != "" && e.ErrorMessage != "":
		return fmt.Sprintf("%s: %s", e.Status, e.ErrorMessage)
	case e.Status != "":
		return e.Status
	case e.ErrorMessage != "":
		return e.ErrorMessage
	default:
		// this should not happen
		return "something went wrong, please see the ollama server logs for details"
	}
}

type ImageData []byte

type GenerateRequest struct {
	Model     string      `json:"model"`
	Prompt    string      `json:"prompt"`
	System    string      `json:"system"`
	Template  string      `json:"template"`
	Context   []int       `json:"context,omitempty"`
	Stream    *bool       `json:"stream,omitempty"`
	Raw       bool        `json:"raw,omitempty"`
	Format    string      `json:"format"`
	KeepAlive *Duration   `json:"keep_alive,omitempty"`
	Images    []ImageData `json:"images,omitempty"`

	Options map[string]interface{} `json:"options"`
}

type ChatRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Stream   *bool     `json:"stream,omitempty"`
	Format   string    `json:"format"`

	Options map[string]interface{} `json:"options"`
}

type Message struct {
	Role    string      `json:"role"` // one of ["system", "user", "assistant"]
	Content string      `json:"content"`
	Images  []ImageData `json:"images,omitempty"`
}

type ChatResponse struct {
	Model     string    `json:"model"`
	CreatedAt time.Time `json:"created_at"`
	Message   Message   `json:"message"`


Review comment (suggestion):
This should be on `ChatRequest` and `EmbeddingRequest` too (any routes that use the `load()` function in `routes.go`).

Code after:
func (e StatusError) Error() string {
	switch {
	case e.Status != "" && e.ErrorMessage != "":
		return fmt.Sprintf("%s: %s", e.Status, e.ErrorMessage)
	case e.Status != "":
		return e.Status
	case e.ErrorMessage != "":
		return e.ErrorMessage
	default:
		// this should not happen
		return "something went wrong, please see the ollama server logs for details"
	}
}

type ImageData []byte

type GenerateRequest struct {
	Model     string      `json:"model"`
	Prompt    string      `json:"prompt"`
	System    string      `json:"system"`
	Template  string      `json:"template"`
	Context   []int       `json:"context,omitempty"`
	Stream    *bool       `json:"stream,omitempty"`
	Raw       bool        `json:"raw,omitempty"`
	Format    string      `json:"format"`
	KeepAlive *Duration   `json:"keep_alive,omitempty"`
	Images    []ImageData `json:"images,omitempty"`

	Options map[string]interface{} `json:"options"`
}

type ChatRequest struct {
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	Stream    *bool     `json:"stream,omitempty"`
	Format    string    `json:"format"`
	KeepAlive *Duration `json:"keep_alive,omitempty"`

	Options map[string]interface{} `json:"options"`
}

type Message struct {
	Role    string      `json:"role"` // one of ["system", "user", "assistant"]
	Content string      `json:"content"`
	Images  []ImageData `json:"images,omitempty"`
}

type ChatResponse struct {
	Model     string    `json:"model"`
	CreatedAt time.Time `json:"created_at"`
	Message   Message   `json:"message"`