mirror of
https://github.com/hanzo-go/openai.git
synced 2026-09-24 00:31:39 +00:00
The fork kept the upstream module path (module github.com/sashabaranov/ go-openai), so every consumer could only reach it through a "replace github.com/sashabaranov/go-openai => github.com/hanzoai/go-openai" directive — and Go replace directives do NOT propagate to consumers, so each downstream repo had to copy the same replace or fail to compile against fork-only fields (e.g. ReasoningContent). That is the opposite of one-and- only-one-way. Declare the fork's OWN module path so it can be required directly and inherited transitively. Package name stays 'openai' (import identifier unchanged); only the module path + internal self-imports (/internal, /jsonschema) are renamed. Upstream issue-URL comments are left intact as attribution. Builds + vets clean. Co-authored-by: Hanzo Dev <[email protected]>
43 lines
944 B
Go
43 lines
944 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/hanzoai/go-openai"
|
|
)
|
|
|
|
func main() {
|
|
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
|
|
|
|
req := openai.ChatCompletionRequest{
|
|
Model: openai.GPT3Dot5Turbo,
|
|
Messages: []openai.ChatCompletionMessage{
|
|
{
|
|
Role: openai.ChatMessageRoleSystem,
|
|
Content: "you are a helpful chatbot",
|
|
},
|
|
},
|
|
}
|
|
fmt.Println("Conversation")
|
|
fmt.Println("---------------------")
|
|
fmt.Print("> ")
|
|
s := bufio.NewScanner(os.Stdin)
|
|
for s.Scan() {
|
|
req.Messages = append(req.Messages, openai.ChatCompletionMessage{
|
|
Role: openai.ChatMessageRoleUser,
|
|
Content: s.Text(),
|
|
})
|
|
resp, err := client.CreateChatCompletion(context.Background(), req)
|
|
if err != nil {
|
|
fmt.Printf("ChatCompletion error: %v\n", err)
|
|
continue
|
|
}
|
|
fmt.Printf("%s\n\n", resp.Choices[0].Message.Content)
|
|
req.Messages = append(req.Messages, resp.Choices[0].Message)
|
|
fmt.Print("> ")
|
|
}
|
|
}
|