File size: 80,561 Bytes
6648d93
 
1
2
3
{"repo_name": "deepseek-php-client", "file_name": "/deepseek-php-client/src/DeepSeekClient.php", "inference_info": {"prefix_code": "<?php\n\nnamespace DeepSeek;\n\nuse DeepSeek\\Contracts\\ClientContract;\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Enums\\Requests\\ClientTypes;\nuse DeepSeek\\Enums\\Requests\\EndpointSuffixes;\nuse DeepSeek\\Resources\\Resource;\nuse Psr\\Http\\Client\\ClientInterface;\nuse DeepSeek\\Factories\\ApiFactory;\nuse DeepSeek\\Enums\\Queries\\QueryRoles;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\nuse DeepSeek\\Enums\\Configs\\TemperatureValues;\nuse DeepSeek\\Traits\\Resources\\{HasChat, HasCoder};\nuse DeepSeek\\Traits\\Client\\HasToolsFunctionCalling;\n\n", "suffix_code": "\n", "middle_code": "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}", "code_description": null, "fill_type": "CLASS_TYPE", "language_type": "php", "sub_task_type": null}, "context_code": [["/deepseek-php-client/src/Factories/ApiFactory.php", "<?php\n\nnamespace DeepSeek\\Factories;\n\nuse DeepSeek\\Contracts\\Factories\\ApiFactoryContract;\nuse DeepSeek\\Enums\\Configs\\DefaultConfigs;\nuse DeepSeek\\Enums\\Requests\\ClientTypes;\nuse DeepSeek\\Enums\\Requests\\HeaderFlags;\nuse GuzzleHttp\\Client;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Symfony\\Component\\HttpClient\\HttpClient;\nuse Symfony\\Component\\HttpClient\\Psr18Client;\nuse RuntimeException;\nuse InvalidArgumentException;\n\nfinal class ApiFactory implements ApiFactoryContract\n{\n    protected string $apiKey;\n    protected string $baseUrl;\n    protected int $timeout;\n    protected array $clientConfig;\n\n    public static function build(): self\n    {\n        return new self();\n    }\n\n    public function setBaseUri(?string $baseUrl = null): self\n    {\n        $this->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", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Contracts\\Resources\\ResourceContract;\nuse DeepSeek\\Enums\\Configs\\DefaultConfigs;\nuse DeepSeek\\Enums\\Models;\nuse DeepSeek\\Enums\\Data\\DataTypes;\nuse DeepSeek\\Enums\\Requests\\EndpointSuffixes;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\nuse DeepSeek\\Models\\BadResult;\nuse DeepSeek\\Models\\FailureResult;\nuse DeepSeek\\Models\\SuccessResult;\nuse DeepSeek\\Traits\\Queries\\HasQueryParams;\nuse GuzzleHttp\\Exception\\BadResponseException;\nuse GuzzleHttp\\Exception\\GuzzleException;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestFactoryInterface;\nuse Psr\\Http\\Message\\StreamFactoryInterface;\nuse Nyholm\\Psr7\\Factory\\Psr17Factory;\n\nclass Resource implements ResourceContract\n{\n    use HasQueryParams;\n\n    protected ClientInterface $client;\n    protected ?string $endpointSuffixes;\n    protected RequestFactoryInterface $requestFactory;\n    protected StreamFactoryInterface $streamFactory;\n\n    public function __construct(\n        ClientInterface $client,\n        ?string $endpointSuffixes = null,\n        ?RequestFactoryInterface $requestFactory = null,\n        ?StreamFactoryInterface $streamFactory = null\n    ) {\n        $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Client;\n\nuse DeepSeek\\Enums\\Queries\\QueryRoles;\n\ntrait HasToolsFunctionCalling\n{\n    /**\n     * @param array $tools A list of tools the model may call.\n     * @return self The current instance for method chaining.\n     */\n    public function setTools(array $tools): self\n    {\n        $this->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", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Enums\\Requests\\HTTPState;\nuse Psr\\Http\\Message\\ResponseInterface;\n\nabstract class ResultAbstract implements ResultContract\n{\n    protected ?int $statusCode;\n    protected ?string $content;\n    /**\n     * handel response coming from request\n     * @var ResponseInterface|null\n     */\n    protected ?ResponseInterface $response;\n    public function __construct(?int $statusCode = null, ?string $content = null)\n    {\n        $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Queries;\n\nuse DeepSeek\\Enums\\Data\\DataTypes;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\n\ntrait HasQueryParams\n{\n    /**\n     * Helper method to get the query parameter or default value with type conversion.\n     *\n     * @param array $query\n     * @param string $key\n     * @param mixed $default\n     * @param string $type\n     * @return mixed\n     */\n    private function getQueryParam(array $query, string $key, $default, string $type): mixed\n    {\n        if (isset($query[$key])) {\n            $value = $query[$key];\n            return $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Resources;\n\nuse DeepSeek\\Resources\\Chat;\n\ntrait HasChat\n{\n    /**\n     * Send the accumulated queries to the Chat resource.\n     *\n     * @return string\n     */\n    public function chat(): string\n    {\n        $requestData = [\n            'messages' => $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", "<?php\n\nnamespace DeepSeek\\Traits\\Resources;\n\nuse DeepSeek\\Resources\\Coder;\n\ntrait HasCoder\n{\n    /**\n     * Send the accumulated queries to the code resource.\n     *\n     * @return string\n     */\n    public function code(): string\n    {\n        $requestData = [\n            'messages' => $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", "<?php\n\nnamespace DeepSeek\\Contracts;\n\ninterface ClientContract\n{\n    public function run(): string;\n    public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null): self;\n    public function query(string $content, ?string $role = \"user\"): self;\n    public function getModelsList(): self;\n    public function withModel(?string $model = null): self;\n    public function withStream(bool $stream = true): self;\n    public function buildQuery(string $content, ?string $role = null): array;\n}\n"], ["/deepseek-php-client/src/Contracts/Factories/ApiFactoryContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Factories;\n\nuse DeepSeek\\Factories\\ApiFactory;\nuse GuzzleHttp\\Client;\nuse Psr\\Http\\Client\\ClientInterface;\n\ninterface ApiFactoryContract\n{\n    /**\n     * Create a new instance of the factory.\n     *\n     * @return ApiFactory\n     */\n    public static function build(): ApiFactory;\n\n    /**\n     * Set the base URL for the API.\n     *\n     * @param string|null $baseUrl The base URL to set (optional).\n     * @return ApiFactory\n     */\n    public function setBaseUri(?string $baseUrl = null): ApiFactory;\n\n    /**\n     * Set the API key for authentication.\n     *\n     * @param string $apiKey The API key to set.\n     * @return ApiFactory\n     */\n    public function setKey(string $apiKey): ApiFactory;\n\n    /**\n     * Set the timeout for the API request.\n     *\n     * @param int|null $timeout The timeout value in seconds (optional).\n     * @return ApiFactory\n     */\n    public function setTimeout(?int $timeout = null): ApiFactory;\n\n    /**\n     * Build and return http Client instance.\n     *\n     * @return ClientInterface\n     */\n    public function run(?string $clientType = null): ClientInterface;\n}\n"], ["/deepseek-php-client/src/Resources/Coder.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nuse DeepSeek\\Enums\\Models;\n\nclass Coder extends Resource\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::CODER->value;\n    }\n}\n"], ["/deepseek-php-client/src/Enums/Requests/QueryFlags.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum QueryFlags: string\n{\n    case MESSAGES = 'messages';\n    case MODEL = 'model';\n    case STREAM = 'stream';\n    case TEMPERATURE = 'temperature';\n    case MAX_TOKENS = 'max_tokens';\n    case TOOLS = 'tools';\n    case RESPONSE_FORMAT = 'response_format';\n}\n"], ["/deepseek-php-client/src/Contracts/Models/ResultContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Models;\n\ninterface ResultContract\n{\n    /**\n     * result status code\n     * @return int\n     */\n    public function getStatusCode(): int;\n\n    /**\n     * result content date as a string\n     * @return string\n     */\n    public function getContent(): string;\n\n    /**\n     * if response status code is ok (200)\n     * @return bool\n     */\n    public function isSuccess(): bool;\n}\n"], ["/deepseek-php-client/src/Contracts/Resources/ResourceContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Resources;\n\n/**\n * Interface for defining the structure of resource classes.\n */\ninterface ResourceContract\n{\n    /**\n     * Get the endpoint suffix for the resource.\n     *\n     * @return string\n     */\n    public function getEndpointSuffix(): string;\n\n    /**\n     * Get the model associated with the resource.\n     *\n     * @return string\n     */\n    public function getDefaultModel(): string;\n\n    /**\n     * check if stream enabled or not.\n     *\n     * @return bool\n     */\n    public function getDefaultStream(): bool;\n}\n"], ["/deepseek-php-client/src/Enums/Requests/EndpointSuffixes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum EndpointSuffixes: string\n{\n    case CHAT = '/chat/completions';\n    case MODELS_LIST = '/models';\n}\n"], ["/deepseek-php-client/src/Enums/Configs/TemperatureValues.php", "<?php\n\nnamespace DeepSeek\\Enums\\Configs;\n\nenum TemperatureValues: string\n{\n    case CODING = \"0.0\";\n    case MATH = \"0.1\";\n    case DATA_ANALYSIS = \"1.0\";\n    case DATA_CLEANING = \"1.1\";\n    case GENERAL_CONVERSATION = \"1.3\";\n    case TRANSLATION = \"1.4\";\n    case CREATIVE_WRITING = \"1.5\";\n    case POETRY = \"1.6\";\n    case MAX_TOKENS = \"4096\";\n    case RESPONSE_FORMAT_TYPE = \"text\";\n}\n"], ["/deepseek-php-client/src/Enums/Requests/HeaderFlags.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum HeaderFlags: string\n{\n    case BASE_URL = 'base_uri';\n    case TIMEOUT = 'timeout';\n    case HEADERS = 'headers';\n    case AUTHORIZATION = 'Authorization';\n    case CONTENT_TYPE = 'content-type';\n}\n"], ["/deepseek-php-client/src/Enums/Queries/QueryRoles.php", "<?php\n\nnamespace DeepSeek\\Enums\\Queries;\n\nenum QueryRoles: string\n{\n    case USER = 'user';\n    case SYSTEM = 'system';\n    case ASSISTANT = 'assistant';\n    case TOOL = 'tool';\n}\n"], ["/deepseek-php-client/src/Enums/Data/DataTypes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Data;\n\nenum DataTypes: string\n{\n    case STRING = 'string';\n    case INTEGER = 'integer';\n    case FLOAT = 'float';\n    case ARRAY = 'array';\n    case OBJECT = 'object';\n    case BOOL = 'bool';\n    case JSON = 'json';\n}\n"], ["/deepseek-php-client/src/Enums/Requests/ClientTypes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum ClientTypes: string\n{\n    case GUZZLE = 'guzzle';\n    case SYMFONY = 'symfony';\n\n}\n"], ["/deepseek-php-client/src/Enums/Configs/DefaultConfigs.php", "<?php\n\nnamespace DeepSeek\\Enums\\Configs;\n\nenum DefaultConfigs: string\n{\n    case BASE_URL = 'https://api.deepseek.com/v3';\n    case MODEL = 'DeepSeek-R1';\n    case TIMEOUT = '30';\n    case STREAM = 'false';\n}\n"], ["/deepseek-php-client/src/Enums/Models.php", "<?php\n\nnamespace DeepSeek\\Enums;\n\nenum Models: string\n{\n    case CHAT = 'deepseek-chat';\n    case CODER = 'deepseek-coder';\n    case R1 = 'DeepSeek-R1';\n    case R1Zero = 'DeepSeek-R1-Zero';\n}\n"], ["/deepseek-php-client/src/Enums/Requests/HTTPState.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum HTTPState: int\n{\n    /**\n     * HTTP successful response\n     * status is ok\n     */\n    case OK = 200;\n\n    /**\n     * HTTP client error response\n     * status is unauthorized\n     */\n    case UNAUTHORIZED = 401;\n\n    /**\n     * HTTP client error response\n     * status is payment required\n     */\n    case PAYMENT_REQUIRED = 402;\n\n}\n"], ["/deepseek-php-client/src/Models/BadResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass BadResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Models/SuccessResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass SuccessResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Models/FailureResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass FailureResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Resources/Chat.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nclass Chat extends Resource\n{\n\n}\n"]], "task_instance_info": {"created_time": "2025-08-20 21:12:31", "created_task_model": "DeepSeek-R1", "class_skeleton": "class\nDeepSeekClient\nimplements ClientContract\n{\nprotected ClientInterface $httpClient;\nprotected array $queries = [];\nprotected ?string $model;\nprotected bool $stream;\nprotected float $temperature;\nprotected int $maxTokens;\nprotected string $responseFormatType;\nprotected ResultContract $result;\nprotected string $requestMethod;\nprotected ?string $endpointSuffixes;\nprotected ?array $tools;\npublic function __construct (ClientInterface $httpClient) {}\npublic function run () : string {}\npublic static function build (string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null) : self {}\npublic function query (string $content, ?string $role = \"user\") : self {}\npublic function resetQueries () {}\npublic function getModelsList () : self {}\npublic function withModel (?string $model = null) : self {}\npublic function withStream (bool $stream = true) : self {}\npublic function setTemperature (float $temperature) : self {}\npublic function setMaxTokens (int $maxTokens) : self {}\npublic function setResponseFormat (string $type) : self {}\npublic function buildQuery (string $content, ?string $role = null) : array {}\npublic function setResult (ResultContract $result) {}\npublic function getResult () : ResultContract {}\n}", "code_description": "This code segment functions to: Provide a configurable interface for interacting with an API service by managing request parameters, handling authentication setup, processing data transformations, and orchestrating communication between different service components while maintaining state consistency across operations."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```php\n[TASK_BEGIN]\nclass DeepSeekClient implements ClientContract\n{\n    use HasChat, HasCoder, HasToolsFunctionCalling;\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 = 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\n    public function __construct(ClientInterface $httpClient)\n    {\n        $this->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": "<?php\n\nnamespace DeepSeek;\n\nuse DeepSeek\\Contracts\\ClientContract;\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Enums\\Requests\\ClientTypes;\nuse DeepSeek\\Enums\\Requests\\EndpointSuffixes;\nuse DeepSeek\\Resources\\Resource;\nuse Psr\\Http\\Client\\ClientInterface;\nuse DeepSeek\\Factories\\ApiFactory;\nuse DeepSeek\\Enums\\Queries\\QueryRoles;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\nuse DeepSeek\\Enums\\Configs\\TemperatureValues;\nuse DeepSeek\\Traits\\Resources\\{HasChat, HasCoder};\nuse DeepSeek\\Traits\\Client\\HasToolsFunctionCalling;\n\n", "suffix_code": "\n", "middle_code": "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}", "code_description": null, "fill_type": "CLASS_TYPE", "language_type": "php", "sub_task_type": null}, "context_code": [["/deepseek-php-client/src/Factories/ApiFactory.php", "<?php\n\nnamespace DeepSeek\\Factories;\n\nuse DeepSeek\\Contracts\\Factories\\ApiFactoryContract;\nuse DeepSeek\\Enums\\Configs\\DefaultConfigs;\nuse DeepSeek\\Enums\\Requests\\ClientTypes;\nuse DeepSeek\\Enums\\Requests\\HeaderFlags;\nuse GuzzleHttp\\Client;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Symfony\\Component\\HttpClient\\HttpClient;\nuse Symfony\\Component\\HttpClient\\Psr18Client;\nuse RuntimeException;\nuse InvalidArgumentException;\n\nfinal class ApiFactory implements ApiFactoryContract\n{\n    protected string $apiKey;\n    protected string $baseUrl;\n    protected int $timeout;\n    protected array $clientConfig;\n\n    public static function build(): self\n    {\n        return new self();\n    }\n\n    public function setBaseUri(?string $baseUrl = null): self\n    {\n        $this->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", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Contracts\\Resources\\ResourceContract;\nuse DeepSeek\\Enums\\Configs\\DefaultConfigs;\nuse DeepSeek\\Enums\\Models;\nuse DeepSeek\\Enums\\Data\\DataTypes;\nuse DeepSeek\\Enums\\Requests\\EndpointSuffixes;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\nuse DeepSeek\\Models\\BadResult;\nuse DeepSeek\\Models\\FailureResult;\nuse DeepSeek\\Models\\SuccessResult;\nuse DeepSeek\\Traits\\Queries\\HasQueryParams;\nuse GuzzleHttp\\Exception\\BadResponseException;\nuse GuzzleHttp\\Exception\\GuzzleException;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestFactoryInterface;\nuse Psr\\Http\\Message\\StreamFactoryInterface;\nuse Nyholm\\Psr7\\Factory\\Psr17Factory;\n\nclass Resource implements ResourceContract\n{\n    use HasQueryParams;\n\n    protected ClientInterface $client;\n    protected ?string $endpointSuffixes;\n    protected RequestFactoryInterface $requestFactory;\n    protected StreamFactoryInterface $streamFactory;\n\n    public function __construct(\n        ClientInterface $client,\n        ?string $endpointSuffixes = null,\n        ?RequestFactoryInterface $requestFactory = null,\n        ?StreamFactoryInterface $streamFactory = null\n    ) {\n        $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Client;\n\nuse DeepSeek\\Enums\\Queries\\QueryRoles;\n\ntrait HasToolsFunctionCalling\n{\n    /**\n     * @param array $tools A list of tools the model may call.\n     * @return self The current instance for method chaining.\n     */\n    public function setTools(array $tools): self\n    {\n        $this->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", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nuse DeepSeek\\Contracts\\Models\\ResultContract;\nuse DeepSeek\\Enums\\Requests\\HTTPState;\nuse Psr\\Http\\Message\\ResponseInterface;\n\nabstract class ResultAbstract implements ResultContract\n{\n    protected ?int $statusCode;\n    protected ?string $content;\n    /**\n     * handel response coming from request\n     * @var ResponseInterface|null\n     */\n    protected ?ResponseInterface $response;\n    public function __construct(?int $statusCode = null, ?string $content = null)\n    {\n        $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Queries;\n\nuse DeepSeek\\Enums\\Data\\DataTypes;\nuse DeepSeek\\Enums\\Requests\\QueryFlags;\n\ntrait HasQueryParams\n{\n    /**\n     * Helper method to get the query parameter or default value with type conversion.\n     *\n     * @param array $query\n     * @param string $key\n     * @param mixed $default\n     * @param string $type\n     * @return mixed\n     */\n    private function getQueryParam(array $query, string $key, $default, string $type): mixed\n    {\n        if (isset($query[$key])) {\n            $value = $query[$key];\n            return $this->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", "<?php\n\nnamespace DeepSeek\\Traits\\Resources;\n\nuse DeepSeek\\Resources\\Chat;\n\ntrait HasChat\n{\n    /**\n     * Send the accumulated queries to the Chat resource.\n     *\n     * @return string\n     */\n    public function chat(): string\n    {\n        $requestData = [\n            'messages' => $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", "<?php\n\nnamespace DeepSeek\\Traits\\Resources;\n\nuse DeepSeek\\Resources\\Coder;\n\ntrait HasCoder\n{\n    /**\n     * Send the accumulated queries to the code resource.\n     *\n     * @return string\n     */\n    public function code(): string\n    {\n        $requestData = [\n            'messages' => $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", "<?php\n\nnamespace DeepSeek\\Contracts;\n\ninterface ClientContract\n{\n    public function run(): string;\n    public static function build(string $apiKey, ?string $baseUrl = null, ?int $timeout = null): self;\n    public function query(string $content, ?string $role = \"user\"): self;\n    public function getModelsList(): self;\n    public function withModel(?string $model = null): self;\n    public function withStream(bool $stream = true): self;\n    public function buildQuery(string $content, ?string $role = null): array;\n}\n"], ["/deepseek-php-client/src/Contracts/Factories/ApiFactoryContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Factories;\n\nuse DeepSeek\\Factories\\ApiFactory;\nuse GuzzleHttp\\Client;\nuse Psr\\Http\\Client\\ClientInterface;\n\ninterface ApiFactoryContract\n{\n    /**\n     * Create a new instance of the factory.\n     *\n     * @return ApiFactory\n     */\n    public static function build(): ApiFactory;\n\n    /**\n     * Set the base URL for the API.\n     *\n     * @param string|null $baseUrl The base URL to set (optional).\n     * @return ApiFactory\n     */\n    public function setBaseUri(?string $baseUrl = null): ApiFactory;\n\n    /**\n     * Set the API key for authentication.\n     *\n     * @param string $apiKey The API key to set.\n     * @return ApiFactory\n     */\n    public function setKey(string $apiKey): ApiFactory;\n\n    /**\n     * Set the timeout for the API request.\n     *\n     * @param int|null $timeout The timeout value in seconds (optional).\n     * @return ApiFactory\n     */\n    public function setTimeout(?int $timeout = null): ApiFactory;\n\n    /**\n     * Build and return http Client instance.\n     *\n     * @return ClientInterface\n     */\n    public function run(?string $clientType = null): ClientInterface;\n}\n"], ["/deepseek-php-client/src/Resources/Coder.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nuse DeepSeek\\Enums\\Models;\n\nclass Coder extends Resource\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::CODER->value;\n    }\n}\n"], ["/deepseek-php-client/src/Enums/Requests/QueryFlags.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum QueryFlags: string\n{\n    case MESSAGES = 'messages';\n    case MODEL = 'model';\n    case STREAM = 'stream';\n    case TEMPERATURE = 'temperature';\n    case MAX_TOKENS = 'max_tokens';\n    case TOOLS = 'tools';\n    case RESPONSE_FORMAT = 'response_format';\n}\n"], ["/deepseek-php-client/src/Contracts/Models/ResultContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Models;\n\ninterface ResultContract\n{\n    /**\n     * result status code\n     * @return int\n     */\n    public function getStatusCode(): int;\n\n    /**\n     * result content date as a string\n     * @return string\n     */\n    public function getContent(): string;\n\n    /**\n     * if response status code is ok (200)\n     * @return bool\n     */\n    public function isSuccess(): bool;\n}\n"], ["/deepseek-php-client/src/Contracts/Resources/ResourceContract.php", "<?php\n\nnamespace DeepSeek\\Contracts\\Resources;\n\n/**\n * Interface for defining the structure of resource classes.\n */\ninterface ResourceContract\n{\n    /**\n     * Get the endpoint suffix for the resource.\n     *\n     * @return string\n     */\n    public function getEndpointSuffix(): string;\n\n    /**\n     * Get the model associated with the resource.\n     *\n     * @return string\n     */\n    public function getDefaultModel(): string;\n\n    /**\n     * check if stream enabled or not.\n     *\n     * @return bool\n     */\n    public function getDefaultStream(): bool;\n}\n"], ["/deepseek-php-client/src/Enums/Requests/EndpointSuffixes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum EndpointSuffixes: string\n{\n    case CHAT = '/chat/completions';\n    case MODELS_LIST = '/models';\n}\n"], ["/deepseek-php-client/src/Enums/Configs/TemperatureValues.php", "<?php\n\nnamespace DeepSeek\\Enums\\Configs;\n\nenum TemperatureValues: string\n{\n    case CODING = \"0.0\";\n    case MATH = \"0.1\";\n    case DATA_ANALYSIS = \"1.0\";\n    case DATA_CLEANING = \"1.1\";\n    case GENERAL_CONVERSATION = \"1.3\";\n    case TRANSLATION = \"1.4\";\n    case CREATIVE_WRITING = \"1.5\";\n    case POETRY = \"1.6\";\n    case MAX_TOKENS = \"4096\";\n    case RESPONSE_FORMAT_TYPE = \"text\";\n}\n"], ["/deepseek-php-client/src/Enums/Requests/HeaderFlags.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum HeaderFlags: string\n{\n    case BASE_URL = 'base_uri';\n    case TIMEOUT = 'timeout';\n    case HEADERS = 'headers';\n    case AUTHORIZATION = 'Authorization';\n    case CONTENT_TYPE = 'content-type';\n}\n"], ["/deepseek-php-client/src/Enums/Queries/QueryRoles.php", "<?php\n\nnamespace DeepSeek\\Enums\\Queries;\n\nenum QueryRoles: string\n{\n    case USER = 'user';\n    case SYSTEM = 'system';\n    case ASSISTANT = 'assistant';\n    case TOOL = 'tool';\n}\n"], ["/deepseek-php-client/src/Enums/Data/DataTypes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Data;\n\nenum DataTypes: string\n{\n    case STRING = 'string';\n    case INTEGER = 'integer';\n    case FLOAT = 'float';\n    case ARRAY = 'array';\n    case OBJECT = 'object';\n    case BOOL = 'bool';\n    case JSON = 'json';\n}\n"], ["/deepseek-php-client/src/Enums/Requests/ClientTypes.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum ClientTypes: string\n{\n    case GUZZLE = 'guzzle';\n    case SYMFONY = 'symfony';\n\n}\n"], ["/deepseek-php-client/src/Enums/Configs/DefaultConfigs.php", "<?php\n\nnamespace DeepSeek\\Enums\\Configs;\n\nenum DefaultConfigs: string\n{\n    case BASE_URL = 'https://api.deepseek.com/v3';\n    case MODEL = 'DeepSeek-R1';\n    case TIMEOUT = '30';\n    case STREAM = 'false';\n}\n"], ["/deepseek-php-client/src/Enums/Models.php", "<?php\n\nnamespace DeepSeek\\Enums;\n\nenum Models: string\n{\n    case CHAT = 'deepseek-chat';\n    case CODER = 'deepseek-coder';\n    case R1 = 'DeepSeek-R1';\n    case R1Zero = 'DeepSeek-R1-Zero';\n}\n"], ["/deepseek-php-client/src/Enums/Requests/HTTPState.php", "<?php\n\nnamespace DeepSeek\\Enums\\Requests;\n\nenum HTTPState: int\n{\n    /**\n     * HTTP successful response\n     * status is ok\n     */\n    case OK = 200;\n\n    /**\n     * HTTP client error response\n     * status is unauthorized\n     */\n    case UNAUTHORIZED = 401;\n\n    /**\n     * HTTP client error response\n     * status is payment required\n     */\n    case PAYMENT_REQUIRED = 402;\n\n}\n"], ["/deepseek-php-client/src/Models/BadResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass BadResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Models/SuccessResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass SuccessResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Models/FailureResult.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Models;\n\nclass FailureResult extends ResultAbstract\n{\n\n}\n\n"], ["/deepseek-php-client/src/Resources/Chat.php", "<?php\n\ndeclare(strict_types=1);\n\nnamespace DeepSeek\\Resources;\n\nclass Chat extends Resource\n{\n\n}\n"]], "task_instance_info": {"created_time": "2025-08-20 21:12:31", "created_task_model": "DeepSeek-R1", "class_skeleton": "class\nDeepSeekClient\nimplements ClientContract\n{\nprotected ClientInterface $httpClient;\nprotected array $queries = [];\nprotected ?string $model;\nprotected bool $stream;\nprotected float $temperature;\nprotected int $maxTokens;\nprotected string $responseFormatType;\nprotected ResultContract $result;\nprotected string $requestMethod;\nprotected ?string $endpointSuffixes;\nprotected ?array $tools;\npublic function __construct (ClientInterface $httpClient) {}\npublic function run () : string {}\npublic static function build (string $apiKey, ?string $baseUrl = null, ?int $timeout = null, ?string $clientType = null) : self {}\npublic function query (string $content, ?string $role = \"user\") : self {}\npublic function resetQueries () {}\npublic function getModelsList () : self {}\npublic function withModel (?string $model = null) : self {}\npublic function withStream (bool $stream = true) : self {}\npublic function setTemperature (float $temperature) : self {}\npublic function setMaxTokens (int $maxTokens) : self {}\npublic function setResponseFormat (string $type) : self {}\npublic function buildQuery (string $content, ?string $role = null) : array {}\npublic function setResult (ResultContract $result) {}\npublic function getResult () : ResultContract {}\n}", "code_description": "This code segment functions to: Provide a configurable interface for constructing API requests, handling parameter settings and query building while integrating multiple service capabilities through trait composition, and execute network operations through a centralized resource handler."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```php\n[TASK_BEGIN]\nclass 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\n    public function __construct(ClientInterface $httpClient)\n    {\n        $this->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}"}}