diff --git a/src/Api/Chatglm/Client.php b/src/Api/Chatglm/Client.php index 08ba536..ac69d98 100644 --- a/src/Api/Chatglm/Client.php +++ b/src/Api/Chatglm/Client.php @@ -35,6 +35,7 @@ class Client implements ClientInterface protected ?LoggerInterface $logger; protected bool $debug = true; + protected string $model; public function __construct(ChatglmConfig $config, LoggerInterface $logger, string $model) @@ -44,24 +45,6 @@ public function __construct(ChatglmConfig $config, LoggerInterface $logger, stri $this->initConfig($config); } - protected function initConfig(ChatglmConfig $config): static - { - if (! $config instanceof ChatglmConfig) { - throw new InvalidArgumentException('ChatglmConfig is required'); - } - $this->config = $config; - $headers = [ - 'Authorization' => 'Bearer ' . $config->getApiKey(), - 'Content-Type' => 'application/json', - 'User-Agent' => 'Hyperf-Odin/1.0', - ]; - $this->clients[$this->model] = new GuzzleClient([ - 'base_uri' => $config->getHost(), - 'headers' => $headers, - ]); - return $this; - } - public function chat( array $messages, string $model, @@ -114,11 +97,6 @@ public function chat( return $chatCompletionResponse; } - protected function getClient(string $model): ?GuzzleClient - { - return $this->clients[$model]; - } - public function models(): ListResponse { throw new NotImplementedException(); @@ -130,13 +108,11 @@ public function embedding( ?string $user = null ): ListResponse { $json = [ + 'model' => $model, 'input' => $input, ]; $user && $json['user'] = $user; $response = $this->getClient($model)->post('/api/paas/v4/embeddings', [ - 'query' => [ - 'api-version' => $this->config->getApiVersion($model), - ], 'json' => $json, 'verify' => false, ]); @@ -154,8 +130,27 @@ public function setDebug(bool $debug): static return $this; } - protected function buildDeploymentPath(string $model = 'glm-4'): string + protected function initConfig(ChatglmConfig $config): static { - return 'openai/deployments/' . $this->config->getDeploymentName($model); + if (! $config instanceof ChatglmConfig) { + throw new InvalidArgumentException('ChatglmConfig is required'); + } + $this->config = $config; + $headers = [ + 'Authorization' => 'Bearer ' . $config->getApiKey(), + 'Content-Type' => 'application/json', + 'User-Agent' => 'Hyperf-Odin/1.0', + ]; + $this->clients[$this->model] = new GuzzleClient([ + 'base_uri' => $config->getHost(), + 'headers' => $headers, + ]); + return $this; } + + protected function getClient(string $model): ?GuzzleClient + { + return $this->clients[$model]; + } + }