-
Notifications
You must be signed in to change notification settings - Fork 691
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 #10 from andrewyng/together
- Loading branch information
Showing
5 changed files
with
72 additions
and
63 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
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,40 @@ | ||
"""The interface to the Together API.""" | ||
|
||
import os | ||
|
||
from ..framework.provider_interface import ProviderInterface | ||
|
||
_TOGETHER_BASE_URL = "https://api.together.xyz/v1" | ||
|
||
|
||
class TogetherInterface(ProviderInterface): | ||
"""Implements the ProviderInterface for interacting with Together's APIs.""" | ||
|
||
def __init__(self): | ||
"""Set up the Together client using the API key obtained from the user's environment.""" | ||
from openai import OpenAI | ||
|
||
self.together_client = OpenAI( | ||
api_key=os.getenv("TOGETHER_API_KEY"), | ||
base_url=_TOGETHER_BASE_URL, | ||
) | ||
|
||
def chat_completion_create(self, messages=None, model=None, temperature=0): | ||
"""Request chat completions from the Together API. | ||
Args: | ||
---- | ||
model (str): Identifies the specific provider/model to use. | ||
messages (list of dict): A list of message objects in chat history. | ||
temperature (float): The temperature to use in the completion. | ||
Returns: | ||
------- | ||
The API response with the completion result. | ||
""" | ||
return self.together_client.chat.completions.create( | ||
model=model, | ||
messages=messages, | ||
temperature=temperature, | ||
) |
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