Skip to content
Open

Lf #146

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
138 changes: 133 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,134 @@ public function tts($opts)
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 array $query
* @return string
*/
public function vectorStoresList(array $query)
{
$url = Url::vectorStoresUrl();
$this->addAssistantsBetaHeader();
$this->baseUrl($url);

if (count($query) > 0) {
$url .= '?' . http_build_query($query);
}

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

/**
* @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 vectorStoresFilesCreateOrAppend(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 +1067,7 @@ public function setORG(string $org)
$this->headers[] = "OpenAI-Organization: $org";
}
}

/**
* @param string $org
*/
Expand All @@ -953,10 +1081,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";
}
}