@@ -9,34 +9,44 @@ import (
9
9
)
10
10
11
11
// https://developers.cloudflare.com/workers-ai/models/zephyr-7b-beta-awq/#using-streaming
12
+ // CfTextGenerationResponse represents the response structure for text generation from the Cloudflare AI API.
12
13
type CfTextGenerationResponse struct {
13
14
Response string `json:"response"`
14
15
P string `json:"p"`
15
16
}
16
17
18
+ // CfTextGenerationMsg represents a message for text generation in Cloudflare AI.
17
19
type CfTextGenerationMsg struct {
18
20
Role string `json:"role"`
19
21
Content string `json:"content"`
20
22
}
21
23
24
+ // CfTextGenerationArg represents the arguments for text generation in Cloudflare AI.
22
25
type CfTextGenerationArg struct {
23
26
Stream bool `json:"stream,omitempty"`
24
27
Messages []CfTextGenerationMsg `json:"messages,omitempty"`
25
28
}
26
29
30
+ // body returns the request body as an io.ReadCloser and any encoding error encountered.
27
31
func (c * CfTextGenerationArg ) body () (io.ReadCloser , error ) {
28
32
buff := bytes .NewBuffer (nil )
29
33
err := json .NewEncoder (buff ).Encode (c )
30
34
return io .NopCloser (buff ), err
31
35
}
32
36
37
+ // CloudflareAI represents the configuration for accessing the Cloudflare AI service.
33
38
type CloudflareAI struct {
34
- AccountID string
35
- APIToken string
39
+ AccountID string // AccountID is the identifier for the Cloudflare account.
40
+ APIToken string // APIToken is the authentication token for accessing the Cloudflare AI service.
36
41
}
37
42
38
43
var httpClient = & http.Client {}
39
44
45
+ // modelsTextGeneration is a slice of strings that represents a list of models used for text generation.
46
+ // Each string in the slice corresponds to a specific model.
47
+ // The models are stored in the Cloudflare AI service and can be accessed using the provided URLs.
48
+ // The list is divided into multiple pages, with each page containing a set of models.
49
+ // To access a specific model, you can refer to its corresponding URL.
40
50
var modelsTextGeneration = []string {
41
51
//https://dash.cloudflare.com/0a76b889e644c012524110042e6f197e/ai/workers-ai
42
52
//page 1
@@ -79,6 +89,8 @@ func (c *CloudflareAI) modelCheck(model string) error {
79
89
return errors .New ("model not found: " + model )
80
90
}
81
91
92
+ // Do executes the Cloudflare AI model with the specified model and arguments.
93
+ // It returns the HTTP response and an error, if any.
82
94
func (c * CloudflareAI ) Do (model string , arg * CfTextGenerationArg ) (* http.Response , error ) {
83
95
if c .AccountID == "" || c .APIToken == "" {
84
96
return nil , errors .New ("CF_ACCOUNT_ID and CF_API_TOKEN environment variables are required" )
0 commit comments