feat: upload audio, get a private Swedish transcript, discuss it (#33, ADR-033) #39
@@ -25,12 +25,16 @@ import (
|
|||||||
// docs/homelab-integration.md.
|
// docs/homelab-integration.md.
|
||||||
const defaultMaxTokens = 8192
|
const defaultMaxTokens = 8192
|
||||||
|
|
||||||
|
// defaultTemperature is what every caller got before WithTemperature existed.
|
||||||
|
const defaultTemperature = 0.2
|
||||||
|
|
||||||
// Client calls an OpenAI-compatible chat completions endpoint.
|
// Client calls an OpenAI-compatible chat completions endpoint.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
baseURL string
|
baseURL string
|
||||||
apiKey string
|
apiKey string
|
||||||
model string
|
model string
|
||||||
maxTokens int
|
maxTokens int
|
||||||
|
temp float64
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
usageHook func(model string, prompt, completion int)
|
usageHook func(model string, prompt, completion int)
|
||||||
}
|
}
|
||||||
@@ -51,6 +55,12 @@ func WithMaxTokens(n int) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTemperature overrides the sampling temperature. Zero IS a valid value and is sent
|
||||||
|
// as zero: the reconciler's accuracy was measured at temperature 0 and must run there.
|
||||||
|
func WithTemperature(t float64) Option {
|
||||||
|
return func(c *Client) { c.temp = t }
|
||||||
|
}
|
||||||
|
|
||||||
// WithUsageHook registers a callback fired after a successful completion with the
|
// WithUsageHook registers a callback fired after a successful completion with the
|
||||||
// model and the prompt/completion token counts from the response usage block. It
|
// model and the prompt/completion token counts from the response usage block. It
|
||||||
// keeps this copied, stdlib-only package (ADR-004) decoupled from metrics: the
|
// keeps this copied, stdlib-only package (ADR-004) decoupled from metrics: the
|
||||||
@@ -66,6 +76,7 @@ func New(baseURL, apiKey, model string, timeout time.Duration, opts ...Option) *
|
|||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
model: model,
|
model: model,
|
||||||
maxTokens: defaultMaxTokens,
|
maxTokens: defaultMaxTokens,
|
||||||
|
temp: defaultTemperature,
|
||||||
httpClient: &http.Client{Timeout: timeout},
|
httpClient: &http.Client{Timeout: timeout},
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -105,7 +116,7 @@ func (c *Client) Complete(ctx context.Context, system, user string) (string, err
|
|||||||
{Role: "system", Content: system},
|
{Role: "system", Content: system},
|
||||||
{Role: "user", Content: user},
|
{Role: "user", Content: user},
|
||||||
},
|
},
|
||||||
Temperature: 0.2,
|
Temperature: c.temp,
|
||||||
MaxTokens: c.maxTokens,
|
MaxTokens: c.maxTokens,
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(body)
|
b, err := json.Marshal(body)
|
||||||
|
|||||||
Reference in New Issue
Block a user