-
Notifications
You must be signed in to change notification settings - Fork 363
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 #24 from togethercomputer/add-quickstart
Added quickstart MoA code + architecture diagram
- Loading branch information
Showing
3 changed files
with
126 additions
and
14 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
# Mixture-of-Agents in 50 lines of code | ||
import asyncio | ||
import os | ||
from together import AsyncTogether, Together | ||
|
||
client = Together(api_key=os.environ.get("TOGETHER_API_KEY")) | ||
async_client = AsyncTogether(api_key=os.environ.get("TOGETHER_API_KEY")) | ||
|
||
user_prompt = "What are some fun things to do in SF?" | ||
reference_models = [ | ||
"Qwen/Qwen2-72B-Instruct", | ||
"Qwen/Qwen1.5-72B-Chat", | ||
"mistralai/Mixtral-8x22B-Instruct-v0.1", | ||
"databricks/dbrx-instruct", | ||
] | ||
aggregator_model = "mistralai/Mixtral-8x22B-Instruct-v0.1" | ||
aggreagator_system_prompt = """You have been provided with a set of responses from various open-source models to the latest user query. Your task is to synthesize these responses into a single, high-quality response. It is crucial to critically evaluate the information provided in these responses, recognizing that some of it may be biased or incorrect. Your response should not simply replicate the given answers but should offer a refined, accurate, and comprehensive reply to the instruction. Ensure your response is well-structured, coherent, and adheres to the highest standards of accuracy and reliability. | ||
Responses from models:""" | ||
|
||
|
||
async def run_llm(model): | ||
"""Run a single LLM call with a reference model.""" | ||
response = await async_client.chat.completions.create( | ||
model=model, | ||
messages=[{"role": "user", "content": user_prompt}], | ||
temperature=0.7, | ||
max_tokens=512, | ||
) | ||
print(model) | ||
return response.choices[0].message.content | ||
|
||
|
||
async def main(): | ||
results = await asyncio.gather(*[run_llm(model) for model in reference_models]) | ||
|
||
finalStream = client.chat.completions.create( | ||
model=aggregator_model, | ||
messages=[ | ||
{"role": "system", "content": aggreagator_system_prompt}, | ||
{"role": "user", "content": ",".join(str(element) for element in results)}, | ||
], | ||
stream=True, | ||
) | ||
|
||
for chunk in finalStream: | ||
print(chunk.choices[0].delta.content or "", end="", flush=True) | ||
|
||
|
||
asyncio.run(main()) |