Skip to content

Commit 8462492

Browse files
committed
Added session based caching
1 parent fda1020 commit 8462492

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

main.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,46 @@ func main() {
3333
"Queue action: 'view', 'clear', 'count', 'completed-count', 'completed-first', 'completed-last'",
3434
)
3535

36+
flag.Usage = func() {
37+
w := flag.CommandLine.Output()
38+
w.Write([]byte(`
39+
Usage:
40+
app --mode <mode> [options]
3641
42+
Modes:
43+
client Enqueue a job
44+
worker Run the worker
45+
view View results
46+
delete-group Delete a group and its results
47+
queue Queue operations
48+
help Show this help message
3749
38-
flag.Parse()
50+
Client mode options:
51+
--args Job args as JSON
52+
--metadata Job metadata as JSON
53+
--bulk-from-file Bulk insert jobs from JSON file
54+
55+
View mode options:
56+
--total-groups Show total groups
57+
--group <id> Show results for a group
58+
-n <number> Number of results to display
59+
60+
Delete-group mode options:
61+
--delete-group-id Group ID to delete
3962
63+
Queue mode options:
64+
--action view | clear | count | completed-count | completed-first | completed-last
65+
--queue-n Number of jobs to display
66+
67+
`))
68+
}
69+
70+
flag.Parse()
71+
if *mode == "help" {
72+
flag.Usage()
73+
os.Exit(0)
74+
}
75+
4076
ctx, cancel := context.WithCancel(context.Background())
4177
defer cancel()
4278

ollama.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func LoadLLMConfig(configPath string) (*LLMConfig, error) {
2525
return &conf.LLM, nil
2626
}
2727

28-
func CallOllama(prompt string, schema interface{}, configPath string) (string, error) {
28+
func CallOllama(prompt string, schema interface{}, configPath string, groupName string, system_prompt string) (string, error) {
2929
startTotal := time.Now()
3030

3131
// 1️⃣ Load config
@@ -43,7 +43,9 @@ func CallOllama(prompt string, schema interface{}, configPath string) (string, e
4343
req := map[string]interface{}{
4444
"model": llmConfig.Model,
4545
"stream": false,
46+
"session_id": groupName,
4647
"messages": []map[string]string{
48+
{"role": "system", "content": system_prompt },
4749
{"role": "user", "content": prompt},
4850
},
4951
"options": map[string]float64{

types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type DPromptsJobArgs struct {
1414
Prompt string `json:"prompt"`
1515
Schema interface{} `json:"schema,omitempty"`
1616
GroupName string `json:"group_name,omitempty"` // optional
17+
SystemPrompt string `json:"system_prompt,omitempty"` // optional
1718
}
1819

1920

worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (w *DPromptsWorker) Work(ctx context.Context, job *river.Job[DPromptsJobArg
4545

4646
// Before LLM call
4747
stageTimestamps["before_ollama"] = time.Now()
48-
response, err := CallOllama(job.Args.Prompt, job.Args.Schema, configPath)
48+
response, err := CallOllama(job.Args.Prompt, job.Args.Schema, configPath, job.Args.GroupName, job.Args.SystemPrompt)
4949
stageTimestamps["after_ollama"] = time.Now()
5050
if err != nil {
5151
log.Error().Err(err).Msg("Ollama call failed")

0 commit comments

Comments
 (0)