Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ost/ba/prototype
1 result
Show changes
Commits on Source (7)
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# assistants_id
/assistant_id
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
\ No newline at end of file
from openai import OpenAI
DEFAULT_ORGANIZATION = "org-l7LAlNiV90lRSOKFIx8vUvDt"
def get_client(api_key: str, organization: str) -> OpenAI:
return OpenAI(
api_key=api_key,
organization=organization
)
from openai import OpenAI
from client import get_client, DEFAULT_ORGANIZATION
import os
API_KEY = "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"
def create():
client = get_client(API_KEY, DEFAULT_ORGANIZATION)
assistant = client.beta.assistants.create(
name="test",
model="gpt-3.5-turbo-0125",
instructions="You are a cooking helper.",
)
with open("assistant_id", "w") as f:
# just a temporary solution, in production, this will be hard-coded or retrieved from somewhere
f.write(assistant.id)
def delete():
client = get_client(API_KEY, DEFAULT_ORGANIZATION)
with open("assistant_id", "r") as f:
assistant_id = f.readline()
client.beta.assistants.delete(assistant_id)
os.remove("assistant_id")
if __name__ == '__main__':
create()
# delete()
from client import get_client, DEFAULT_ORGANIZATION
from time import sleep
API_KEY = "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"
def main():
client = get_client(API_KEY, DEFAULT_ORGANIZATION)
thread = client.beta.threads.create()
assistant_id = ""
with open("assistant_id", 'r') as f:
assistant_id = f.readline()
running = True
while running:
try:
user_message = input("Your message: ")
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=user_message,
)
run = client.beta.threads.runs.create(
thread.id,
assistant_id=assistant_id,
)
# streaming currently not supported
while run.status != "completed": # a lot more states must be checked in production
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id,
)
sleep(2)
responses = client.beta.threads.messages.list(
thread.id,
)
responses_to_message = [r for r in responses.data if r.run_id == run.id and r.role == "assistant"]
for response in responses_to_message:
for response_content in response.content:
# not really safe like this, type should be checked
print(response_content.text.value)
except (KeyboardInterrupt):
running = False
client.beta.threads.delete(thread.id)
if __name__ == "__main__":
main()
from setuptools import setup, find_packages
requirements = []
with open("requirements.txt") as f:
requirements = f.readlines()
setup(name='prototype',
version='1.0',
packages=find_packages(),
install_requires=requirements,
entry_points={
"console_scripts": [
"prototype = nctool.main:main"
],
}
)