Skip to content

Commit

Permalink
Add initial prem integration
Browse files Browse the repository at this point in the history
  • Loading branch information
richiejp committed Sep 4, 2024
1 parent ea2c34e commit 840b32d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/assistants/prem/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import sys

from premai import Prem
from premai.models import ChatCompletionResponse

# Ayup can read this from a .ayup-env inside the assistant directory
prem_api_key = os.getenv("PREM_API_KEY")
if prem_api_key is None:
raise ValueError("Environment variable PREM_API_KEY is not set. You can use a .ayup-env file to set it")

project_id = os.getenv("PREM_PROJECT_ID")
if project_id is None:
raise ValueError("Environment variable PREM_PROJECT_ID is not set. You can set variables in .ayup-env")

file_path = '/out/app/__main__.py'

client = Prem(api_key=prem_api_key)

response = client.chat.completions.create(
project_id=project_id,
system_prompt="""You are a code generation assistant. You only output Python code that is used
in a standalone script and no other text. You must not wrap the code in markdown or anything
else, it will be submitted directly to the Python interpreter""",
messages = [{"role": "user", "content": "Create a hello world REST server"}]
)

print(f"Prem response: {response}")

if not isinstance(response, ChatCompletionResponse):
sys.exit(1)

with open(file_path, 'w') as file:
c = response.choices[0].message.content
if isinstance(c, str):
file.write(c)
print(f"File written to {file_path}")
else:
print("No message content to write!")
sys.exit(1)

21 changes: 21 additions & 0 deletions examples/assistants/prem/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
anyio==4.4.0
attrs==24.2.0
brotlicffi==1.1.0.0
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
docopt==0.6.2
h11==0.14.0
httpcore==1.0.5
httpx==0.26.0
idna==3.7
pipreqs==0.4.13
premai==0.3.67
pycparser==2.22
python-dateutil==2.9.0.post0
requests==2.32.3
six==1.16.0
sniffio==1.3.1
typing_extensions==4.12.2
urllib3==2.2.2
yarg==0.1.9

0 comments on commit 840b32d

Please sign in to comment.