-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from leolivier:leolivier/issue3
Leolivier/issue3
- Loading branch information
Showing
5 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import xai_sdk | ||
import asyncio | ||
from .client_base import TranspoClient | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GrokClient(TranspoClient): | ||
def __init__(self, params, target_language=None): | ||
params.model = params.model or "" # default model given by Grok itself if not provided | ||
super().__init__(params, target_language) | ||
self.client = xai_sdk.Client(api_key=params.xai_api_key) if hasattr(params, 'xai_api_key') else xai_sdk.Client() | ||
|
||
async def async_get_translation(self, system_prompt, user_prompt): | ||
conversation = self.client.chat.create_conversation() | ||
response = await conversation.add_response_no_stream(f'{system_prompt}\n{user_prompt}\n') | ||
return response.message | ||
|
||
def get_translation(self, system_prompt, user_prompt): | ||
return asyncio.run(self.async_get_translation(system_prompt, user_prompt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters