Skip to content
Snippets Groups Projects

Resolve #3480683 "Use core json"

Open Paul Smith requested to merge issue/ai-3480683:3480683-use-core-json into 1.0.x
8 unresolved threads

Closes #3480683

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
327 * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
328 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
329 * @throws \Drupal\Core\Entity\EntityStorageException
342 330 */
343 protected function generateTag($name, array $settings) {
344 /** @var \Drupal\taxonomy\TermStorage */
331 protected function generateTag(string $name, array $settings): ?Term {
332 /** @var \Drupal\taxonomy\TermStorage $storage */
345 333 $storage = $this->entityTypeManager->getStorage('taxonomy_term');
346 334 $bundle = !empty($settings['handler_settings']['auto_create_bundle']) ? $settings['handler_settings']['auto_create_bundle'] : key($settings['handler_settings']['target_bundles']);
347 335
348 336 if (!$name || !$bundle) {
349 337 return NULL;
350 338 }
339
340 /** @var \Drupal\taxonomy\Entity\Term $term */
  • 175 165 * The key to set the context to.
    176 166 * @param mixed $data
    177 167 * The data.
    168 *
    169 * @throws \Drupal\Core\TempStore\TempStoreException
    • Normally @throws tags aren't added in core

    • Author Contributor

      The coder complains about them not being there - Core does a lot of things the coder complains about in fact ;) - do we need to strip them out again? The code can throw those exceptions and presumably the practice of documenting them has a reason.

    • Please register or sign in to reply
  • 84 77 $provider = \Drupal::service('ai.provider')->createInstance('echoai');
    85 78 $input = new ImageClassificationInput(new ImageFile('', 'image/jpeg', 'test.jpg'));
    86 79 $this->expectException(AiBadRequestException::class);
    87 $provider->imageClassification($input, $this->model);
    80 $provider->imageClassification($input, NULL);
  • Love it; constructor promotion, return types, etc. Thanks!

  • 42 43 $form_state->setValue('tt_ai_model', $request->query->get('model_id'));
    43 44 }
    44 45
    45 $input = json_decode($request->query->get('input', '[]'));
    46 $input = Json::decode($request->query->get('input', '[]'));
  • 130 127 // Add JSON output.
    131 128 foreach ($prompts as $key => $prompt) {
    132 129 $prompt .= "\n\nDo not make up any data, only transfer data that is in the original context. Do not include any explanations, do not provide any markup just pure json, do not format the output with any surroundings, only provide a RFC8259 compliant JSON response following this format without deviation. :\n";
    133 $prompt .= json_encode([$promptJsonFields], JSON_PRETTY_PRINT);
  • 213 224 *
    214 225 * @return \Symfony\Component\HttpFoundation\StreamedResponse
    215 226 * The streamed response.
    227 *
    228 * @throws \Drupal\Core\TempStore\TempStoreException
    216 229 */
    217 private function createStreamedResponse(StreamedChatMessageIterator $streamedMessages): StreamedResponse {
    230 private function createStreamedResponse(StreamedChatMessageIteratorInterface $streamedMessages): StreamedResponse {
  • 97 109 $form_state->setValue('image_generator_ai_model', $request->query->get('model_id'));
    98 110 }
    99 111
    100 $input = json_decode($request->query->get('input', '[]'));
    112 $input = Json::decode($request->query->get('input', '[]'));
  • 82 82 * The chunks to encode.
    83 83 */
    84 84 protected function writeExpectedJsonForTest(string $file, array $chunks): void {
    85 // Same as core Json::encode() except adding JSON_PRETTY_PRINT as well
    86 // so we can easier check that new encodings are fine.
    87 $json = json_encode($chunks, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRETTY_PRINT);
    Please register or sign in to reply
    Loading