-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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
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) | ||
|
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,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 |