Skip to content

Commit b56655f

Browse files
committed
Updated
1 parent 5b510e1 commit b56655f

File tree

4 files changed

+120
-14
lines changed

4 files changed

+120
-14
lines changed

README.md

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,110 @@ The transation of field types is as follows:
374374
* `uint`, `int` - Translates to JSON `integer`
375375
* `float32`, `float64` - Translates to JSON `number`
376376

377-
## Options
377+
## Complete and Chat Options
378+
379+
These are the options you can use with the `Completion` and `Chat` methods.
380+
381+
<table>
382+
<tr>
383+
<th>Ollama</th>
384+
<th>Anthropic</th>
385+
<th>Mistral</th>
386+
<th>OpenAI</th>
387+
<th>Gemini</th>
388+
</tr>
389+
390+
<tr><td colspan="6">
391+
<code>llm.WithTemperature(float64)</code>
392+
What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
393+
</td></tr>
394+
<tr style="border-bottom: 2px solid black;">
395+
<td>Yes</td>
396+
<td>Yes</td>
397+
<td>Yes</td>
398+
<td>Yes</td>
399+
<td>Yes</td>
400+
</tr>
401+
402+
</table>
403+
404+
## Embedding Options
405+
406+
These are the options you can include for the `Embedding`method.
407+
408+
<table>
409+
<tr>
410+
<th>Ollama</th>
411+
<th>Anthropic</th>
412+
<th>Mistral</th>
413+
<th>OpenAI</th>
414+
<th>Gemini</th>
415+
</tr>
416+
417+
<tr><td colspan="6">
418+
<code>ollama.WithKeepAlive(time.Duration)</code>
419+
Controls how long the model will stay loaded into memory following the request
420+
</td></tr>
421+
<tr style="border-bottom: 2px solid black;">
422+
<td>Yes</td>
423+
<td>No</td>
424+
<td>No</td>
425+
<td>No</td>
426+
<td>No</td>
427+
</tr>
428+
429+
<tr><td colspan="6">
430+
<code>ollama.WithTruncate()</code>
431+
Does not truncate the end of each input to fit within context length. Returns error if context length is exceeded.
432+
</td></tr>
433+
<tr style="border-bottom: 2px solid black;">
434+
<td>Yes</td>
435+
<td>No</td>
436+
<td>No</td>
437+
<td>No</td>
438+
<td>No</td>
439+
</tr>
440+
441+
<tr><td colspan="6">
442+
<code>ollama.WithOption(string, any)</code>
443+
Set model-specific option value.
444+
</td></tr>
445+
<tr style="border-bottom: 2px solid black;">
446+
<td>Yes</td>
447+
<td>No</td>
448+
<td>No</td>
449+
<td>No</td>
450+
<td>No</td>
451+
</tr>
452+
453+
<tr><td colspan="6">
454+
<code>openai.WithDimensions(uint64)</code>
455+
The number of dimensions the resulting output embeddings
456+
should have. Only supported in text-embedding-3 and later models.
457+
</td></tr>
458+
<tr style="border-bottom: 2px solid black;">
459+
<td>No</td>
460+
<td>No</td>
461+
<td>No</td>
462+
<td>Yes</td>
463+
<td>No</td>
464+
</tr>
465+
466+
<tr><td colspan="6">
467+
<code>llm.WithFormat(string)</code>
468+
The format to return the embeddings in. Can be either .
469+
</td></tr>
470+
<tr style="border-bottom: 2px solid black;">
471+
<td>No</td>
472+
<td>No</td>
473+
<td>'float'</td>
474+
<td>'float' or 'base64'</td>
475+
<td>No</td>
476+
</tr>
477+
478+
</table>
479+
480+
## Older Content
378481

379482
You can add options to sessions, or to prompts. Different providers and models support
380483
different options.
@@ -389,9 +492,6 @@ type Model interface {
389492
// Create a completion from a text prompt
390493
Completion(context.Context, string, ...Opt) (Completion, error)
391494

392-
// Create a completion from a chat session
393-
Chat(context.Context, []Completion, ...Opt) (Completion, error)
394-
395495
// Embedding vector generation
396496
Embedding(context.Context, string, ...Opt) ([]float64, error)
397497
}

model.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ import (
55
)
66

77
// An Model can be used to generate a response to a user prompt,
8-
// which is passed to an agent. The interaction occurs through
8+
// which is passed to an agent. A back-and-forth interaction occurs through
99
// a session context object.
1010
type Model interface {
1111
// Return the name of the model
1212
Name() string
1313

14-
// Return am empty session context object for the model,
15-
// setting session options
14+
// Return am empty session context object for the model, setting
15+
// session options
1616
Context(...Opt) Context
1717

1818
// Create a completion from a text prompt
1919
Completion(context.Context, string, ...Opt) (Completion, error)
2020

21-
// Create a completion from a chat session
22-
Chat(context.Context, []Completion, ...Opt) (Completion, error)
23-
2421
// Embedding vector generation
2522
Embedding(context.Context, string, ...Opt) ([]float64, error)
2623
}

pkg/ollama/opt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func WithInsecure() llm.Opt {
2121
}
2222

2323
// Embeddings: Does not truncate the end of each input to fit within context length. Returns error if context length is exceeded.
24-
func WithTruncate(v bool) llm.Opt {
24+
func WithTruncate() llm.Opt {
2525
return func(o *llm.Opts) error {
26-
o.Set("truncate", v)
26+
o.Set("truncate", true)
2727
return nil
2828
}
2929
}

pkg/session/session.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ type MessageFactory interface {
2323
ToolResults(...llm.ToolResult) ([]llm.Completion, error)
2424
}
2525

26+
type Model interface {
27+
// Additional method for a context object
28+
Chat(ctx context.Context, completions []llm.Completion, opts ...llm.Opt) (llm.Completion, error)
29+
}
30+
2631
///////////////////////////////////////////////////////////////////////////////
2732
// TYPES
2833

2934
// A chat session with history
3035
type session struct {
31-
model llm.Model // The model used for the session
36+
model Model // The model used for the session
3237
opts []llm.Opt // Options to apply to the session
3338
seq []llm.Completion // Sequence of messages
3439
factory MessageFactory // Factory for generating messages
@@ -41,8 +46,12 @@ var _ llm.Context = (*session)(nil)
4146

4247
// Create a new empty session to store a context window
4348
func NewSession(model llm.Model, factory MessageFactory, opts ...llm.Opt) *session {
49+
chatmodel, ok := model.(Model)
50+
if !ok || model == nil {
51+
panic("Model does not implement the session.Model interface")
52+
}
4453
return &session{
45-
model: model,
54+
model: chatmodel,
4655
opts: opts,
4756
seq: make([]llm.Completion, 0, 10),
4857
factory: factory,

0 commit comments

Comments
 (0)