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

Add Vector Stores operation and add Vector Stores Files operation #145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 129 additions & 5 deletions src/OpenAi.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ public function createRun($threadId, $data, $stream = null)

$this->stream_method = $stream;
}

$this->addAssistantsBetaHeader();
$url = Url::threadsUrl() . '/' . $threadId . '/runs';
$this->baseUrl($url);
Expand Down Expand Up @@ -791,7 +791,7 @@ public function submitToolOutputs($threadId, $runId, $outputs, $stream = null)

$this->stream_method = $stream;
}

$this->addAssistantsBetaHeader();
$url = Url::threadsUrl() . '/' . $threadId . '/runs/' . $runId . '/submit_tool_outputs';
$this->baseUrl($url);
Expand Down Expand Up @@ -871,6 +871,130 @@ public function tts($opts)
return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param $opts
* @return string
*/
public function vectorStores($opts)
{
$url = Url::vectorStoresUrl();
$this->baseUrl($url);

return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param array $opts
* @return string
*/
public function vectorStoresCreate(array $opts)
{
$url = Url::vectorStoresUrl();
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param string $vectorStoresId
* @return string
*/
public function vectorStoresSearch(string $vectorStoresId)
{
$url = Url::vectorStoresUrl() . '/' . $vectorStoresId;
$this->addAssistantsBetaHeader();
$this->baseUrl($url);


return $this->sendRequest($url, 'GET');
}

/**
* @param $opts
* @return string
*/
public function vectorStoresEdit(array $opts)
{
$url = Url::vectorStoresUrl();
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param $opts
* @return string
*/
public function vectorStoresDelete(string $vectorStoresId)
{
$url = Url::vectorStoresUrl() . '/' . $vectorStoresId;
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'DELETE');
}

/**
* @param string $vectorStoresId
* @param array $opts
* @return string
*/
public function vectorStoresFilesCreate(string $vectorStoresId, array $opts)
{
$url = Url::vectorStoresFilesUrl($vectorStoresId);
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'POST', $opts);
}

/**
* @param string $vectorStoresId
* @param array $query
* @return string
*/
public function vectorStoresFilesList(string $vectorStoresId, array $query)
{
$url = Url::vectorStoresFilesUrl($vectorStoresId);
if (count($query) > 0) {
$url .= '?' . http_build_query($query);
}
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'GET');
}

/**
* @param string $vectorStoresId
* @param string $filesId
* @return string
*/
public function vectorStoresFilesSearch(string $vectorStoresId, string $filesId)
{
$url = Url::vectorStoresFilesUrl($vectorStoresId) . "/" . $filesId;
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'GET');
}

/**
* @param string $vectorStoresId
* @param string $filesId
* @return string
*/
public function vectorStoresFilesDelete(string $vectorStoresId, string $filesId)
{
$url = Url::vectorStoresFilesUrl($vectorStoresId) . "/" . $filesId;
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

return $this->sendRequest($url, 'DELETE');
}

/**
* @param int $timeout
*/
Expand Down Expand Up @@ -939,7 +1063,7 @@ public function setORG(string $org)
$this->headers[] = "OpenAI-Organization: $org";
}
}

/**
* @param string $org
*/
Expand All @@ -953,10 +1077,10 @@ public function setAssistantsBetaVersion(string $version)
/**
* @return void
*/
private function addAssistantsBetaHeader(){
private function addAssistantsBetaHeader(){
$this->headers[] = 'OpenAI-Beta: assistants='.$this->assistantsBetaVersion;
}


/**
* @param string $url
Expand Down
18 changes: 18 additions & 0 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,22 @@ public static function ttsUrl(): string
{
return self::OPEN_AI_URL . "/audio/speech";
}

/**
* @param
* @return string
*/
public static function vectorStoresUrl(): string
{
return self::OPEN_AI_URL . "/vector_stores";
}

/**
* @param string $vectorStoresId
* @return string
*/
public static function vectorStoresFilesUrl(string $vectorStoresId): string
{
return self::OPEN_AI_URL . "/vector_stores/" . $vectorStoresId . "/files";
}
}