from openai import OpenAI
client = OpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-api-key>"
)
completion = client.chat.completions.create(
model="Meta-Llama-3.1-8B-Instruct",
messages = [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
]
)
print(completion.choices[0].message.content)
from openai import AsyncOpenAI
import asyncio
async def main():
client = AsyncOpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-api-key>"
)
completion = await client.chat.completions.create(
model="Meta-Llama-3.1-8B-Instruct",
messages = [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
]
)
print(completion.choices[0].message.content)
asyncio.run(main())
from openai import OpenAI
client = OpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-api-key>"
)
completion = client.chat.completions.create(
model="Meta-Llama-3.1-8B-Instruct",
messages = [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
],
stream = True
)
for chunk in completion:
print(chunk.choices[0].delta.content, end="")
from openai import AsyncOpenAI
import asyncio
async def main():
client = AsyncOpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-api-key>"
)
completion = await client.chat.completions.create(
model="Meta-Llama-3.1-8B-Instruct",
messages = [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
],
stream = True
)
async for chunk in completion:
print(chunk.choices[0].delta.content, end="")
asyncio.run(main())
Factor | Consideration |
---|---|
Task complexity | Larger models are better suited for complex tasks. |
Accuracy requirements | Larger models generally offer higher accuracy. |
Cost and resources | Larger models come with increased costs and resource demands. |
Element | Description |
---|---|
Defining a persona | Assigning a specific role to the model (e.g., “You are a financial advisor”). |
Providing context | Supplying background information to guide the model’s response. |
Specifying output format | Instructing the model to respond in a particular style (e.g., JSON, bullet points, structured text). |
Describing a use case | Clarifying the goal of the interaction. |
Technique | Description |
---|---|
In-context learning | Providing examples of desired outputs to guide the model. |
Chain-of-Thought (CoT) prompting | Encouraging the model to articulate its reasoning before delivering a response. |
Element | Description |
---|---|
role | Specifies who is sending the message. |
content | Contains the message text. |
system
, user
, or assistant
.
Role | Description |
---|---|
system | Provides general instructions to the model. |
user | Represents user input. |
assistant | Contains the model’s response. |
completion = client.chat.completions.create(
model="Meta-Llama-3.1-8B-Instruct",
messages = [
{"role": "user", "content": "Hi! My name is Peter and I am 31 years old. What is 1+1?"},
{"role": "assistant", "content": "Nice to meet you, Peter. 1 + 1 is equal to 2"},
{"role": "user", "content": "What is my age?"}
],
stream = True
)
for chunk in completion:
print(chunk.choices[0].delta.content, end="")
You told me earlier, Peter. You're 31 years old.