Repository navigation
Expand file tree
/
Copy pathllmv1chat.go
More file actions
133 lines (123 loc) · 3.92 KB
/
Copy pathllmv1chat.go
File metadata and controls
133 lines (123 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package cmd
import (
"context"
"fmt"
"github.com/CaseMark/casedev-cli/internal/apiquery"
"github.com/CaseMark/casedev-cli/internal/requestflag"
"github.com/CaseMark/casedev-go"
"github.com/CaseMark/casedev-go/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)
var llmV1ChatCreateCompletion = requestflag.WithInnerFlags(cli.Command{
Name: "create-completion",
Usage: "Create a completion for the provided prompt and parameters. Compatible with\nOpenAI's chat completions API. Supports 40+ models including GPT-4, Claude,\nGemini, and CaseMark legal AI models. Includes streaming support, token\ncounting, and usage tracking.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[[]map[string]any]{
Name: "message",
Usage: "List of messages comprising the conversation",
Required: true,
BodyPath: "messages",
},
&requestflag.Flag[bool]{
Name: "casemark-show-reasoning",
Usage: "CaseMark-only: controls whether reasoning fields appear in responses. Defaults to false (suppressed) for most CaseMark models; defaults to true for casemark/core-potassium.",
BodyPath: "casemark_show_reasoning",
},
&requestflag.Flag[float64]{
Name: "frequency-penalty",
Usage: "Frequency penalty parameter",
BodyPath: "frequency_penalty",
},
&requestflag.Flag[int64]{
Name: "max-tokens",
Usage: "Maximum number of tokens to generate",
BodyPath: "max_tokens",
},
&requestflag.Flag[string]{
Name: "model",
Usage: "Model to use for completion. Defaults to casemark/core-large if not specified",
BodyPath: "model",
},
&requestflag.Flag[float64]{
Name: "presence-penalty",
Usage: "Presence penalty parameter",
BodyPath: "presence_penalty",
},
&requestflag.Flag[bool]{
Name: "stream",
Usage: "Whether to stream back partial progress",
BodyPath: "stream",
},
&requestflag.Flag[float64]{
Name: "temperature",
Usage: "Sampling temperature between 0 and 2",
BodyPath: "temperature",
},
&requestflag.Flag[float64]{
Name: "top-p",
Usage: "Nucleus sampling parameter",
BodyPath: "top_p",
},
&requestflag.Flag[string]{
Name: "ai-reporting-tags",
HeaderPath: "ai-reporting-tags",
},
&requestflag.Flag[string]{
Name: "ai-reporting-user",
HeaderPath: "ai-reporting-user",
},
},
Action: handleLlmV1ChatCreateCompletion,
HideHelpCommand: true,
}, map[string][]requestflag.HasOuterFlag{
"message": {
&requestflag.InnerFlag[string]{
Name: "message.content",
Usage: "The contents of the message",
InnerField: "content",
},
&requestflag.InnerFlag[string]{
Name: "message.role",
Usage: "The role of the message author",
InnerField: "role",
},
},
})
func handleLlmV1ChatCreateCompletion(ctx context.Context, cmd *cli.Command) error {
client := githubcomcasemarkcasedevgo.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatComma,
ApplicationJSON,
false,
)
if err != nil {
return err
}
params := githubcomcasemarkcasedevgo.LlmV1ChatNewCompletionParams{}
var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Llm.V1.Chat.NewCompletion(ctx, params, options...)
if err != nil {
return err
}
obj := gjson.ParseBytes(res)
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "llm:v1:chat create-completion",
Transform: transform,
})
}