Skip to content

Commit fd03a8d

Browse files
authored
add doc
1 parent 040a355 commit fd03a8d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cloudflare_ai.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,44 @@ import (
99
)
1010

1111
// 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.
1213
type CfTextGenerationResponse struct {
1314
Response string `json:"response"`
1415
P string `json:"p"`
1516
}
1617

18+
// CfTextGenerationMsg represents a message for text generation in Cloudflare AI.
1719
type CfTextGenerationMsg struct {
1820
Role string `json:"role"`
1921
Content string `json:"content"`
2022
}
2123

24+
// CfTextGenerationArg represents the arguments for text generation in Cloudflare AI.
2225
type CfTextGenerationArg struct {
2326
Stream bool `json:"stream,omitempty"`
2427
Messages []CfTextGenerationMsg `json:"messages,omitempty"`
2528
}
2629

30+
// body returns the request body as an io.ReadCloser and any encoding error encountered.
2731
func (c *CfTextGenerationArg) body() (io.ReadCloser, error) {
2832
buff := bytes.NewBuffer(nil)
2933
err := json.NewEncoder(buff).Encode(c)
3034
return io.NopCloser(buff), err
3135
}
3236

37+
// CloudflareAI represents the configuration for accessing the Cloudflare AI service.
3338
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.
3641
}
3742

3843
var httpClient = &http.Client{}
3944

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.
4050
var modelsTextGeneration = []string{
4151
//https://dash.cloudflare.com/0a76b889e644c012524110042e6f197e/ai/workers-ai
4252
//page 1
@@ -79,6 +89,8 @@ func (c *CloudflareAI) modelCheck(model string) error {
7989
return errors.New("model not found: " + model)
8090
}
8191

92+
// Do executes the Cloudflare AI model with the specified model and arguments.
93+
// It returns the HTTP response and an error, if any.
8294
func (c *CloudflareAI) Do(model string, arg *CfTextGenerationArg) (*http.Response, error) {
8395
if c.AccountID == "" || c.APIToken == "" {
8496
return nil, errors.New("CF_ACCOUNT_ID and CF_API_TOKEN environment variables are required")

0 commit comments

Comments
 (0)