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

Assistant ID not found 404 #877

Open
gesaleh opened this issue Oct 14, 2024 · 0 comments
Open

Assistant ID not found 404 #877

gesaleh opened this issue Oct 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@gesaleh
Copy link

gesaleh commented Oct 14, 2024

Your issue may already be reported!
Please search on the issue tracker before creating one.

Describe the bug
I'm trying to run an assistant, the init is done and i can see the list of assistants, when i usse the runrequest.i get always 404 not found

To Reproduce
list assistant , RunThread


import (
	"context"
	"log"
	"os"
	"time"

	"github.com/sashabaranov/go-openai"
)

var client *openai.Client
var assistantId string

func InitOpenAi() {
	client = openai.NewClient(os.Getenv("OPENAI_API_TOKEN"))
	assistantId = os.Getenv("ASSISTANT_ID")
}

func CreateThread() (openai.Thread, error) {
	ctx := context.Background()

	thread, err := client.CreateThread(ctx, openai.ThreadRequest{
		// it's possible to give a chat history here to continue a conversation
	})
	if err != nil {
		return thread, err
	}
	return thread, nil
}

func AddMessage(thread openai.Thread, request string) (openai.Message, error) {
	ctx := context.Background()
	message, err := client.CreateMessage(ctx, thread.ID, openai.MessageRequest{
		Role:    openai.ChatMessageRoleUser,
		Content: request,
	})
	if err != nil {
		return message, err
	}
	return message, nil
}

func ListThread() {
	ctx := context.Background()
	ListAssistants, err := client.ListAssistants(ctx, nil, nil, nil, nil)
	if err != nil {
		log.Printf("List assiatant %+v", err)
	}
	for _, assistant := range ListAssistants.Assistants {
		log.Printf("Assistant ID: %s", assistant.ID)
	}
}

func RunThread(thread openai.Thread) (openai.Run, error) {
	ctx := context.Background()
	run, err := client.CreateRun(ctx, thread.ID, openai.RunRequest{
		AssistantID: assistantId,
	})
	if err != nil {
		return run, err
	}
	for run.Status == openai.RunStatusQueued || run.Status == openai.RunStatusInProgress {
		run, err = client.RetrieveRun(ctx, run.ThreadID, run.ID)
		if err != nil {
			return run, err
		}
		time.Sleep(100 * time.Millisecond)
	}
	if run.Status != openai.RunStatusCompleted {
		log.Fatalf("run failed with status %s", run.Status)
		return run, err
	}
	return run, nil
}

func Getmessages(threadId string) (string, error) {
	ctx := context.Background()
	//var limit int
	var order, after, before, runID string

	numMessages := 1
	messages, err := client.ListMessage(ctx, threadId, &numMessages, &order, &after, &before, &runID)
	if err != nil {
		return "", err
		//log.Fatal(err)
	}

	log.Printf(messages.Messages[0].Content[0].Text.Value)
	return (messages.Messages[0].Content[0].Text.Value), nil
}

Expected behavior
RunThread should execute

Screenshots/Logs
List assistant :
2024/10/14 17:20:38 Assistant ID: asst_5PZy55w28jOyD08YgCnh9nza
2024/10/14 17:20:38 Assistant ID: asst_Q6hFqCMQcIU29TXkeFlKmoI8
2024/10/14 17:20:38 Assistant ID: asst_5sPxZ8xsuZfHrXhSHUKnkDLY
RunThread
2024/10/14 17:20:38 Failed to run thread: error, status code: 404, status: 404 Not Found, message: No assistant found with id 'asst_Q6hFqCMQcIU29TXkeF1KmoI8'.

Environment :

  • go-openai version: go-openai v1.31.0
  • Go version: go version go1.23.1 darwin/arm64
  • OpenAI API version: [e.g. v1]
  • OS: MAcOS 14.6.1 (23G93)

Additional context
Add any other context about the problem here.

@gesaleh gesaleh added the bug Something isn't working label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant