Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/api/client/client.go
3433 views
1
package client
2
3
import (
4
"github.com/kardolus/chatgpt-cli/api/http"
5
"github.com/kardolus/chatgpt-cli/config"
6
"github.com/kardolus/chatgpt-cli/history"
7
"github.com/kardolus/chatgpt-cli/internal/fsio"
8
"time"
9
)
10
11
const (
12
AssistantRole = "assistant"
13
ErrHistoryTracking = "history tracking needs to be enabled to use this feature"
14
UserRole = "user"
15
)
16
17
type Timer interface {
18
Now() time.Time
19
}
20
21
type RealTime struct {
22
}
23
24
func (r *RealTime) Now() time.Time {
25
return time.Now()
26
}
27
28
type Client struct {
29
Config config.Config
30
History []history.History
31
Caller http.Caller
32
historyStore history.Store
33
transport MCPTransport
34
timer Timer
35
reader fsio.Reader
36
writer fsio.Writer
37
}
38
39
func New(callerFactory http.CallerFactory, hs history.Store, t Timer, r fsio.Reader, w fsio.Writer, cfg config.Config) *Client {
40
caller := callerFactory(cfg)
41
42
return &Client{
43
Config: cfg,
44
Caller: caller,
45
historyStore: hs,
46
timer: t,
47
reader: r,
48
writer: w,
49
}
50
}
51
52
func (c *Client) WithContextWindow(window int) *Client {
53
c.Config.ContextWindow = window
54
return c
55
}
56
57
func (c *Client) WithServiceURL(url string) *Client {
58
c.Config.URL = url
59
return c
60
}
61
62
func (c *Client) WithTransport(transport MCPTransport) *Client {
63
c.transport = transport
64
return c
65
}
66
67