Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected [, expecting semicolon or newline or } #216

Closed
venvis856 opened this issue Mar 31, 2023 · 4 comments
Closed

unexpected [, expecting semicolon or newline or } #216

venvis856 opened this issue Mar 31, 2023 · 4 comments
Labels
question Further information is requested stale

Comments

@venvis856
Copy link

When I use the official example

package main

import (
	"context"
	"fmt"
	openai "github.com/sashabaranov/go-openai"
)

func main() {
	client := openai.NewClient("sk-xxxxxxxxxxxxxxxxxxxxxxxxx")
	resp, err := client.CreateChatCompletion(
		context.Background(),
		openai.ChatCompletionRequest{
			Model: openai.GPT3Dot5Turbo,
			Messages: []openai.ChatCompletionMessage{
				{
					Role:    openai.ChatMessageRoleUser,
					Content: "Hello!",
				},
			},
		},
	)

	if err != nil {
		fmt.Printf("ChatCompletion error: %v\n", err)
		return
	}

	fmt.Println(resp.Choices[0].Message.Content)
}

Reported the following error

# github.com/sashabaranov/go-openai
/root/go/pkg/mod/github.com/sashabaranov/go-openai@v1.5.7/chat_stream.go:29:15: syntax error: unexpected [, expecting semicolon or newline or }
/root/go/pkg/mod/github.com/sashabaranov/go-openai@v1.5.7/chat_stream.go:58:60: syntax error: unexpected {, expecting comma or }
/root/go/pkg/mod/github.com/sashabaranov/go-openai@v1.5.7/chat_stream.go:60:49: syntax error: unexpected ) at end of statement
/root/go/pkg/mod/github.com/sashabaranov/go-openai@v1.5.7/chat_stream.go:63:42: syntax error: unexpected comma after top level declaration

I need your help

@suifengqjn
Copy link

Did you fix it? me too

@cention-mujibur-rahman
Copy link

I think its go version. Could you please check your version?

@vvatanabe
Copy link
Collaborator

@venvis856 Perhaps your locally installed version of Go is less than 1.18. go-openai uses generics internally, so Go 1.18 or higher is required.

@vvatanabe vvatanabe added question Further information is requested stale labels Jul 1, 2023
@vvatanabe
Copy link
Collaborator

Closing this due to lack of comments for an extended period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

4 participants