sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
9.03k stars 1.39k forks source link

Support Tool Resources properties for Threads #760

Closed pkosiec closed 3 months ago

pkosiec commented 4 months ago

Describe the change

Support Tool Resources properties for Threads.

Provide OpenAI documentation link

Describe your solution Describe how your changes address the problem or how they add the feature. This should include a brief description of your approach and any new libraries or dependencies you're using.

Tests I've manually tested the functionality when using the library in the project I'm working on.

Additional context

Resolves https://github.com/sashabaranov/go-openai/issues/759

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.68%. Comparing base (774fc9d) to head (9b434df). Report is 19 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #760 +/- ## ========================================== + Coverage 98.46% 98.68% +0.22% ========================================== Files 24 24 Lines 1364 1140 -224 ========================================== - Hits 1343 1125 -218 + Misses 15 9 -6 Partials 6 6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

temamagic commented 3 months ago

@pkosiec Hello! Could you provide an example of how you use this? I tried to substitute a vector store in the request and am getting an error, would like to take a look at your version of using this

pkosiec commented 3 months ago

Hey @temamagic, this is how I used it:

    return  i.openaiClient.CreateThread(ctx, openai.ThreadRequest{
        Metadata: map[string]any{
            // ...
        },
        ToolResources: openai.ToolResourcesRequest{
            FileSearch: &openai.FileSearchToolResourcesRequest{
                VectorStoreIDs: []string{
                    "{customVectorStoreID}",
                },
            },
        },
        Messages: []openai.ThreadMessage{
            {
                Role:    openai.ThreadMessageRoleUser,
                Content: "prompt",
            },
        },
    })

Hope that helps!

pkosiec commented 3 months ago

Thank you @sashabaranov, let me add the field ASAP 👍

pkosiec commented 3 months ago

@sashabaranov Done: https://github.com/sashabaranov/go-openai/pull/760/commits/9b434df1e88e06ddbe578698cd2fb47bf314dde3

temamagic commented 3 months ago

Hey @temamagic, this is how I used it:

  return  i.openaiClient.CreateThread(ctx, openai.ThreadRequest{
      Metadata: map[string]any{
          // ...
      },
      ToolResources: openai.ToolResourcesRequest{
          FileSearch: &openai.FileSearchToolResourcesRequest{
              VectorStoreIDs: []string{
                  "{customVectorStoreID}",
              },
          },
      },
      Messages: []openai.ThreadMessage{
          {
              Role:    openai.ThreadMessageRoleUser,
              Content: "prompt",
          },
      },
  })

Hope that helps!

In my case, it helped to set the agents version to 2 after initializing the client, but thanks!

pkosiec commented 3 months ago

@temamagic Ah yes, forgot to mention that, sorry. Glad you figured it out!