-
Notifications
You must be signed in to change notification settings - Fork 16
[WIP] v1.0.0 Updates #71
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
Conversation
ENG-900 Support messages (chat endpoint) in together python library
Multiple customers are getting confused that using Therefore, we want to support More context here: https://www.notion.so/together-docs/Prompt-template-discrepancy-proposal-a557d4fb7f5d49d59a9b79480e0926b9 |
68930b7
to
92fcb44
Compare
here is my async demo import os
import time
from together import Together
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
def sync_chat_completion(messages, max_tokens):
client = Together(api_key=TOGETHER_API_KEY)
start_time = time.time()
for message in messages:
response = client.chat.completions.create(
model="togethercomputer/llama-2-7b-chat",
max_tokens=max_tokens,
messages=[{"role": "user", "content": message}]
)
print(response.choices[0].message.content)
end_time = time.time()
print("Synchronous total execution time:", end_time - start_time, "seconds")
async def async_chat_completion(messages, max_tokens):
async_client = AsyncTogether(api_key=TOGETHER_API_KEY)
start_time = time.time()
tasks = [async_client.chat.completions.create(
model="togethercomputer/llama-2-7b-chat",
max_tokens=max_tokens,
messages=[{"role": "user", "content": message}]
) for message in messages]
responses = await asyncio.gather(*tasks)
for response in responses:
print(response.choices[0].message.content)
end_time = time.time()
print("Asynchronous total execution time:", end_time - start_time, "seconds") in jupyter notebook messages = ["hi there what is the meaning of life?", "What country is Paris in?"]
sync_chat_completion(messages, 32)
await async_chat_completion(messages, 32) otherwise
expected output
|
f6ccf10
to
389fbc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great Abhy, amazing work! Feel free to merge, then I can make a new PR to update the README (and update our actual docs), then we can open source this repo + announce.
To-Do:
Endpoints to support:
Example usage:
Updated contribution style
Setting up pre-commit for dev: