Example Usage
Simply copy and paste any of the following scripts in your coding environments to interact with SN1 - Please ensure you have an API Key.
Chat Completions Script
import asyncio
import openai
STREAM = True
API_KEY = "..."
async def main():
try:
client = openai.AsyncOpenAI(
base_url="https://sn1.api.macrocosmos.ai/v1",
max_retries=0,
timeout=openai.Timeout(120, connect=10, read=110),
api_key=API_KEY
)
payload = {
"messages": [
{"role": "user", "content": "List 5 popular places in Hawaii"}
],
"seed": 42,
"sampling_parameters": {
"do_sample": True,
"max_new_tokens": 512,
"temperature": 0.7,
"top_k": 50,
"top_p": 0.95
},
"inference_mode": "Reasoning-Fast",
}
result = await client.chat.completions.create(
model="Default",
messages=payload["messages"],
stream=STREAM,
extra_body=payload,
)
if not STREAM:
print(result)
else:
chunks = []
async for chunk in result:
if chunk.choices[0].delta.content:
chunks.append(chunk.choices[0].delta.content)
print("".join(chunks))
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
asyncio.run(main())Web Retrieval Script
Last updated
