parent
b96d59c47f
commit
95c4fa7437
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash -x
|
||||
|
||||
OPENAI_API_KEY=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
|
||||
|
||||
curl https://api.openai.com/v1/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||
-d '{
|
||||
"model": "text-davinci-003",
|
||||
"prompt": "In GO, how would I list the available network interfaces?",
|
||||
"temperature": 0.7,
|
||||
"max_tokens": 640,
|
||||
"top_p": 1.0,
|
||||
"frequency_penalty": 0.0,
|
||||
"presence_penalty": 0.0
|
||||
}'
|
|
@ -0,0 +1,9 @@
|
|||
run:
|
||||
GO111MODULE="off" go run -v -x main.go
|
||||
|
||||
prep:
|
||||
GO111MODULE="off" go get -v .
|
||||
|
||||
build:
|
||||
GO111MODULE="off" go build -v -x
|
||||
# go build
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
type favContextKey string
|
||||
|
||||
f := func(ctx context.Context, k favContextKey) {
|
||||
if v := ctx.Value(k); v != nil {
|
||||
fmt.Println("found value:", v)
|
||||
return
|
||||
}
|
||||
fmt.Println("key not found:", k)
|
||||
}
|
||||
|
||||
k := favContextKey("language")
|
||||
ctx := context.WithValue(context.Background(), k, "Go")
|
||||
|
||||
f(ctx, k)
|
||||
f(ctx, favContextKey("color"))
|
||||
|
||||
}
|
Loading…
Reference in New Issue