Skip to content

Commit

Permalink
Fix chatglm model
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui committed Jun 6, 2024
1 parent c62d37e commit b22cdb2
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/Api/Chatglm/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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,
]);
Expand All @@ -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];
}

}

0 comments on commit b22cdb2

Please sign in to comment.