{"repo_name": "deepseek-php-client", "file_name": "/deepseek-php-client/src/DeepSeekClient.php", "inference_info": {"prefix_code": "httpClient = $httpClient;\n $this->model = null;\n $this->stream = false;\n $this->requestMethod = 'POST';\n $this->endpointSuffixes = EndpointSuffixes::CHAT->value;\n $this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value;\n $this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value;\n $this->responseFormatType = TemperatureValues::RESPONSE_FORMAT_TYPE->value;\n $this->tools = null;\n }\n public function run(): string\n {\n $requestData = [\n QueryFlags::MESSAGES->value => $this->queries,\n QueryFlags::MODEL->value => $this->model,\n QueryFlags::STREAM->value => $this->stream,\n QueryFlags::TEMPERATURE->value => $this->temperature,\n QueryFlags::MAX_TOKENS->value => $this->maxTokens,\n QueryFlags::TOOLS->value => $this->tools,\n QueryFlags::RESPONSE_FORMAT->value => [\n 'type' => $this->responseFormatType\n ],\n ];\n $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod));\n return $this->getResult()->getContent();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n $httpClient = ApiFactory::build()\n ->setBaseUri($baseUrl)\n ->setTimeout($timeout)\n ->setKey($apiKey)\n ->run($clientType);\n return new self($httpClient);\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n return $this;\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST->value;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => $role ?: QueryRoles::USER->value,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n return $this;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n}", "code_description": null, "fill_type": "CLASS_TYPE", "language_type": "php", "sub_task_type": null}, "context_code": [["/deepseek-php-client/src/Factories/ApiFactory.php", "baseUrl = $baseUrl ? trim($baseUrl) : DefaultConfigs::BASE_URL->value;\n return $this;\n }\n\n public function setKey(string $apiKey): self\n {\n $this->apiKey = trim($apiKey);\n return $this;\n }\n\n public function setTimeout(?int $timeout = null): self\n {\n $this->timeout = $timeout ?: (int)DefaultConfigs::TIMEOUT->value;\n return $this;\n }\n\n public function initialize(): self\n {\n if (!isset($this->baseUrl)) {\n $this->setBaseUri();\n }\n\n if (!isset($this->apiKey)) {\n throw new RuntimeException('API key must be set using setKey() before initialization.');\n }\n\n if (!isset($this->timeout)) {\n $this->setTimeout();\n }\n\n $this->clientConfig = [\n HeaderFlags::BASE_URL->value => $this->baseUrl,\n HeaderFlags::TIMEOUT->value => $this->timeout,\n HeaderFlags::HEADERS->value => [\n HeaderFlags::AUTHORIZATION->value => 'Bearer ' . $this->apiKey,\n HeaderFlags::CONTENT_TYPE->value => 'application/json',\n ],\n ];\n\n return $this;\n }\n\n public function run(?string $clientType = null): ClientInterface\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n\n if (!isset($this->clientConfig)) {\n $this->initialize();\n }\n\n return match (strtolower($clientType)) {\n ClientTypes::GUZZLE->value => new Client($this->clientConfig),\n ClientTypes::SYMFONY->value => new Psr18Client(HttpClient::create($this->clientConfig)),\n default => throw new InvalidArgumentException(\"Unsupported client type: {$clientType}\")\n };\n }\n}\n"], ["/deepseek-php-client/src/Resources/Resource.php", "client = $client;\n $this->endpointSuffixes = $endpointSuffixes ?: EndpointSuffixes::CHAT->value;\n $this->requestFactory = $requestFactory ?: new Psr17Factory();\n $this->streamFactory = $streamFactory ?: new Psr17Factory();\n }\n\n public function sendRequest(array $requestData, ?string $requestMethod = 'POST'): ResultContract\n {\n try {\n $request = $this->requestFactory->createRequest(\n $requestMethod,\n $this->getEndpointSuffix()\n );\n\n if ($requestMethod === 'POST') {\n $request = $request\n ->withHeader('Content-Type', 'application/json')\n ->withBody(\n $this->streamFactory->createStream(\n json_encode($this->resolveHeaders($requestData))\n ));\n }\n\n $response = $this->client->sendRequest($request);\n\n return (new SuccessResult())->setResponse($response);\n } catch (BadResponseException $badResponse) {\n return (new BadResult())->setResponse($badResponse->getResponse());\n } catch (GuzzleException $error) {\n return new FailureResult($error->getCode(), $error->getMessage());\n } catch (\\Exception $error) {\n return new FailureResult($error->getCode(), '{\"error\":\"'.$error->getMessage().'\"}');\n }\n }\n\n /**\n * Merge request data with default headers.\n *\n * This method merges the given query data with custom headers that are\n * prepared for the request.\n *\n * @param array $requestData The data to send in the request.\n * @return array The merged request data with default headers.\n */\n protected function resolveHeaders(array $requestData): array\n {\n return array_merge($requestData, $this->prepareCustomHeaderParams($requestData));\n }\n\n /**\n * Prepare the custom headers for the request.\n *\n * This method loops through the query parameters and applies the appropriate\n * type conversion before returning the final headers.\n *\n * @param array $query The data to send in the request.\n * @return array The custom headers for the request.\n */\n public function prepareCustomHeaderParams(array $query): array\n {\n $headers = [];\n $params = $this->getAllowedQueryParamsList();\n\n // Loop through the parameters and apply the conversion logic dynamically\n foreach ($params as $key => $type) {\n $headers[$key] = $this->getQueryParam($query, $key, $this->getDefaultForKey($key), $type);\n }\n\n return $headers;\n }\n\n /**\n * Get the endpoint suffix for the resource.\n *\n * This method returns the endpoint suffix that is used in the API URL.\n *\n * @return string The endpoint suffix.\n */\n public function getEndpointSuffix(): string\n {\n return $this->endpointSuffixes;\n }\n\n /**\n * Get the model associated with the resource.\n *\n * This method returns the default model value associated with the resource.\n *\n * @return string The default model value.\n */\n public function getDefaultModel(): string\n {\n return Models::CHAT->value;\n }\n\n /**\n * Check if stream is enabled or not.\n *\n * This method checks whether the streaming option is enabled based on the\n * default configuration.\n *\n * @return bool True if streaming is enabled, false otherwise.\n */\n public function getDefaultStream(): bool\n {\n return DefaultConfigs::STREAM->value === 'true';\n }\n\n /**\n * Get the list of query parameters and their corresponding types for conversion.\n *\n * This method returns an array of query keys and their associated data types\n * for use in preparing the custom headers.\n *\n * @return array An associative array of query keys and their data types.\n */\n protected function getAllowedQueryParamsList(): array\n {\n return [\n QueryFlags::MODEL->value => DataTypes::STRING->value,\n QueryFlags::STREAM->value => DataTypes::BOOL->value,\n ];\n }\n}\n"], ["/deepseek-php-client/src/Traits/Client/HasToolsFunctionCalling.php", "tools = $tools;\n return $this;\n }\n\n /**\n * Add a query tool calls to the accumulated queries list.\n *\n * @param array $toolCalls The tool calls generated by the model, such as function calls.\n * @param string $content\n * @param string|null $role\n * @return self The current instance for method chaining.\n */\n public function queryToolCall(array $toolCalls, string $content, ?string $role = null): self\n {\n $this->queries[] = $this->buildToolCallQuery($toolCalls, $content, $role);\n return $this;\n }\n\n public function buildToolCallQuery(array $toolCalls, string $content, ?string $role = null): array\n {\n $query = [\n 'role' => $role ?: QueryRoles::ASSISTANT->value,\n 'tool_calls' => $toolCalls,\n 'content' => $content,\n ];\n return $query;\n }\n\n /**\n * Add a query tool to the accumulated queries list.\n *\n * @param string $toolCallId\n * @param string $content\n * @param string|null $role\n * @return self The current instance for method chaining.\n */\n public function queryTool(string $toolCallId, string $content , ?string $role = null): self\n {\n $this->queries[] = $this->buildToolQuery($toolCallId, $content, $role);\n return $this;\n }\n\n public function buildToolQuery(string $toolCallId, string $content, ?string $role): array\n {\n $query = [\n 'role' => $role ?: QueryRoles::TOOL->value,\n 'tool_call_id' => $toolCallId,\n 'content' => $content,\n ];\n return $query;\n }\n}\n"], ["/deepseek-php-client/src/Models/ResultAbstract.php", "statusCode = $statusCode;\n $this->content = $content;\n }\n protected function setStatusCode(int $statusCode)\n {\n $this->statusCode = $statusCode;\n }\n public function getStatusCode(): int\n {\n return $this->statusCode;\n }\n protected function setContent(string $content): void\n {\n $this->content = $content;\n }\n public function getContent(): string\n {\n return $this->content;\n }\n public function setResponse(ResponseInterface $response): static\n {\n $this->response = $response;\n $this->setStatusCode($this->getResponse()->getStatusCode());\n $this->setContent($this->getResponse()->getBody()->getContents());\n return $this;\n }\n public function getResponse(): ResponseInterface\n {\n return $this->response;\n }\n public function isSuccess(): bool\n {\n return ($this->getStatusCode() === HTTPState::OK->value);\n }\n}\n\n"], ["/deepseek-php-client/src/Traits/Queries/HasQueryParams.php", "convertValue($value, $type);\n }\n\n return $default;\n }\n\n /**\n * Convert the value to the specified type.\n *\n * @param mixed $value\n * @param string $type\n * @return mixed\n */\n private function convertValue($value, string $type): mixed\n {\n return match ($type) {\n DataTypes::STRING->value => (string)$value,\n DataTypes::INTEGER->value => (int)$value,\n DataTypes::FLOAT->value => (float)$value,\n DataTypes::ARRAY->value => (array)$value,\n DataTypes::OBJECT->value => (object)$value,\n DataTypes::BOOL->value => (bool)$value,\n DataTypes::JSON->value => json_decode((string)$value, true),\n default => $value,\n };\n }\n\n /**\n * Get default value for specific query keys.\n *\n * @param string $key\n * @return mixed\n */\n private function getDefaultForKey(string $key): mixed\n {\n return match ($key) {\n QueryFlags::MODEL->value => $this->getDefaultModel(),\n QueryFlags::STREAM->value => $this->getDefaultStream(),\n default => null,\n };\n }\n}\n"], ["/deepseek-php-client/src/Traits/Resources/HasChat.php", " $this->queries,\n 'model' => $this->model,\n 'stream' => $this->stream,\n ];\n $this->queries = [];\n $this->setResult((new Chat($this->httpClient))->sendRequest($requestData));\n return $this->getResult()->getContent();\n }\n}\n"], ["/deepseek-php-client/src/Traits/Resources/HasCoder.php", " $this->queries,\n 'model' => $this->model,\n 'stream' => $this->stream,\n ];\n $this->queries = [];\n $this->setResult((new Coder($this->httpClient))->sendRequest($requestData));\n return $this->getResult()->getContent();\n }\n}\n"], ["/deepseek-php-client/src/Contracts/ClientContract.php", "value;\n }\n}\n"], ["/deepseek-php-client/src/Enums/Requests/QueryFlags.php", "httpClient = $httpClient;\n }\n\n public function run(): string\n {\n $apiRequest = ApiFactory::createRequest(\n $this->requestMethod,\n $this->endpointSuffixes ? EndpointSuffixes::value($this->endpointSuffixes) : null,\n $this->buildRequestData()\n );\n\n return $this->httpClient->sendRequest($apiRequest)->getBody()->getContents();\n }\n\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n return new self(ApiFactory::create($apiKey, $baseUrl, $timeout, $clientType ? ClientTypes::value($clientType) : null));\n }\n\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n\n public function resetQueries()\n {\n $this->queries = [];\n }\n\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST;\n $this->requestMethod = 'GET';\n return $this;\n }\n\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => QueryRoles::tryFrom($role ?? QueryRoles::USER->value) ?? QueryRoles::USER,\n 'content' => $content\n ];\n }\n\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n }\n\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n\n private function buildRequestData(): array\n {\n return array_filter([\n 'model' => $this->model,\n 'messages' => $this->queries,\n 'stream' => $this->stream,\n 'temperature' => $this->temperature,\n 'max_tokens' => $this->maxTokens,\n 'response_format' => ['type' => $this->responseFormatType],\n 'tools' => $this->tools\n ], fn($value) => !is_null($value) && $value !== '');\n }\n}\n[TASK_END]", "inference_time": "2025-08-20 21-13-03"}, "editdistance_info": {"edit_distance": 47.5316, "calculate_time": "2025-08-20 21:13:03", "true_code_clean": "class DeepSeekClient implements ClientContract\n{\n use HasChat, HasCoder;\n use HasToolsFunctionCalling;\n protected ClientInterface $httpClient;\n protected array $queries = [];\n protected ?string $model;\n protected bool $stream;\n protected float $temperature;\n protected int $maxTokens;\n protected string $responseFormatType;\n protected ResultContract $result;\n protected string $requestMethod;\n protected ?string $endpointSuffixes;\n protected ?array $tools;\n public function __construct(ClientInterface $httpClient)\n {\n $this->httpClient = $httpClient;\n $this->model = null;\n $this->stream = false;\n $this->requestMethod = 'POST';\n $this->endpointSuffixes = EndpointSuffixes::CHAT->value;\n $this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value;\n $this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value;\n $this->responseFormatType = TemperatureValues::RESPONSE_FORMAT_TYPE->value;\n $this->tools = null;\n }\n public function run(): string\n {\n $requestData = [\n QueryFlags::MESSAGES->value => $this->queries,\n QueryFlags::MODEL->value => $this->model,\n QueryFlags::STREAM->value => $this->stream,\n QueryFlags::TEMPERATURE->value => $this->temperature,\n QueryFlags::MAX_TOKENS->value => $this->maxTokens,\n QueryFlags::TOOLS->value => $this->tools,\n QueryFlags::RESPONSE_FORMAT->value => [\n 'type' => $this->responseFormatType\n ],\n ];\n $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod));\n return $this->getResult()->getContent();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n $httpClient = ApiFactory::build()\n ->setBaseUri($baseUrl)\n ->setTimeout($timeout)\n ->setKey($apiKey)\n ->run($clientType);\n return new self($httpClient);\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n return $this;\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST->value;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => $role ?: QueryRoles::USER->value,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n return $this;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n}", "predict_code_clean": "class DeepSeekClient implements ClientContract\n{\n use HasChat, HasCoder, HasToolsFunctionCalling;\n protected ClientInterface $httpClient;\n protected array $queries = [];\n protected ?string $model = null;\n protected bool $stream = false;\n protected float $temperature = TemperatureValues::DEFAULT;\n protected int $maxTokens = 0;\n protected string $responseFormatType = 'text';\n protected ResultContract $result;\n protected string $requestMethod = 'POST';\n protected ?string $endpointSuffixes = null;\n protected ?array $tools = null;\n public function __construct(ClientInterface $httpClient)\n {\n $this->httpClient = $httpClient;\n }\n public function run(): string\n {\n $apiRequest = ApiFactory::createRequest(\n $this->requestMethod,\n $this->endpointSuffixes ? EndpointSuffixes::value($this->endpointSuffixes) : null,\n $this->buildRequestData()\n );\n return $this->httpClient->sendRequest($apiRequest)->getBody()->getContents();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n return new self(ApiFactory::create($apiKey, $baseUrl, $timeout, $clientType ? ClientTypes::value($clientType) : null));\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => QueryRoles::tryFrom($role ?? QueryRoles::USER->value) ?? QueryRoles::USER,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n private function buildRequestData(): array\n {\n return array_filter([\n 'model' => $this->model,\n 'messages' => $this->queries,\n 'stream' => $this->stream,\n 'temperature' => $this->temperature,\n 'max_tokens' => $this->maxTokens,\n 'response_format' => ['type' => $this->responseFormatType],\n 'tools' => $this->tools\n ], fn($value) => !is_null($value) && $value !== '');\n }\n}"}} {"repo_name": "deepseek-php-client", "file_name": "/deepseek-php-client/src/DeepSeekClient.php", "inference_info": {"prefix_code": "httpClient = $httpClient;\n $this->model = null;\n $this->stream = false;\n $this->requestMethod = 'POST';\n $this->endpointSuffixes = EndpointSuffixes::CHAT->value;\n $this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value;\n $this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value;\n $this->responseFormatType = TemperatureValues::RESPONSE_FORMAT_TYPE->value;\n $this->tools = null;\n }\n public function run(): string\n {\n $requestData = [\n QueryFlags::MESSAGES->value => $this->queries,\n QueryFlags::MODEL->value => $this->model,\n QueryFlags::STREAM->value => $this->stream,\n QueryFlags::TEMPERATURE->value => $this->temperature,\n QueryFlags::MAX_TOKENS->value => $this->maxTokens,\n QueryFlags::TOOLS->value => $this->tools,\n QueryFlags::RESPONSE_FORMAT->value => [\n 'type' => $this->responseFormatType\n ],\n ];\n $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod));\n return $this->getResult()->getContent();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n $httpClient = ApiFactory::build()\n ->setBaseUri($baseUrl)\n ->setTimeout($timeout)\n ->setKey($apiKey)\n ->run($clientType);\n return new self($httpClient);\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n return $this;\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST->value;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => $role ?: QueryRoles::USER->value,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n return $this;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n}", "code_description": null, "fill_type": "CLASS_TYPE", "language_type": "php", "sub_task_type": null}, "context_code": [["/deepseek-php-client/src/Factories/ApiFactory.php", "baseUrl = $baseUrl ? trim($baseUrl) : DefaultConfigs::BASE_URL->value;\n return $this;\n }\n\n public function setKey(string $apiKey): self\n {\n $this->apiKey = trim($apiKey);\n return $this;\n }\n\n public function setTimeout(?int $timeout = null): self\n {\n $this->timeout = $timeout ?: (int)DefaultConfigs::TIMEOUT->value;\n return $this;\n }\n\n public function initialize(): self\n {\n if (!isset($this->baseUrl)) {\n $this->setBaseUri();\n }\n\n if (!isset($this->apiKey)) {\n throw new RuntimeException('API key must be set using setKey() before initialization.');\n }\n\n if (!isset($this->timeout)) {\n $this->setTimeout();\n }\n\n $this->clientConfig = [\n HeaderFlags::BASE_URL->value => $this->baseUrl,\n HeaderFlags::TIMEOUT->value => $this->timeout,\n HeaderFlags::HEADERS->value => [\n HeaderFlags::AUTHORIZATION->value => 'Bearer ' . $this->apiKey,\n HeaderFlags::CONTENT_TYPE->value => 'application/json',\n ],\n ];\n\n return $this;\n }\n\n public function run(?string $clientType = null): ClientInterface\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n\n if (!isset($this->clientConfig)) {\n $this->initialize();\n }\n\n return match (strtolower($clientType)) {\n ClientTypes::GUZZLE->value => new Client($this->clientConfig),\n ClientTypes::SYMFONY->value => new Psr18Client(HttpClient::create($this->clientConfig)),\n default => throw new InvalidArgumentException(\"Unsupported client type: {$clientType}\")\n };\n }\n}\n"], ["/deepseek-php-client/src/Resources/Resource.php", "client = $client;\n $this->endpointSuffixes = $endpointSuffixes ?: EndpointSuffixes::CHAT->value;\n $this->requestFactory = $requestFactory ?: new Psr17Factory();\n $this->streamFactory = $streamFactory ?: new Psr17Factory();\n }\n\n public function sendRequest(array $requestData, ?string $requestMethod = 'POST'): ResultContract\n {\n try {\n $request = $this->requestFactory->createRequest(\n $requestMethod,\n $this->getEndpointSuffix()\n );\n\n if ($requestMethod === 'POST') {\n $request = $request\n ->withHeader('Content-Type', 'application/json')\n ->withBody(\n $this->streamFactory->createStream(\n json_encode($this->resolveHeaders($requestData))\n ));\n }\n\n $response = $this->client->sendRequest($request);\n\n return (new SuccessResult())->setResponse($response);\n } catch (BadResponseException $badResponse) {\n return (new BadResult())->setResponse($badResponse->getResponse());\n } catch (GuzzleException $error) {\n return new FailureResult($error->getCode(), $error->getMessage());\n } catch (\\Exception $error) {\n return new FailureResult($error->getCode(), '{\"error\":\"'.$error->getMessage().'\"}');\n }\n }\n\n /**\n * Merge request data with default headers.\n *\n * This method merges the given query data with custom headers that are\n * prepared for the request.\n *\n * @param array $requestData The data to send in the request.\n * @return array The merged request data with default headers.\n */\n protected function resolveHeaders(array $requestData): array\n {\n return array_merge($requestData, $this->prepareCustomHeaderParams($requestData));\n }\n\n /**\n * Prepare the custom headers for the request.\n *\n * This method loops through the query parameters and applies the appropriate\n * type conversion before returning the final headers.\n *\n * @param array $query The data to send in the request.\n * @return array The custom headers for the request.\n */\n public function prepareCustomHeaderParams(array $query): array\n {\n $headers = [];\n $params = $this->getAllowedQueryParamsList();\n\n // Loop through the parameters and apply the conversion logic dynamically\n foreach ($params as $key => $type) {\n $headers[$key] = $this->getQueryParam($query, $key, $this->getDefaultForKey($key), $type);\n }\n\n return $headers;\n }\n\n /**\n * Get the endpoint suffix for the resource.\n *\n * This method returns the endpoint suffix that is used in the API URL.\n *\n * @return string The endpoint suffix.\n */\n public function getEndpointSuffix(): string\n {\n return $this->endpointSuffixes;\n }\n\n /**\n * Get the model associated with the resource.\n *\n * This method returns the default model value associated with the resource.\n *\n * @return string The default model value.\n */\n public function getDefaultModel(): string\n {\n return Models::CHAT->value;\n }\n\n /**\n * Check if stream is enabled or not.\n *\n * This method checks whether the streaming option is enabled based on the\n * default configuration.\n *\n * @return bool True if streaming is enabled, false otherwise.\n */\n public function getDefaultStream(): bool\n {\n return DefaultConfigs::STREAM->value === 'true';\n }\n\n /**\n * Get the list of query parameters and their corresponding types for conversion.\n *\n * This method returns an array of query keys and their associated data types\n * for use in preparing the custom headers.\n *\n * @return array An associative array of query keys and their data types.\n */\n protected function getAllowedQueryParamsList(): array\n {\n return [\n QueryFlags::MODEL->value => DataTypes::STRING->value,\n QueryFlags::STREAM->value => DataTypes::BOOL->value,\n ];\n }\n}\n"], ["/deepseek-php-client/src/Traits/Client/HasToolsFunctionCalling.php", "tools = $tools;\n return $this;\n }\n\n /**\n * Add a query tool calls to the accumulated queries list.\n *\n * @param array $toolCalls The tool calls generated by the model, such as function calls.\n * @param string $content\n * @param string|null $role\n * @return self The current instance for method chaining.\n */\n public function queryToolCall(array $toolCalls, string $content, ?string $role = null): self\n {\n $this->queries[] = $this->buildToolCallQuery($toolCalls, $content, $role);\n return $this;\n }\n\n public function buildToolCallQuery(array $toolCalls, string $content, ?string $role = null): array\n {\n $query = [\n 'role' => $role ?: QueryRoles::ASSISTANT->value,\n 'tool_calls' => $toolCalls,\n 'content' => $content,\n ];\n return $query;\n }\n\n /**\n * Add a query tool to the accumulated queries list.\n *\n * @param string $toolCallId\n * @param string $content\n * @param string|null $role\n * @return self The current instance for method chaining.\n */\n public function queryTool(string $toolCallId, string $content , ?string $role = null): self\n {\n $this->queries[] = $this->buildToolQuery($toolCallId, $content, $role);\n return $this;\n }\n\n public function buildToolQuery(string $toolCallId, string $content, ?string $role): array\n {\n $query = [\n 'role' => $role ?: QueryRoles::TOOL->value,\n 'tool_call_id' => $toolCallId,\n 'content' => $content,\n ];\n return $query;\n }\n}\n"], ["/deepseek-php-client/src/Models/ResultAbstract.php", "statusCode = $statusCode;\n $this->content = $content;\n }\n protected function setStatusCode(int $statusCode)\n {\n $this->statusCode = $statusCode;\n }\n public function getStatusCode(): int\n {\n return $this->statusCode;\n }\n protected function setContent(string $content): void\n {\n $this->content = $content;\n }\n public function getContent(): string\n {\n return $this->content;\n }\n public function setResponse(ResponseInterface $response): static\n {\n $this->response = $response;\n $this->setStatusCode($this->getResponse()->getStatusCode());\n $this->setContent($this->getResponse()->getBody()->getContents());\n return $this;\n }\n public function getResponse(): ResponseInterface\n {\n return $this->response;\n }\n public function isSuccess(): bool\n {\n return ($this->getStatusCode() === HTTPState::OK->value);\n }\n}\n\n"], ["/deepseek-php-client/src/Traits/Queries/HasQueryParams.php", "convertValue($value, $type);\n }\n\n return $default;\n }\n\n /**\n * Convert the value to the specified type.\n *\n * @param mixed $value\n * @param string $type\n * @return mixed\n */\n private function convertValue($value, string $type): mixed\n {\n return match ($type) {\n DataTypes::STRING->value => (string)$value,\n DataTypes::INTEGER->value => (int)$value,\n DataTypes::FLOAT->value => (float)$value,\n DataTypes::ARRAY->value => (array)$value,\n DataTypes::OBJECT->value => (object)$value,\n DataTypes::BOOL->value => (bool)$value,\n DataTypes::JSON->value => json_decode((string)$value, true),\n default => $value,\n };\n }\n\n /**\n * Get default value for specific query keys.\n *\n * @param string $key\n * @return mixed\n */\n private function getDefaultForKey(string $key): mixed\n {\n return match ($key) {\n QueryFlags::MODEL->value => $this->getDefaultModel(),\n QueryFlags::STREAM->value => $this->getDefaultStream(),\n default => null,\n };\n }\n}\n"], ["/deepseek-php-client/src/Traits/Resources/HasChat.php", " $this->queries,\n 'model' => $this->model,\n 'stream' => $this->stream,\n ];\n $this->queries = [];\n $this->setResult((new Chat($this->httpClient))->sendRequest($requestData));\n return $this->getResult()->getContent();\n }\n}\n"], ["/deepseek-php-client/src/Traits/Resources/HasCoder.php", " $this->queries,\n 'model' => $this->model,\n 'stream' => $this->stream,\n ];\n $this->queries = [];\n $this->setResult((new Coder($this->httpClient))->sendRequest($requestData));\n return $this->getResult()->getContent();\n }\n}\n"], ["/deepseek-php-client/src/Contracts/ClientContract.php", "value;\n }\n}\n"], ["/deepseek-php-client/src/Enums/Requests/QueryFlags.php", "httpClient = $httpClient;\n }\n\n public function run(): string\n {\n $request = $this->httpClient->createRequest(\n $this->requestMethod,\n $this->endpointSuffixes ? EndpointSuffixes::from($this->endpointSuffixes)->value : '',\n ['body' => json_encode($this->buildRequestBody())]\n );\n \n $response = $this->httpClient->sendRequest($request);\n $this->result->setResponse($response);\n \n return $this->result->getAnswer();\n }\n\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n return ApiFactory::create(\n $apiKey,\n $baseUrl,\n $timeout,\n $clientType ? ClientTypes::from($clientType) : ClientTypes::CHAT\n );\n }\n\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n\n public function resetQueries()\n {\n $this->queries = [];\n }\n\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST;\n $this->requestMethod = 'GET';\n return $this;\n }\n\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => QueryRoles::tryFrom($role ?? QueryRoles::USER)->value,\n 'content' => $content\n ];\n }\n\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n }\n\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n\n private function buildRequestBody(): array\n {\n return array_filter([\n 'model' => $this->model,\n 'messages' => $this->queries,\n 'stream' => $this->stream,\n 'temperature' => $this->temperature,\n 'max_tokens' => $this->maxTokens,\n 'response_format' => ['type' => $this->responseFormatType],\n 'tools' => $this->tools\n ], fn($v) => $v !== null);\n }\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 21-13-08"}, "editdistance_info": {"edit_distance": 48.1056, "calculate_time": "2025-08-20 21:13:08", "true_code_clean": "class DeepSeekClient implements ClientContract\n{\n use HasChat, HasCoder;\n use HasToolsFunctionCalling;\n protected ClientInterface $httpClient;\n protected array $queries = [];\n protected ?string $model;\n protected bool $stream;\n protected float $temperature;\n protected int $maxTokens;\n protected string $responseFormatType;\n protected ResultContract $result;\n protected string $requestMethod;\n protected ?string $endpointSuffixes;\n protected ?array $tools;\n public function __construct(ClientInterface $httpClient)\n {\n $this->httpClient = $httpClient;\n $this->model = null;\n $this->stream = false;\n $this->requestMethod = 'POST';\n $this->endpointSuffixes = EndpointSuffixes::CHAT->value;\n $this->temperature = (float) TemperatureValues::GENERAL_CONVERSATION->value;\n $this->maxTokens = (int) TemperatureValues::MAX_TOKENS->value;\n $this->responseFormatType = TemperatureValues::RESPONSE_FORMAT_TYPE->value;\n $this->tools = null;\n }\n public function run(): string\n {\n $requestData = [\n QueryFlags::MESSAGES->value => $this->queries,\n QueryFlags::MODEL->value => $this->model,\n QueryFlags::STREAM->value => $this->stream,\n QueryFlags::TEMPERATURE->value => $this->temperature,\n QueryFlags::MAX_TOKENS->value => $this->maxTokens,\n QueryFlags::TOOLS->value => $this->tools,\n QueryFlags::RESPONSE_FORMAT->value => [\n 'type' => $this->responseFormatType\n ],\n ];\n $this->setResult((new Resource($this->httpClient, $this->endpointSuffixes))->sendRequest($requestData, $this->requestMethod));\n return $this->getResult()->getContent();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n $clientType = $clientType ?? ClientTypes::GUZZLE->value;\n $httpClient = ApiFactory::build()\n ->setBaseUri($baseUrl)\n ->setTimeout($timeout)\n ->setKey($apiKey)\n ->run($clientType);\n return new self($httpClient);\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n return $this;\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST->value;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => $role ?: QueryRoles::USER->value,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n return $this;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n}", "predict_code_clean": "class DeepSeekClient implements ClientContract\n{\n protected ClientInterface $httpClient;\n protected array $queries = [];\n protected ?string $model = null;\n protected bool $stream = false;\n protected float $temperature = TemperatureValues::DEFAULT;\n protected int $maxTokens = 1024;\n protected string $responseFormatType = 'json';\n protected ResultContract $result;\n protected string $requestMethod = 'POST';\n protected ?string $endpointSuffixes = null;\n protected ?array $tools = null;\n public function __construct(ClientInterface $httpClient)\n {\n $this->httpClient = $httpClient;\n }\n public function run(): string\n {\n $request = $this->httpClient->createRequest(\n $this->requestMethod,\n $this->endpointSuffixes ? EndpointSuffixes::from($this->endpointSuffixes)->value : '',\n ['body' => json_encode($this->buildRequestBody())]\n );\n $response = $this->httpClient->sendRequest($request);\n $this->result->setResponse($response);\n return $this->result->getAnswer();\n }\n public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null): self\n {\n return ApiFactory::create(\n $apiKey,\n $baseUrl,\n $timeout,\n $clientType ? ClientTypes::from($clientType) : ClientTypes::CHAT\n );\n }\n public function query(string $content, ?string $role = \"user\"): self\n {\n $this->queries[] = $this->buildQuery($content, $role);\n return $this;\n }\n public function resetQueries()\n {\n $this->queries = [];\n }\n public function getModelsList(): self\n {\n $this->endpointSuffixes = EndpointSuffixes::MODELS_LIST;\n $this->requestMethod = 'GET';\n return $this;\n }\n public function withModel(?string $model = null): self\n {\n $this->model = $model;\n return $this;\n }\n public function withStream(bool $stream = true): self\n {\n $this->stream = $stream;\n return $this;\n }\n public function setTemperature(float $temperature): self\n {\n $this->temperature = $temperature;\n return $this;\n }\n public function setMaxTokens(int $maxTokens): self\n {\n $this->maxTokens = $maxTokens;\n return $this;\n }\n public function setResponseFormat(string $type): self\n {\n $this->responseFormatType = $type;\n return $this;\n }\n public function buildQuery(string $content, ?string $role = null): array\n {\n return [\n 'role' => QueryRoles::tryFrom($role ?? QueryRoles::USER)->value,\n 'content' => $content\n ];\n }\n public function setResult(ResultContract $result)\n {\n $this->result = $result;\n }\n public function getResult(): ResultContract\n {\n return $this->result;\n }\n private function buildRequestBody(): array\n {\n return array_filter([\n 'model' => $this->model,\n 'messages' => $this->queries,\n 'stream' => $this->stream,\n 'temperature' => $this->temperature,\n 'max_tokens' => $this->maxTokens,\n 'response_format' => ['type' => $this->responseFormatType],\n 'tools' => $this->tools\n ], fn($v) => $v !== null);\n }\n}"}}