Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ responses:
x-codeSamples:
- $ref: 'examples/curl/agentInference_create_chat_completion.yml'
- $ref: 'examples/python/agentInference_create_chat_completion.yml'
- $ref: 'examples/go/agentInference_create_chat_completion.yml'
- $ref: 'examples/dots/agentInference_create_chat_completion.yml'
security:
- inference_bearer_auth: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
agent, err := godo.NewAgentInferenceClient(
os.Getenv("AGENT_ENDPOINT"),
os.Getenv("AGENT_ACCESS_KEY"),
)
if err != nil {
panic(err)
}

ctx := context.Background()

completion, _, err := agent.Chat.Completions.New(ctx, &godo.ChatCompletionNewParams{
Model: "llama3.3-70b-instruct",
Messages: []godo.ChatCompletionMessage{
godo.UserMessage("What is the capital of Portugal?"),
},
})
if err != nil {
panic(err)
}

if msg := completion.Choices[0].Message.Content; msg != nil {
fmt.Println(*msg)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

// Async invoke uses model_id + a free-form input map. Shape of input
// depends on the model (image, audio, TTS, and so on).
invocation, _, err := client.AsyncInvocations.New(ctx, &godo.AsyncInvocationNewParams{
ModelID: "fal-ai/flux/schnell",
Input: map[string]interface{}{
"prompt": "A futuristic city at sunset",
},
})
if err != nil {
panic(err)
}

fmt.Println(invocation.RequestID, invocation.Status)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

batch, _, err := client.BatchInference.CancelJob(ctx, os.Getenv("BATCH_ID"))
if err != nil {
panic(err)
}

fmt.Println("batch_id:", batch.BatchID)
fmt.Println("status: ", batch.Status)
if batch.CancelRequestedAt != nil {
fmt.Println("cancel_requested_at:", *batch.CancelRequestedAt)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
lang: Go
source: |-
package main

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

id := make([]byte, 16)
if _, err := rand.Read(id); err != nil {
panic(err)
}

batch, _, err := client.BatchInference.CreateJob(ctx, &godo.CreateBatchRequest{
FileID: os.Getenv("BATCH_INPUT_FILE_ID"),
Provider: "openai",
Endpoint: "/v1/chat/completions",
CompletionWindow: "24h",
RequestID: hex.EncodeToString(id),
})
if err != nil {
panic(err)
}

fmt.Println("batch_id:", batch.BatchID)
fmt.Println("status: ", batch.Status)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

intent, _, err := client.BatchInference.CreatePresignedUploadURL(ctx, &godo.CreateBatchFileRequest{
FileName: "batch_requests.jsonl",
})
if err != nil {
panic(err)
}

fmt.Println("file_id: ", intent.FileID)
fmt.Println("upload_url:", intent.UploadURL)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

completion, _, err := client.Chat.Completions.New(ctx, &godo.ChatCompletionNewParams{
Model: "llama3.3-70b-instruct",
Messages: []godo.ChatCompletionMessage{
godo.UserMessage("What is the capital of Portugal?"),
},
})
if err != nil {
panic(err)
}

if msg := completion.Choices[0].Message.Content; msg != nil {
fmt.Println(*msg)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
lang: Go
source: |-
package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

resp, _, err := client.Embeddings.New(ctx, &godo.EmbeddingNewParams{
Model: "qwen3-embedding-0.6b",
Input: []string{"hello world", "goodbye world"},
EncodingFormat: "float",
User: "user-1234",
})
if err != nil {
panic(err)
}

for _, item := range resp.Data {
var vec []float32
if err := json.Unmarshal(item.Embedding, &vec); err != nil {
panic(err)
}
head := vec
if len(head) > 8 {
head = head[:8]
}
fmt.Println(item.Index, head)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

resp, _, err := client.ImageGenerations.Generate(ctx, &godo.ImageGenerateParams{
Model: "openai-gpt-image-1",
Prompt: "A cute baby sea otter floating on its back in calm blue water",
Size: godo.PtrTo("auto"),
Quality: godo.PtrTo("auto"),
N: 1,
})
if err != nil {
panic(err)
}

fmt.Println(resp.Data[0].B64JSON)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
lang: Go
source: |-
package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

content, err := json.Marshal("What is the capital of Portugal?")
if err != nil {
panic(err)
}

msg, _, err := client.Messages.New(ctx, &godo.MessageNewParams{
Model: "claude-opus-4-6",
MaxTokens: 1024,
Messages: []godo.MessageParam{
{Role: "user", Content: content},
},
})
if err != nil {
panic(err)
}

for _, block := range msg.Content {
if block.Type == "text" {
fmt.Println(block.Text)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

resp, _, err := client.Responses.New(ctx, &godo.ResponseNewParams{
Model: "openai-gpt-oss-20b",
Input: "What is the capital of France?",
MaxOutputTokens: godo.PtrTo(50),
Temperature: godo.PtrTo(0.7),
})
if err != nil {
panic(err)
}

fmt.Println(resp.OutputText())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lang: Go
source: |-
package main

import (
"context"
"fmt"
"os"

"github.com/digitalocean/godo"
)

func main() {
client := godo.NewFromToken(os.Getenv("DIGITALOCEAN_TOKEN"))
ctx := context.Background()

batch, _, err := client.BatchInference.GetJob(ctx, os.Getenv("BATCH_ID"))
if err != nil {
panic(err)
}

fmt.Println("batch_id: ", batch.BatchID)
fmt.Println("status: ", batch.Status)
fmt.Println("result_available:", batch.ResultAvailable)
if batch.RequestCounts != nil {
fmt.Printf("request_counts: %+v\n", *batch.RequestCounts)
}
}
Loading
Loading