Groq
Portkey + Groq
使用快速的 Groq API 和 OpenAI 兼容性通过 Portkey!
使用 OpenAI 客户端
使用 Portkey 客户端
高级路由 - 负载均衡
使用 Portkey 进行可观察性

Last updated

Last updated
!pip install -qU portkey-ai openaifrom openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
from google.colab import userdata
client = OpenAI(
api_key= userdata.get('GROQ_API_KEY'), ## replace it your Groq API key
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="groq",
api_key= userdata.get('PORTKEY_API_KEY'), ## replace it your Portkey API key
)
)
chat_complete = client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user",
"content": "What's the purpose of Generative AI?"}],
)
print(chat_complete.choices[0].message.content)生成性人工智能的主要目的是创造新的、原始的且通常逼真的数据或内容,例如图像、视频、音乐、文本或演讲,这些内容与人类创造的内容相似。生成性人工智能模型旨在生成与真实世界数据无法区分的新数据样本,从而允许广泛的应用和可能性。生成性人工智能的一些主要目的包括:
1. **数据增强**:生成新数据以增强现有数据集,提高机器学习模型的性能,并减少过拟合。
2. **内容创作**:自动化内容的创建,例如音乐、视频或文章,可用于娱乐、教育或营销目的。
3. **模拟与建模**:生成合成数据以模拟现实世界场景,允许在医疗、金融或气候建模等各个领域进行实验、测试和分析。
4. **个性化**:创建个性化的内容、推荐或体验,以满足个别用户的偏好和行为。
5. **创意辅助**:为人类创作者提供工具和灵感,例如艺术家、作家或音乐家,以帮助他们的创作过程。
6. **合成数据生成**:生成逼真的合成数据以保护敏感信息,例如个人数据或机密商业数据。
7. **研究与开发**:通过生成新数据或场景,促进计算机视觉、自然语言处理或机器人等各个领域的研究。
8. **娱乐与休闲**:创造引人入胜的互动体验,例如游戏、聊天机器人或互动故事。
9. **教育与培训**:生成教育内容,例如互动教程、虚拟实验室或个性化学习材料。
10. **医疗与生物医学应用**:生成合成医学图像、患者数据或临床试验数据,以帮助疾病诊断、治疗规划和药物发现。
生成性人工智能的一些主要好处包括:
* 提高效率和生产力
* 改善准确性和真实感
* 增强创造力和灵感
* 加速研究与开发
* 个性化体验和服务
* 降低成本和减少数据收集成本
然而,必须解决与生成性人工智能相关的潜在风险和担忧,例如:
* 对生成内容的误用和滥用
* AI 生成数据中的偏见和不公正
* 隐私和安全问题
* 工作岗位流失和劳动市场影响
随着生成性人工智能的不断发展,制定和实施负责任的人工智能实践至关重要,确保这些技术用于改善社会和人类的福祉。from portkey_ai import Portkey
portkey = Portkey(
api_key = userdata.get('PORTKEY_API_KEY'), # 替换为您的 Portkey API 密钥
virtual_key= "groq-431005", # 替换为您的 Groq AI 虚拟密钥
)completion = portkey.chat.completions.create(
messages= [{ "role": 'user', "content": 'Who are you?'}],
model= 'llama3-70b-8192',
max_tokens=250
)
print(completion){
"id": "chatcmpl-8cec08e0-910e-4331-9c4b-f675d9923371",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "I am LLaMA, an AI assistant developed by Meta AI that can understand and respond to human input in a conversational manner. I'm not a human, but a computer program designed to simulate conversation and answer questions to the best of my knowledge. I can discuss a wide range of topics, from science and history to entertainment and culture. I can even generate creative content, such as stories or poems.\n\nMy primary function is to assist and provide helpful responses to your queries. I'm constantly learning and improving my responses based on the interactions I have with users like you, so please bear with me if I make any mistakes.\n\nFeel free to ask me anything, and I'll do my best to provide a helpful and accurate response!",
"role": "assistant",
"function_call": null,
"tool_calls": null
}
}
],
"created": 1714136032,
"model": "llama3-70b-8192",
"object": "chat.completion",
"system_fingerprint": null,
"usage": {
"prompt_tokens": 14,
"completion_tokens": 147,
"total_tokens": 161
}
}config = {
"strategy": {
"mode": "loadbalance",
},
"targets": [
{
"virtual_key": "groq-431005", # Groq 虚拟密钥
"override_params": {"model": "llama3-70b-8192"},
"weight": 0.7
},
{
"virtual_key": "gpt3-8070a6", # OpenAI 虚拟密钥
"override_params": {"model": "gpt-3.5-turbo-0125"},
"weight": 0.3
}
]
}from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
from google.colab import userdata
client = OpenAI(
api_key="X",
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
api_key=userdata.get("PORTKEY_API_KEY"),
config=config
)
)
chat_complete = client.chat.completions.create(
model="X",
messages=[{"role": "user",
"content": "Just say hi!"}],
)
print(chat_complete.model)
print(chat_complete.choices[0].message.content)gpt-3.5-turbo-0125
Hi! How can I assist you today?