Skip to content

Feature: Add context to requests for custom API services. #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

lnikonl
Copy link

@lnikonl lnikonl commented Jan 10, 2025

Feature:
Add context to requests for custom API services.

Use case:
When using LLM models for a custom dictionary, the translation quality will be more accurate if the context is added to the query.
And it is possible to use it as part of the prompt.

Changed:

  • Add 'context' field in SearchApiRequest.
    app/Http/Requests/Dictionaries/SearchApiRequest.php
        return [
            'language' => 'required|string',
            'term' => 'required|string',
            'context' => 'string',
        ];
  • Add 'ctx' field for request to custom api.
    app/Services/DictionaryService.php
private function buildCustomApiTranslateRequest(Pool $pool, Dictionary $dictionary, string $term, string $context): void
{
    $pool->post($dictionary->api_host, [
        'q' => $term,
        'ctx' => $context,
        'source' => strtolower($dictionary->source_language),
        'target' => strtolower($dictionary->target_language),
    ]);
}
  • Some changes in code for support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant